03
/**
* 03版本
* @throws IOException
*/
@Test
public void testRead03() throws IOException {
//获取文件流
FileInputStream fileInputStream = new FileInputStream("E:\\practice\\poi-test\\" + "test1.xls");
//获取工作簿
Workbook workbook = new HSSFWorkbook(fileInputStream);
//获取工作表
Sheet sheet = workbook.getSheet("表名");
//获取行
Row row = sheet.getRow(1);
//获取单元格
Cell cell = row.getCell(2);
//单元格赋值
String stringCellValue = cell.getStringCellValue();
//输出
System.out.println(stringCellValue);
fileInputStream.close();
}
07
/**
* 07版本
* @throws IOException
*/
@Test
public void testRead07() throws IOException {
//获取文件流
FileInputStream fileInputStream = new FileInputStream("E:\\practice\\poi-test\\" + "test1.xlsx");
//获取工作簿
Workbook workbook = new XSSFWorkbook(fileInputStream);
//获取工作表
Sheet sheet = workbook.getSheet("表名");
//获取行
Row row = sheet.getRow(1);
//获取单元格
Cell cell = row.getCell(2);
//单元格赋值
String stringCellValue = cell.getStringCellValue();
//输出
System.out.println(stringCellValue);
fileInputStream.close();
}
cell类型判断
if (cell != null){
CellType cellType = cell.getCellType();
switch (cellType){
case _NONE:
break;
case NUMERIC:
break;
case STRING:
case FORMULA:
break;
case BLANK:
break;
case BOOLEAN:
break;
case ERROR:
break;
}
}