0
votes

Currently I'm trying to implement the code given in the answer to this question:

CTSheetView view =  sheet.getCTWorksheet().getSheetViews().getSheetViewArray(0);
view.setView(STSheetViewType.PAGE_LAYOUT);

but the poi-ooxml-schemas (version 3.14) JAR file does not contain the class STSheetViewType. I delved into the poi-ooxml-schemas JAR file (using 7ZIP) and found that the class file STSheetViewType$Enum.class existed within the path:

org.openxmlformats.schemas.spreadsheetml.x2006.main.STSheetViewType$Enum.class

But (If I'm not mistaken) The '$' signifies an inner/nested class, meaning the STSheetViewType Enum is encapsulated within another class. I checked the documentation on the STSheetViewType class in an older version of poi-ooxml-schemas (version 1.1) here and found that the class STSheetViewType contained an inner Enum STSheetViewType.Enum.

This also seems to be confirmed by the errors I'm receiving from within Eclipse. I get these errors when using the code shown above:

"STSheetViewType cannot be resolved to a variable"

"The type org.openxmlformats.schemas.spreadsheetml.x2006.main.STSheetViewType cannot be resolved. It is indirectly referenced from required .class files"

Which further makes me believe that the STSheetViewType.Enum is missing its parent STSheetViewType class file. But why? I checked the documentation on the new version of poi-ooxml-schemas-3.14 and found no mention of STSheetViewType in the changelogs. I've downloaded the binary zip file for POI several times to ensure that my download wasn't faulty, I even downloaded the source and tried building the JARs but the class file is missing each time.

I found that a class STSheetViewType with seemingly the same functionality is held in another Jar file here but I can't seem to import the class correctly. Is such a thing even possible? Or must the class file come with the poi-ooxml-schemas-3.14 JAR file?

Ultimately I'd like to find out how to make the above code compatible with the current version of poi-ooxml-schemas-3.14 JAR. Any information or insight shed on that would be greatly appreciated.

1
To using STSheetViewType the fully ooxml-schemas-1.3.jar is needed as mentioned in poi.apache.org/faq.html#faq-N10025. So download ooxml-schemas-1.3.jar and put it in the class path. But you could try STSheetViewType.Enum.forString("pageLayout"); without this additional jar since the class Enum is static - not tested.Axel Richter

1 Answers

3
votes

As pointed out by @AxelRichter and the FAQ, Apache POI 3.14 and above uses a subset of classes from the ooxml-schemas-1.3.jar. You need to get that jar file and include in your classpath instead of poi-ooxml-schemas-3.14.jar. POI only provides the ooxml schemas classes it requires. When you begin to directly call ooxml schema classes in your own code, you most likely have to get the full jar that has all ooxml schemas classes to avoid this kind of issue you have. You can get the jar from maven central:

http://central.maven.org/maven2/org/apache/poi/ooxml-schemas/1.3/

See also the FAQ entry at http://poi.apache.org/faq.html#faq-N10025