使用apache poi从扩展名为xlsx的Excel文件中读取数据时,需要花费很长时间 [英] While Reading the data from Excel file with extension xlsx using apache poi it takes long time

查看:214
本文介绍了使用apache poi从扩展名为xlsx的Excel文件中读取数据时,需要花费很长时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用apache poi读取扩展名为xlsx的excel文件时,识别扩展名需要花费很长时间.您能帮忙吗,为什么要花很长时间?

While reading the excel file with extension xlsx using apache poi it takes the long time for identifying the extension. Can you please help why it takes the long time?

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内置了为您执行此操作的代码!

Promoting a comment to an answer - don't try to do this yourself, Apache POI has built-in code for doing this for you!

您应该使用

You should use WorkbookFactory.create(File) to do it, eg just

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

Apache POI文档所述,Apache POI文档应优先使用InputStream 用于更快和更低的内存处理

As explained in the Apache POI docs, use a File directly in preference to an InputStream for quicker and lower memory processing

这篇关于使用apache poi从扩展名为xlsx的Excel文件中读取数据时,需要花费很长时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆