java读取excel(xlsx格式)内容为string

来源:互联网 发布:现在淘宝客服好做吗 编辑:程序博客网 时间:2024/06/05 16:04
public static String xlsx2String(File file){String result = "";try {FileInputStream fis = new FileInputStream(file);StringBuilder sb = new StringBuilder();XSSFWorkbook xssfWorkbook = new XSSFWorkbook(fis);//read the sheetfor(int numSheet=0;numSheet<xssfWorkbook.getNumberOfSheets();numSheet++){XSSFSheet xssfSheet = xssfWorkbook.getSheetAt(numSheet);if(xssfSheet ==null){continue;}//read the rowfor(int rowNum=0; rowNum<=xssfSheet.getLastRowNum();rowNum++){XSSFRow xssfRow = xssfSheet.getRow(rowNum);for(int cosNum=0;cosNum<xssfRow.getLastCellNum();cosNum++){XSSFCell cell = xssfRow.getCell(cosNum);sb.append(cell.getStringCellValue());}}}fis.close();result +=sb.toString();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}return result;}

0 0
原创粉丝点击