到apache网站下载poi-2.5.1.jar,加入到classpath下.
InputStream inputStream = new FileInputStream("D:/a.xls");
HSSFWorkbook workBook = new HSSFWorkbook(inputStream); // 工作薄
HSSFSheet sheet = workBook.getSheetAt(0); // 第一个工作表
int rowCount = sheet.getPhysicalNumberOfRows(); // 工作表中记录的行数
HSSFRow row;
HSSFCell cell;
for (int r = 0; r <= rowCount; r++) {
row = sheet.getRow(r); // 循环得到每一行
if (row != null) {
cell = row.getCell((short) 0); // 取得第一个单元格
if (cell.getCellType() == HSSFCell.CELL_TYPE_STRING) {
String str = cell.getStringCellValue();
}else {
Double dbl = cell.getNumericCellValue();
}
}
}
用poi读取excel
最新推荐文章于 2023-09-21 09:59:18 发布