问题
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