18

im doing a conversion of the HSSF model to XSSF. Im getting lil errors here and there. I donwloaded the latest POI and dropped all the jar files in and did the apache includes in my java class.....getting this error:

import org.apache.poi.ss.usermodel.Workbook;

Workbook wb = WorkbookFactory.create();

275: cannot find symbol [javac] symbol : variable WorkbookFactory [javac] location: class mil.usmc.logcom.chassis.util.HSSFUtils [javac] Workbook wb = WorkbookFactory.create();

2 Answers 2

102

If the question you are asking is how do you find the WorkbookFactory class, that's a good question. WorkbookFactory apparently does not reside in the poi.jar - it is in the poi-ooxml jar.

Add this dependency to your maven project and you should be able to import WorkbookFactory:

<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi-ooxml</artifactId>
    <version>3.9</version>
</dependency>
3
  • 4
    This answer must be the accepted answer as it is the exact solution to the problem described in the title. The number of upvotes also indicates the same thing.
    – Mohd Farid
    Jan 22, 2016 at 6:29
  • 1
    I had to check this question twice before I found the correct answer, as I didn't think the question was relevant, because of the accepted answer. Please register this as the accepted answer, and help us all out :)
    – jumps4fun
    Jan 16, 2017 at 14:40
  • 1
    As a followup to this - another person who (thankfully) skipped the accepted answer and found the solution. I highly recommend editing the question, since it seems to be the top result for similar searches. Feb 5, 2019 at 20:58
4

There is no zero-arg method for WorkbookFactory.create(). For example:

InputStream inp = new FileInputStream("workbook.xlsx");
Workbook wb = WorkbookFactory.create(inp);
3
  • import org.apache.poi.ss.usermodel.WorkbookFactory; Sep 10, 2012 at 18:17
  • yeah, but question....by removing the old references to HSSF..how do I instantiate a new workbook? Sep 10, 2012 at 18:24
  • 1
    Just for anyone else having trouble with this. Remember that a factory method means there's NO new syntax. If you're switching from direct instantiation of XSSFWorkBook to WorkbookFactory.create() make sure you delete your "new" statement or you'll get a weird error that looks like an import issue. Sep 3, 2014 at 0:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.