SpreadsheetML -> FlatOPC
Posted:
Wed Jan 18, 2012 12:17 pm
by andyask
Hi,
Is it possible to read in a xlsx document, then flatten it, saving the FlatOPC?
I know this is possible with the WordprocessingMLPackage, but based on the parameter types for FlatOpcXmlCreator.getFlatDomDocument(), it doesn't appear that this is supported at the moment?
Cheers,
Andy
Re: SpreadsheetML -> FlatOPC
Posted:
Wed Jan 18, 2012 1:05 pm
by jason
Hi, as per
http://blogs.msdn.com/b/ericwhite/archi ... ormat.aspx Excel 2007 does not import/export from Flat OPC. 2010 doesn't appear to export to that format (so you'd expect it not to import, either, but I haven't tested that).
It would be straightforward to alter FlatOpcXmlCreator to support it; in fact a quick glance at the source code suggest you ought to be able to use the existing class by rolling your own replacement for getFlatDomDocument. Should be as simple as
Using java Syntax Highlighting
public static Document getFlatDomDocument
(SpreadsheetMLPackage
spreadsheetMLPackage ) throws Docx4JException
{
FlatOpcXmlCreator worker
= new FlatOpcXmlCreator
(spreadsheetMLPackage
);
org.
docx4j.
xmlPackage.
Package pkg = worker.
get();
org.
w3c.
dom.
Document doc
;
try {
JAXBContext jc
= Context.
jcXmlPackage;
Marshaller marshaller
=jc.
createMarshaller();
doc
= org.
docx4j.
XmlUtils.
neww3cDomDocument();
marshaller.
marshal(pkg, doc
);
} catch (JAXBException e
) {
throw new Docx4JException
("Couldn't marshal Flat OPC to DOM", e
);
}
return doc
;
}
Parsed in 0.016 seconds, using
GeSHi 1.0.8.4
Re: SpreadsheetML -> FlatOPC
Posted:
Fri Jan 20, 2012 1:29 pm
by andyask
Hi Jason,
Thanks for that example. Your code worked first try, and I am flattening my sheets nicely now.
Cheers,
Andy Askinvaurgg