问题描述
除了制作工作簿的那一部分之外,我已经将HSSF中的所有旧代码都转换为SS.
I've converted all of my old code in HSSF to SS except for the portion where I make the work book.
旧代码:HSSFWorkbook wb =新的HSSFWorkbook(新的FileInputStream(文件));
Old Code:HSSFWorkbook wb = new HSSFWorkbook(new FileInputStream(file));
新的无效代码:Workbook [] wb2 = new Workbook [] {new FileInputStream};
New Non-working Code:Workbook[] wb2 = new Workbook[] {new FileInputStream};
这是网站提供的转化示例:
This is an example of conversion that the site gave:
新功能:Workbook [] wbs = new Workbook [] {new HSSFWorkbook(),new XSSFWorkbook()};OLD:HSSFWorkbook wb =新的HSSFWorkbook();
NEW: Workbook[] wbs = new Workbook[] { new HSSFWorkbook(), new XSSFWorkbook() };OLD: HSSFWorkbook wb = new HSSFWorkbook();
推荐答案
工作簿是一个接口,您无法实例化它.相反,您想要的是 WorkbookFactory .传递文件或InputStream,它将为您提供适当的Workbook实例
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
您的旧代码:
HSSFWorkbook wb = new HSSFWorkbook(new FileInputStream(file));
成为:
Workbook wb = WorkbookFactory.create(file);
这篇关于Apache Poi:从HSSF转换为SS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!