有什么办法来读取使用Apache POI都.xls和.XLSX文件? [英] Is there any way to read both .xls and .xlsx files using Apache POI?

查看:136
本文介绍了有什么办法来读取使用Apache POI都.xls和.XLSX文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要创建一个可以读取XLS和XLSX文件的方法。根据我的研究,HSSF用于读取XLS和XSSF阅读XLSX。有没有在Apache POI的一部分,我可以用它来阅读这两个文件?我也遇到了ss.usermodel却发现没有足够的codeS,将娱乐都XLS和XLSX ....

I need to create a method that can read both xls and xlsx files. According to my research, HSSF is used to read xls and XSSF to read xlsx. Is there a part of the Apache POI I can use to read both files? I also came across the ss.usermodel but found no sufficient codes that will entertain both xls and xlsx....

推荐答案

我没有太多EXP与Apache POI,但据我所知,如果你按类工作簿是指一个工作簿,然后您可以读取和写这两个XLS和放大器; XLSX。

I haven't had much exp with Apache POI, but as far as i know if you refer to a workbook by class "Workbook" then you can read and write both xls & xlsx.

所有你需要做的创建对象的写时

All you have to do is when creating object write

有关的.xls -

for .xls-

Workbook wb = new HSSFWorkbook();

有关的.xlsx -

for .xlsx-

Workbook wb = new XSSFWorkbook();

您可以通过文件类型的参数,并相应地创建工作簿对象使用if语句。

you can pass a parameter for file type and create the WorkBook object accordingly using If statement.

这篇关于有什么办法来读取使用Apache POI都.xls和.XLSX文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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