[英]How to read specific sheet of an excel page using java eclipse
I want to read the 3rd sheet of an Excel spreadsheet and compare column D and F which contain Date. 我想阅读Excel电子表格的第3张纸,并比较包含日期的D列和F列。 How to read these column and compare the same in Eclipse?
如何阅读这些专栏并在Eclipse中进行比较?
I would like to use Apache POI . 我想使用Apache POI 。
Thanks in advance. 提前致谢。
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.