Bug 58146 - Unable to simply create Theme in new XSSFWorkbook
Summary: Unable to simply create Theme in new XSSFWorkbook
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: XSSF (show other bugs)
Version: 3.12-FINAL
Hardware: PC Linux
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-07-16 14:18 UTC by Piotr
Modified: 2015-08-03 07:33 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Piotr 2015-07-16 14:18:11 UTC
Is it is possible to create empty Theme if I create XSSFWorkbook by constructor XSSFWorkbook()?
I tried to do this, but there is a lot of fields (like Relations) to fill when I create Theme - and finally I have to do something like reading inputStream. But I don’t have IS, because I want create new workbook and fill everything using data from external JSON file.
I checked that constructor XSSFWorkbook() creates objects like StylesSource and SharedStringsTable, but not ThemesTable. So maybe it’ impossible to change Theme after constructor, because in fact it changes nothing?
Creating Theme is so complicated (or maybe impossible now), so I tried to do this in some other ways too:
1) I tried to: import empty XLSX file to ApachePOI, get Theme from it and set this Theme to my new XSSFWorkbook. But then my new XLSX file doesn’t have file /xl/theme/theme1.xml and informations: <Override ContentType="application/vnd.openxmlformats-officedocument.theme+xml" PartName="/xl/theme/theme1.xml" /> in content_types.xml, <Override ContentType="application/vnd.openxmlformats-officedocument.theme+xml" PartName="/xl/theme/theme1.xml" /> in /xl/_rels/workbook.xml.rels.
2) Then I tried to not create new XSSFWorkbook, but: import external XLSX file, change its Theme and save again as XLSX. Then file has informations about Theme, but about original - not changed.
Comment 1 Piotr 2015-07-21 12:58:19 UTC
After some days I can create new Theme without reading anything from external file. I can create two entries in files content_types.xml and /xl/_rels/workbook.xml.rels:
    XSSFWorkbook xssfWorkbook = new XSSFWorkbook();
    POIXMLDocumentPart docThemePart = xssfWorkbook.createRelationship(XSSFRelation.THEME, XSSFFactory.getInstance(), 1);
Normally it’s not possible in ApachePOI, because it causes error. I had to MODIFY(!) ApachePOI ThemesTable class - I added constructor:
    public ThemesTable() { super(); }
Then function above creates file /xl/theme/theme1.xml too, but it’s empty. How to fill this file? If I get Theme
    ThemesTable theme = (ThemesTable) docThemePart;
and change it, content is not wrote to theme.xml. How to fill this file?
I checked Zip creating. Method marshall() in ZipPartMarshaller class gets input stream from some workbook parts. And for Theme input stream is empty. Maybe that’s the problem? When I tried (for tests) to create other object:
    xssfWorkbook.createRelationship(XSSFRelation.CHART, XSSFFactory.getInstance());
everything was good.