通过流创建工作簿
public static Workbook batchImportData(InputStream in) throws Exception {
if (in == null) {
throw new Exception("文件不得为空!");
}
try
{
return WorkbookFactory.create(in);
}
catch
{
return null;
}
}
POI常用方法
通过sheet的索引
org.apache.poi.ss.usermodel.Sheet s = wb.getSheetAt(0);
通过sheet的name
org.apache.poi.ss.usermodel.Sheet s = wb.getSheetAt(name);
获得行数
int num = s.getPhysicalNumberOfRows()
获得某一行通过索引
Row row = s.getRow(10)
获得某列数
Row row = s.getRow(10)
int num = row.getPhysicalNumberOfCells();
获得单元格的内容
String cellValue = row.getCell(6).toString();