Hello, how I can get styles from existing docx document?
I need compare styles in docx document and dotx tempalte...
At first I need get styles, thanx a lot for advice!
It is currently Wed Apr 02, 2025 8:59 pm
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);
WARN JaxbValidationEventHandler : [ERROR] : unexpected element (uri:"http://schemas.openxmlformats.org/wordprocessingml/2006/main", local:"body"). Expected elements are <{http://schemas.microsoft.com/office/2006/xmlPackage}body>,<{http://schemas.microsoft.com/office/2006/xmlPackage}background>
INFO JaxbValidationEventHandler : continuing (with possible element/attribute loss)
Total posts 10157 • Total topics 2857 • Total members 2087