/**
* 简单的读取excel
* @param inputFile
* @param inputFileSheetIndex
* @throws Exception
*/
public static ArrayList<String> sampleReadExcel(File inputFile, int inputFileSheetIndex) throws Exception {
ArrayList<String> list = new ArrayList<String>();
Workbook book = null;
Cell cell = null;
//避免乱码的设置
WorkbookSettings setting = new WorkbookSettings();
java.util.Locale locale = new java.util.Locale("zh","CN");
setting.setLocale(locale);
setting.setEncoding("ISO-8859-1");
book = Workbook.getWorkbook(inputFile, setting);
Sheet sheet = book.getSheet(inputFileSheetIndex);
for (int rowIndex = 0; rowIndex < sheet.getRows(); rowIndex++) {// Excel第一行为表头,因此J初值设为1
for (int colIndex = 0; colIndex < sheet.getColumns(); colIndex++) {// 只需从Excel中取出2列
cell = sheet.getCell(colIndex, rowIndex);
list.add(cell.getContents());
}
}
//【问题:如果在实际部署的时候没有写下面这句是否会导致不断消耗掉服务器的内存?jxl里面有个ReadWrite.java没有关闭读的,只关闭了写的】
book.close();
return list;
}
jxl读取excel需要关闭Workbook?
最新推荐文章于 2022-09-14 11:26:30 发布