![](/img/trans.png)
[英]Can't read Excel 2010 file with Apache POI. First Row number is -1
[英]Apache POI only read the first row of a large Excel file
我可以使用Apache POI仅读取Excel文件的第一行吗? 我不想读取整个文件,因为它有50,000行,并且最多需要10分钟才能读取(性能是一场灾难)。 我通过文件上传获取字节。 我的选择是字节数组或InputStream。 现在我正在这样做:
Workbook workbook = new XSSFWorkbook(excelByteStream); //This line takes a lot of time, while debugging up to 10 minutes
Sheet firstSheet = workbook.getSheetAt(0);
DataFormatter df = new DataFormatter();
List<ColumnPanel> columnPanels = new ArrayList<>();
int i = 0;
for (Cell cell : firstSheet.getRow(0))
{
columnPanels.add(new ColumnPanel(df.formatCellValue(cell), i++));
}
InputStream是= new FileInputStream(new File(“ / path / to / workbook.xlsx”));
工作簿工作簿= StreamingReader.builder().rowCacheSize(100).bufferSize(4096).open(is);
工作表sheet = workBook.getSheetAt(0);
行firstRow = sheet.rowIterator()。next();
您可以使用以下库: https : //github.com/monitorjbl/excel-streaming-reader
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.