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();

Doc Holiday
  • 9,928
  • 32
  • 98
  • 151

2 Answers2

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>
brettjonesdev
  • 2,271
  • 1
  • 18
  • 23
  • 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 '16 at 06: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 '17 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. – Sh4d0wsPlyr Feb 05 '19 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);
Reimeus
  • 158,255
  • 15
  • 216
  • 276
  • import org.apache.poi.ss.usermodel.WorkbookFactory; – Doc Holiday Sep 10 '12 at 18:17
  • yeah, but question....by removing the old references to HSSF..how do I instantiate a new workbook? – Doc Holiday Sep 10 '12 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. – fIwJlxSzApHEZIl Sep 03 '14 at 00:29