Apache Poi: Converting from HSSF to SS?

a 夏天 提交于 2019-12-02 08:10:50

问题


I've converted all of my old code in HSSF to SS except for the portion where I make the work book.


Old Code: HSSFWorkbook wb = new HSSFWorkbook(new FileInputStream(file));


New Non-working Code: Workbook[] wb2 = new Workbook[] {new FileInputStream};


This is an example of conversion that the site gave:

NEW: Workbook[] wbs = new Workbook[] { new HSSFWorkbook(), new XSSFWorkbook() }; OLD: HSSFWorkbook wb = new HSSFWorkbook();


回答1:


Workbook is an interface, you can't instantiate it. Instead, what you want is WorkbookFactory. Pass that either a File or an InputStream, and it'll give you the appropriate Workbook instance

Your old code:

HSSFWorkbook wb = new HSSFWorkbook(new FileInputStream(file));

Becomes:

Workbook wb = WorkbookFactory.create(file);


来源:https://stackoverflow.com/questions/10854646/apache-poi-converting-from-hssf-to-ss

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!