// 讀取Excel
public static void main(String[] args) {
File file = new File("D:\\test.xlsx");
XSSFWorkbook xssfWorkbook = null;
InputStream inputStream = null;
try {
inputStream = new FileInputStream(file);
xssfWorkbook = new XSSFWorkbook(inputStream); //報錯行
Sheet sheet = xssfWorkbook.getSheetAt(0);
int row_num = sheet.getLastRowNum();
for (int j = 0; j < row_num; j++) {
Row row = sheet.getRow(j);
int num = row.getRowNum();
for (int i = 0; i < num; i++) {
Cell cell = row.getCell(i);
System.out.println(cell.getStringCellValue());
}
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (xssfWorkbook != null)
xssfWorkbook.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
uj5u.com熱心網友回復:
運行環境沒有引入相關的jar包轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/263120.html
標籤:Java相關
