Basic OOXML Export approach
Apache OpenOffice already has ooxml export framework in code base 4.1, but has not been published. These code exist by 2 different ways:
1) Code was already there and also got compiled, but there's no entry to call them
2) Code was there but has been dropped from makefile so that will not have compile
So we have two ways to enable these code correspondingly. For case 1, just add entry so that can activate ooxml filter and call them; for case 2, enable compiling for the source file in makefile. But due to those source files which has never been compiled was contributed earlier so that are not based on the current code base, they probably meet many compile errors which need to be fixed. Of course it is not so easy as just do above things to enable ooxml export because the existing code are far away from product. They have many mistakes and misses which need to improve.
XLSX Export Framework
Let me use XLSX export as a example.
- Activate XLSX export choice in calc_MS_Excel_2007_XML.xcu
In current code base 4.1, filter\source\config\fragments\filters\calc_MS_Excel_2007_XML.xcu, who defines XLSX files filter service, you can find below code:
<node oor:name="Calc MS Excel 2007 XML" oor:op="replace">
<prop oor:name="Flags"><value>IMPORT ALIEN 3RDPARTYFILTER PREFERRED</value></prop>
<prop oor:name="UIComponent"/>
<prop oor:name="FilterService"><value>com.sun.star.comp.oox.xls.ExcelFilter</value></prop>
<prop oor:name="UserData"/>
<prop oor:name="FileFormatVersion"/>
<prop oor:name="Type"><value>MS Excel 2007 XML</value></prop>
Note there is only "IMPORT" in these code, that's why we have no choice of XLSX in file save dialog. First we need to add "EXPORT" in above code then XLSX export will be activated.
- Register XLSX export service in oox\source\xls\excelfilter.cxx & oox\util\oox.component
In this file a service name was already defined as "com.sun.star.comp.oox.xls.ExcelFilter". See oox\source\xls\excelfilter.cxx, a object ExcelFilter was already there, and it implemented services of "com.sun.star.comp.oox.xls.ExcelFilter". See code:
OUString SAL_CALL ExcelFilter_getImplementationName() throw()
{
return CREATE_OUSTRING( "com.sun.star.comp.oox.xls.ExcelFilter" );
}
... ...
OUString ExcelFilter::implGetImplementationName() const
{
return ExcelFilter_getImplementationName();
}
And it supports both import and export services. See definition in oox\util\oox.component:
<implementation name="com.sun.star.comp.oox.xls.ExcelFilter">
<service name="com.sun.star.document.ImportFilter"/>
<service name="com.sun.star.document.ExportFilter"/>
</implementation>
- Add XLSX export entry point in oox\source\xls\excelfilter.cxx
In fact ExcelFilter is only a entry point of XLSX export, it isn't responsible for real export but will delegate to other object in sc module. In fact, in AOO code, real OOXML export is owned by each individual application, say sc, sd, sw. Usually export filters in application layer are located in the same folder as binary filters and use similar logic.
For example, in sc\source\filter\excel\xestream.cxx there are two classes, XclExpStream and XclExpXmlStream. XclExpStream is responsible exporting binary files, XclExpXmlStream is responsible for exporting OOXML files. Similar as binary filter, OOXML filters also export elements from parent to child and usually XclExpXmlXXX classes are OOXML specific and they have a SaveXml method for exporting their data. However, some classes are shared by both binary and OOXML filter. In this case, a Save method is for exporting binary data, a SaveXml method is for export OOXML data.