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 doing above things to enable ooxml export because the existing code are FAR FAR AWAY from product, have big gaps. 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 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 above 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 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 responsible for exporting corresponding OOXML XXX objects 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 exporting OOXML data.

Back to this example, in order to activate XclExpXmlStream, we need to add a method filter to ExcelFilter. Then once export XLSX files, this method will called from sfx2 automatically. In this method, we need to create a service, let's say "com.sun.star.comp.Calc.OOXMLExporter" and also need to implement this service in XclExpXmlStream. Then call the service, now XclExpXmlStream will take over the detailed export works.

  • Register service and component at application side

Now the final step is to register the service and a component at application side. In this example, we need to register a "com.sun.star.comp.Calc.OOXMLExporter"  service and a service component to XclExpXmlStream. It is the most important and most complicated step. Please follow this wiki to get detail: https://wiki.openoffice.org/wiki/Uno/Cpp/Tutorials/component_tutorial

Now all works done, XclExpXmlStream should get worked when export a XLSX file.

PPTX and DOCX Export Framework

The framework of PPTX export is same with that of XLSX. DOCX is similar. But as sw is using gbuild but sc sd are still using dmake, the last step of previous section, register service and component, has some differences. I will not introduce in detail in this wiki.

 

  • No labels