簡體   English   中英

使用apache poi從擴展名為xlsx的Excel文件中讀取數據時,需要花費很長時間

[英]While Reading the data from Excel file with extension xlsx using apache poi it takes long time

使用apache poi讀取擴展名為xlsx的excel文件時,識別擴展名需要花費很長時間。 您能幫忙為什么要花很長時間?

if (file.getExcelFile().getOriginalFilename().endsWith("xls"))
    {
    workbook = new HSSFWorkbook(file.getExcelFile().getInputStream());
    } else if (file.getExcelFile().getOriginalFilename().endsWith("xlsx"))
    {
    workbook = new XSSFWorkbook(file.getExcelFile().getInputStream());
    } else {
    throw new IllegalArgumentException("Received file does not have a standard excel extension.");
    }

在評論中添加評論-不要自己做,Apache POI內置了為您執行此操作的代碼!

您應該使用WorkbookFactory.create(File)來做到這一點,例如

workbook = WorkbookFactory.create(file.getExcelFile());

Apache POI文檔中所述,直接使用File優先於InputStream來進行更快和更低的內存處理

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM