I'm trying to add a styles.xml file (with all the styles I need) to the xlsx spreadsheet i'm creating, using this code :
- Code: Select all
SpreadsheetMLPackage pkg = SpreadsheetMLPackage.createPackage();
factory = Context.getsmlObjectFactory();
WorksheetPart sheet = pkg.createWorksheetPart(new PartName("/xl/worksheets/sheet1.xml"), "Test Dossier", 1);
//Extract from file styles.xml
URL furl = ExcelWriter.class.getResource("styles.xml");
File knownstyles = new File(furl.toURI());
JAXBContext jc = org.docx4j.jaxb.Context.jc;
Unmarshaller u = jc.createUnmarshaller();
u.setEventHandler(new org.docx4j.jaxb.JaxbValidationEventHandler());
Styles styles = (Styles) u.unmarshal(knownstyles); //EXCEPTION THROWN HERE
pkg.addTargetPart(styles);
When I start the file creation, it throws an exception where I unmarshal. I uploaded it in a text file, because it's way too long to be put in a post.
Could you help me making this work ?
Thanks !