import org.apache.poi.poifs.crypt.Decryptor;
import org.apache.poi.poifs.filesystem.FileMagic;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
+import org.apache.xmlbeans.XmlCursor;
+import org.apache.xmlbeans.XmlObject;
public final class POIXMLDocumentHandler {
protected void handlePOIXMLDocument(POIXMLDocument doc) throws Exception {
}
return false;
}
+
+ /**
+ * Recurse through the document and convert all elements so they are available in the ooxml-lite jar.
+ * This method only makes sense for hierarchical documents like .docx.
+ * If the document is split up in different parts like in .pptx, each part needs to be provided.
+ *
+ * @param base the entry point
+ */
+ protected static void cursorRecursive(XmlObject base) {
+ XmlCursor cur = base.newCursor();
+ try {
+ if (!cur.toFirstChild()) {
+ return;
+ }
+ do {
+ cursorRecursive(cur.getObject());
+ } while (cur.toNextSibling());
+ } finally {
+ cur.dispose();
+ }
+ }
}
import org.apache.poi.poifs.crypt.Decryptor;
import org.apache.poi.poifs.crypt.EncryptionInfo;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
+import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.util.IOUtils;
import org.apache.poi.util.NullPrintStream;
import org.apache.poi.xssf.eventusermodel.XSSFReader;
import org.apache.poi.xssf.extractor.XSSFExportToXml;
import org.apache.poi.xssf.usermodel.XSSFMap;
+import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.junit.jupiter.api.Test;
import org.xml.sax.SAXException;
// also verify general POIFS-stuff
new POIXMLDocumentHandler().handlePOIXMLDocument(wb);
+ POIXMLDocumentHandler.cursorRecursive(wb.getCTWorkbook());
+ for (Sheet sh : wb) {
+ POIXMLDocumentHandler.cursorRecursive(((XSSFSheet)sh).getCTWorksheet());
+ }
+
// and finally ensure that exporting to XML works
exportToXML(wb);
try (XWPFDocument doc = new XWPFDocument(stream)) {
new POIXMLDocumentHandler().handlePOIXMLDocument(doc);
+ POIXMLDocumentHandler.cursorRecursive(doc.getDocument());
} catch (POIXMLException e) {
Exception cause = (Exception)e.getCause();
throw cause == null ? e : cause;
exports com.microsoft.schemas.office.excel;
exports com.microsoft.schemas.office.office;
exports com.microsoft.schemas.office.visio.x2012.main;
+ exports com.microsoft.schemas.office.word;
exports com.microsoft.schemas.office.x2006.digsig;
exports com.microsoft.schemas.vml;
exports org.apache.poi.schemas.ooxml.system.ooxml;