gpt4 book ai didi

java - 如何使用java eclipse读取Excel页面的特定工作表

转载 作者:行者123 更新时间:2023-12-02 04:34:52 27 4
gpt4 key购买 nike

我想阅读 Excel 电子表格的第三张工作表并比较包含日期的 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....
}

关于java - 如何使用java eclipse读取Excel页面的特定工作表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30965320/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com