java程序将一张多个sheet的Excel文档,导入数据库中
发布网友
发布时间:2022-04-23 23:31
我来回答
共1个回答
热心网友
时间:2023-11-04 19:07
Workbook excelWB = null;
excelWB = new XSSFWorkbook(excelFile);
oneSheet = excelWB.getSheetAt(0);
oneRow = oneSheet.getRow(rowNum);
if (oneRow == null) {
continue;
}// 获取第几列对象
oneCell = oneRow.getCell(1);
if (oneCell == null) {
continue;
}
switch (oneCell.getCellType()) {
case HSSFCell.CELL_TYPE_STRING:
System.out.println(oneCell.getStringCellValue());
break;
case HSSFCell.CELL_TYPE_FORMULA:
System.out.println(oneCell.getCellFormula());
break;
case HSSFCell.CELL_TYPE_NUMERIC:
HSSFDataFormatter dataFormatter = new HSSFDataFormatter();
String cellFormatted = dataFormatter.formatCellValue(oneCell);
System.out.println( cellFormatted );
break;
case HSSFCell.CELL_TYPE_ERROR:
break;
}
将读取到的value处理下insert到表中即可
追问这段代码上好多方法和属性都报错的啊
追答poi的jar需要加载下
oneRow = oneSheet.getRow(0);
这个地方可以改成0;