public void testIn() {
try {
// 读取Excel中数据
HSSFWorkbook workbook = new HSSFWorkbook(new FileInputStream("D:\\test.xls"));
HSSFSheet sheet = workbook.getSheetAt(0);
HSSFRow row = null;
HSSFCell cell = null;
int rowIndex = 0;
while (true) {
String name = null;
row = sheet.getRow(rowIndex);
if (row == null) {
break;
}
cell = row.getCell(0);
if (cell != null) {
name = cell.getStringCellValue();
}
String code = null;
cell = row.getCell(1);
if (cell != null) {
code = cell.getStringCellValue();
}
System.out.println(name + " " + code);
rowIndex++;
}
} catch (Exception e) {
e.printStackTrace();
}
}
poi简单读取excel内容
最新推荐文章于 2022-06-17 17:33:01 发布