0
我使用Apache poi导入我在桌面区域中的.xlsx文件。每次读取一行/只读特定列并创建对象
用下面的代码我可以读取我想要的孔表。
但是我想每次只读一行,每行只读特定的列(例如我只想从第一行开始将列A,F和G保存为对象,然后第二行也是这样,第三行等)
我该怎么办?
public class main {
public static void main(String[] args) throws Exception {
InputStream ExcelFileToRead = new FileInputStream("C:/User/Desktop/test.xlsx");
XSSFWorkbook wb = new XSSFWorkbook(ExcelFileToRead);
XSSFSheet sheet=wb.getSheetAt(0);
XSSFRow row;
XSSFCell cell;
Iterator rows = sheet.rowIterator();
while (rows.hasNext())
{
row=(XSSFRow) rows.next();
Iterator cells = row.cellIterator();
while (cells.hasNext())
{
cell=(XSSFCell) cells.next();
if (cell.getCellType() == XSSFCell.CELL_TYPE_STRING)
{
System.out.print(cell.getStringCellValue()+" ");
}
else if(cell.getCellType() == XSSFCell.CELL_TYPE_NUMERIC)
{
System.out.print(cell.getNumericCellValue()+" ");
}
else
{
}
}
System.out.println();
}
}
}
你有没有[尝试阅读遍历行和单元格在Apache POI文件(http://poi.apache.org/spreadsheet/quick-guide。 HTML#迭代器)?所有这一切?当你做什么时会发生什么? (提示 - 您需要的答案在文档中!) – Gagravarr