我有一个Excel,我只需要从中读取第一和第三列。我编写了以下代码来读取整个文件。请提出如何从中读取骨皮质柱的建议。
FileInputStream file = new FileInputStream(new File("D:/FinacleCredit/ecpix.xlsx"));
XSSFWorkbook workbook = new XSSFWorkbook(file);
Iterator<Row> rowIterator = sheet.iterator();
DataFormatter dataFormatter = new DataFormatter();
ArrayList<String> columndata = new ArrayList<String>();
while (rowIterator.hasNext())
{
Row row = rowIterator.next();
Iterator<Cell> cellIterator = row.cellIterator();
while (cellIterator.hasNext())
{
Cell cell = cellIterator.next();
String cellValue = dataFormatter.formatCellValue(cell);
System.out.print(cellValue + "\t");
switch (cell.getCellType()) {
case Cell.CELL_TYPE_NUMERIC:
columndata.add(cell.getNumericCellValue()+"");
break;
case Cell.CELL_TYPE_STRING:
columndata.add(cell.getStringCellValue());
break;
}
System.out.println("");
}
}
file.close();
最佳答案
您可以使用此方法获取每一行中的特定单元格:
Cell firstCell = row.getCell(0); // read first column
Cell thirdCell = row.getCell(2); // read third column