java程序将一张多个sheet的Excel文档,导入数据库中
1个回答
展开全部
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;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |