java - 无法使用 HSSF 忽略空行
问题描述
下面的方法写来从 excel 中获取所有数据,但这也是选择空行。您能否建议更改以忽略空行?
public ArrayList<Map<String, String>> getCompleteSheetExcelData(String workbookName, String sheetName) throws IOException {
//obtaining input bytes from a file
FileInputStream fis=new FileInputStream(new File(excelpath+workbookName+".xls"));
//creating workbook instance that refers to .xls file
HSSFWorkbook wb=new HSSFWorkbook(fis);
//creating a Sheet object to retrieve the object
HSSFSheet sheets=wb.getSheet(sheetName);
FormulaEvaluator formulaEvaluator = new HSSFFormulaEvaluator((HSSFWorkbook) wb);
wbname = workbookName;
sName = sheetName;
ArrayList<Map<String, String>> excelData = new ArrayList<>();
DataFormatter formatter = new DataFormatter();
int rowCount = sheets.getLastRowNum();
for(int i=1;i<=rowCount;i++){
Row row = sheets.getRow(0);
Map<String, String> rowData = new HashMap<>();
for (int j = 0; j < row.getLastCellNum(); j++) {
String key = row.getCell(j).getStringCellValue().trim();
try {
String value = formatter.formatCellValue(sheets.getRow(i).getCell(j),formulaEvaluator);
rowData.put(key, value);
}
catch (NullPointerException e){
rowData.put(key, "");
}
}
excelData.add(rowData);
}
fis.close();
return excelData;
}
解决方案
推荐阅读
- python - 使用 pandas.apply() 时在赋值之前引用的局部变量
- sql - 从 bigint 数组转换值
- javascript - 我无法更改导航栏中文本的颜色
- c++ - 使用类型别名声明可变参数函数
- azure - 如何限制对 Azure Function 的调用,N 次从给定的机器/IP
- apache-flink - 如何从数组列中获取数组元素
- django - 使用 django 发送文件
- python - 如何使用 OpenCV 增加我的面罩检测项目的 FPS?
- django - Heroku 运行 python manage.py makemigartions --app=
正在抛出 ImproperlyConfigured:设置 DATABASE_NAME 环境变量 - javascript - React App 加载 HomePage 而不是 Desired Page