簡體   English   中英

如何使用Java Eclipse閱讀Excel頁面的特定工作表

[英]How to read specific sheet of an excel page using java eclipse

我想閱讀Excel電子表格的第3張紙,並比較包含日期的D列和F列。 如何閱讀這些專欄並在Eclipse中進行比較?

我想使用Apache POI

提前致謝。

FileInputStream file = new FileInputStream(new File("C:\\test.xls"));

//Get the workbook instance for XLS file 
HSSFWorkbook workbook = new HSSFWorkbook(file);

//Get third(numbering starts from 0) sheet from the workbook
HSSFSheet sheet = workbook.getSheetAt(2);

//Get iterator to all the rows in current sheet
Iterator<Row> rowIterator = sheet.iterator();

// Iterate through rows
while (rowIterator.hasNext()) {
    Row row = rowIterator.next();

    // Index of column D is 3 (A->0, B->1, etc)
    Cell cellD = row.getCell(3);
    Cell cellF = row.getCell(5);

    Date dateD = HSSFDateUtil.getJavaDate(cellD.getNumberValue()); 
    Date dateF = HSSFDateUtil.getJavaDate(cellF.getNumberValue()); 

    // Your business logic continues....
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM