0

why not unable to compile :

POIFSFileSystem fs = new POIFSFileSystem(in);
Workbook wb=new HSSFWorkbook(fs);

the complier tell me "wb" should be HSSFWorkbook Object.

udevil
  • 1
  • 1
  • 1
    Workbook is only an interface. You can't create instances of an interface. – IQV Mar 16 '18 at 10:34
  • yes you can do that, it is the same as doing `List = new ArrayList`, List is an interface. And here, HSSFWorkbook implements Workbook – Bentaye Mar 16 '18 at 10:35
  • It should be possible and works for me, my suspition is you might not have the correct `Workbook` and `HSSFWorkbook` classes. Can you check your imports: these are the imports you should have: `import org.apache.poi.hssf.usermodel.HSSFWorkbook;` and `import org.apache.poi.ss.usermodel.Workbook;` – Bentaye Mar 16 '18 at 10:36
  • Thks, I have done. But not this problem! – udevil Mar 16 '18 at 16:18

1 Answers1

0

It should be possible as HSSFWorkbook implements the Workbook interface and it works for me, no compiling issue. My suspicion is you might not have the correct Workbook and HSSFWorkbook classes. Can you check your imports?

These are the imports you should have:

import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Workbook;
Bentaye
  • 9,403
  • 5
  • 32
  • 45