filter/source/config/fragments/filters/calc_MS_Excel_2007_XML_Template.xcu | 2 filter/source/config/fragments/filters/calc_OOXML_Template.xcu | 2 filter/source/config/fragments/types/MS_Excel_2007_XML_Template.xcu | 2 sc/qa/unit/helper/qahelper.cxx | 3 sc/qa/unit/helper/qahelper.hxx | 2 sc/qa/unit/subsequent_export-test.cxx | 21 ++++++ sc/source/filter/excel/xestream.cxx | 31 ++++++++-- sc/source/filter/inc/xestream.hxx | 3 sc/source/filter/oox/excelfilter.cxx | 2 9 files changed, 56 insertions(+), 12 deletions(-)
New commits: commit 8cc29e7040ed02afd5f979e23c9ec154c0cb2c83 Author: Vasily Melenchuk <vasily.melenc...@cib.de> AuthorDate: Thu Dec 13 15:47:38 2018 +0100 Commit: Thorsten Behrens <thorsten.behr...@cib.de> CommitDate: Mon Dec 17 15:54:14 2018 +0100 tdf#99438: sc: support for .xltx export Added support for content types for template and template with macros (.xltm, but no user interface for this yet). Fixed preferred extension for template: by default it is .xltx and not .xltm (macro-enabled), because MS Excel is very strict about matching of content-type and extension here. Fixed wrong namespace in FilterService for ExcelFilter. Change-Id: Ie717d31d72203601324860f069918d75082add4a Reviewed-on: https://gerrit.libreoffice.org/65111 Tested-by: Jenkins Reviewed-by: Thorsten Behrens <thorsten.behr...@cib.de> diff --git a/filter/source/config/fragments/filters/calc_MS_Excel_2007_XML_Template.xcu b/filter/source/config/fragments/filters/calc_MS_Excel_2007_XML_Template.xcu index f42c60d71630..db5cb9a21390 100644 --- a/filter/source/config/fragments/filters/calc_MS_Excel_2007_XML_Template.xcu +++ b/filter/source/config/fragments/filters/calc_MS_Excel_2007_XML_Template.xcu @@ -16,7 +16,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . --> <node oor:name="Calc MS Excel 2007 XML Template" oor:op="replace"> - <prop oor:name="Flags"><value>IMPORT ALIEN 3RDPARTYFILTER TEMPLATE TEMPLATEPATH</value></prop> + <prop oor:name="Flags"><value>IMPORT EXPORT ALIEN 3RDPARTYFILTER TEMPLATE TEMPLATEPATH</value></prop> <prop oor:name="UIComponent"/> <prop oor:name="FilterService"><value>com.sun.star.comp.oox.xls.ExcelFilter</value></prop> <prop oor:name="UserData"/> diff --git a/filter/source/config/fragments/filters/calc_OOXML_Template.xcu b/filter/source/config/fragments/filters/calc_OOXML_Template.xcu index 848e7ee38fe8..b65a756088be 100644 --- a/filter/source/config/fragments/filters/calc_OOXML_Template.xcu +++ b/filter/source/config/fragments/filters/calc_OOXML_Template.xcu @@ -18,7 +18,7 @@ <node oor:name="Calc Office Open XML Template" oor:op="replace"> <prop oor:name="Flags"><value>IMPORT ALIEN 3RDPARTYFILTER TEMPLATE TEMPLATEPATH</value></prop> <prop oor:name="UIComponent"/> - <prop oor:name="FilterService"><value>com.sun.star.comp.oox.ExcelFilter</value></prop> + <prop oor:name="FilterService"><value>com.sun.star.comp.oox.xls.ExcelFilter</value></prop> <prop oor:name="UserData"><value>OOXML</value></prop> <prop oor:name="FileFormatVersion"><value>1</value></prop> <prop oor:name="Type"><value>Office Open XML Spreadsheet Template</value></prop> diff --git a/filter/source/config/fragments/types/MS_Excel_2007_XML_Template.xcu b/filter/source/config/fragments/types/MS_Excel_2007_XML_Template.xcu index c55f6393bb5a..35c18e47ac30 100644 --- a/filter/source/config/fragments/types/MS_Excel_2007_XML_Template.xcu +++ b/filter/source/config/fragments/types/MS_Excel_2007_XML_Template.xcu @@ -18,7 +18,7 @@ <node oor:name="MS Excel 2007 XML Template" oor:op="replace" > <prop oor:name="DetectService"><value>com.sun.star.comp.oox.FormatDetector</value></prop> <prop oor:name="URLPattern"/> - <prop oor:name="Extensions"><value>xltm xltx</value></prop> + <prop oor:name="Extensions"><value>xltx xltm</value></prop> <prop oor:name="MediaType"><value>application/vnd.openxmlformats-officedocument.spreadsheetml.template</value></prop> <prop oor:name="Preferred"><value>false</value></prop> <prop oor:name="PreferredFilter"><value>Calc MS Excel 2007 XML Template</value></prop> diff --git a/sc/qa/unit/helper/qahelper.cxx b/sc/qa/unit/helper/qahelper.cxx index e3b2db0cbec4..81c4431f7512 100644 --- a/sc/qa/unit/helper/qahelper.cxx +++ b/sc/qa/unit/helper/qahelper.cxx @@ -87,7 +87,8 @@ const FileFormat ScBootstrapFixture::aFileFormats[] = { { "xml", "MS Excel 2003 XML Orcus", "calc_MS_Excel_2003_XML", XLS_XML_FORMAT_TYPE }, { "xlsb", "Calc MS Excel 2007 Binary", "MS Excel 2007 Binary", XLSB_XML_FORMAT_TYPE }, { "fods", "OpenDocument Spreadsheet Flat XML", "calc_ODS_FlatXML", FODS_FORMAT_TYPE }, - { "gnumeric", "Gnumeric Spreadsheet", "Gnumeric XML", GNUMERIC_FORMAT_TYPE } + { "gnumeric", "Gnumeric Spreadsheet", "Gnumeric XML", GNUMERIC_FORMAT_TYPE }, + { "xltx", "Calc Office Open XML Template", "Office Open XML Spreadsheet Template", XLTX_FORMAT_TYPE } }; bool testEqualsWithTolerance( long nVal1, long nVal2, long nTol ) diff --git a/sc/qa/unit/helper/qahelper.hxx b/sc/qa/unit/helper/qahelper.hxx index 2482248a1754..96268dbb9272 100644 --- a/sc/qa/unit/helper/qahelper.hxx +++ b/sc/qa/unit/helper/qahelper.hxx @@ -47,6 +47,7 @@ namespace utl { class TempFile; } #define XLSB_XML_FORMAT_TYPE (SfxFilterFlags::IMPORT | SfxFilterFlags::ALIEN | SfxFilterFlags::STARONEFILTER | SfxFilterFlags::PREFERED) #define FODS_FORMAT_TYPE (SfxFilterFlags::IMPORT | SfxFilterFlags::EXPORT | SfxFilterFlags::OWN | SfxFilterFlags::STARONEFILTER ) #define GNUMERIC_FORMAT_TYPE (SfxFilterFlags::IMPORT | SfxFilterFlags::ALIEN | SfxFilterFlags::PREFERED ) +#define XLTX_FORMAT_TYPE (SfxFilterFlags::IMPORT | SfxFilterFlags::EXPORT | SfxFilterFlags::TEMPLATE |SfxFilterFlags::ALIEN | SfxFilterFlags::STARONEFILTER | SfxFilterFlags::PREFERED) #define FORMAT_ODS 0 #define FORMAT_XLS 1 @@ -60,6 +61,7 @@ namespace utl { class TempFile; } #define FORMAT_XLSB 9 #define FORMAT_FODS 10 #define FORMAT_GNUMERIC 11 +#define FORMAT_XLTX 12 enum class StringType { PureString, StringValue }; diff --git a/sc/qa/unit/subsequent_export-test.cxx b/sc/qa/unit/subsequent_export-test.cxx index fcfb60f3fbf7..5b1ff5fa66a0 100644 --- a/sc/qa/unit/subsequent_export-test.cxx +++ b/sc/qa/unit/subsequent_export-test.cxx @@ -209,6 +209,8 @@ public: void testTdf118990(); void testTdf121612(); + void testXltxExport(); + CPPUNIT_TEST_SUITE(ScExportTest); CPPUNIT_TEST(test); CPPUNIT_TEST(testTdf111876); @@ -323,6 +325,8 @@ public: CPPUNIT_TEST(testTdf118990); CPPUNIT_TEST(testTdf121612); + CPPUNIT_TEST(testXltxExport); + CPPUNIT_TEST_SUITE_END(); private: @@ -356,6 +360,7 @@ void ScExportTest::registerNamespaces(xmlXPathContextPtr& pXmlXPathCtx) { BAD_CAST("r"), BAD_CAST("http://schemas.openxmlformats.org/package/2006/relationships") }, { BAD_CAST("number"), BAD_CAST("urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0") }, { BAD_CAST("loext"), BAD_CAST("urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0") }, + { BAD_CAST("ContentType"), BAD_CAST("http://schemas.openxmlformats.org/package/2006/content-types") }, }; for(size_t i = 0; i < SAL_N_ELEMENTS(aNamespaces); ++i) { @@ -4189,6 +4194,22 @@ void ScExportTest::testTdf121612() CPPUNIT_ASSERT_EQUAL(size_t(1), pDPColl->GetCount()); } +void ScExportTest::testXltxExport() +{ + // Create new document + ScDocShell* pShell = new ScDocShell( + SfxModelFlags::EMBEDDED_OBJECT | + SfxModelFlags::DISABLE_EMBEDDED_SCRIPTS | + SfxModelFlags::DISABLE_DOCUMENT_RECOVERY); + pShell->DoInitNew(); + + // Export as template and check content type + xmlDocPtr pDoc = XPathHelper::parseExport2(*this, *pShell, m_xSFactory, "[Content_Types].xml", FORMAT_XLTX); + CPPUNIT_ASSERT(pDoc); + assertXPath(pDoc, "/ContentType:Types/ContentType:Override[@PartName='/xl/workbook.xml']", + "ContentType", "application/vnd.openxmlformats-officedocument.spreadsheetml.template.main+xml"); +} + CPPUNIT_TEST_SUITE_REGISTRATION(ScExportTest); CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sc/source/filter/excel/xestream.cxx b/sc/source/filter/excel/xestream.cxx index 45178df49279..3455b741164c 100644 --- a/sc/source/filter/excel/xestream.cxx +++ b/sc/source/filter/excel/xestream.cxx @@ -911,10 +911,11 @@ sax_fastparser::FSHelperPtr XclXmlUtils::WriteFontData( sax_fastparser::FSHelper return pStream; } -XclExpXmlStream::XclExpXmlStream( const uno::Reference< XComponentContext >& rCC, bool bExportVBA ) +XclExpXmlStream::XclExpXmlStream( const uno::Reference< XComponentContext >& rCC, bool bExportVBA, bool bExportTemplate ) : XmlFilterBase( rCC ), mpRoot( nullptr ), - mbExportVBA(bExportVBA) + mbExportVBA(bExportVBA), + mbExportTemplate(bExportTemplate) { } @@ -1076,11 +1077,29 @@ bool XclExpXmlStream::exportDocument() ScDocShell::GetViewData()->WriteExtOptions( mpRoot->GetExtDocOptions() ); OUString const workbook = "xl/workbook.xml"; - const char* pWorkbookContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml"; - - + const char* pWorkbookContentType = nullptr; if (mbExportVBA) - pWorkbookContentType = "application/vnd.ms-excel.sheet.macroEnabled.main+xml"; + { + if (mbExportTemplate) + { + pWorkbookContentType = "application/vnd.ms-excel.template.macroEnabled.main+xml"; + } + else + { + pWorkbookContentType = "application/vnd.ms-excel.sheet.macroEnabled.main+xml"; + } + } + else + { + if (mbExportTemplate) + { + pWorkbookContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.template.main+xml"; + } + else + { + pWorkbookContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml"; + } + } PushStream( CreateOutputStream( workbook, workbook, uno::Reference <XOutputStream>(), diff --git a/sc/source/filter/inc/xestream.hxx b/sc/source/filter/inc/xestream.hxx index 5b10d6a1bf3c..20cd69085c98 100644 --- a/sc/source/filter/inc/xestream.hxx +++ b/sc/source/filter/inc/xestream.hxx @@ -275,7 +275,7 @@ public: class XclExpXmlStream : public oox::core::XmlFilterBase { public: - XclExpXmlStream( const css::uno::Reference< css::uno::XComponentContext >& rCC, bool bExportVBA ); + XclExpXmlStream( const css::uno::Reference< css::uno::XComponentContext >& rCC, bool bExportVBA, bool bExportTemplate ); virtual ~XclExpXmlStream() override; /** Returns the filter root data. */ @@ -355,6 +355,7 @@ private: XclExpXmlPathToStateMap maOpenedStreamMap; bool const mbExportVBA; + bool const mbExportTemplate; }; #endif diff --git a/sc/source/filter/oox/excelfilter.cxx b/sc/source/filter/oox/excelfilter.cxx index e638d0df7c82..c5fda17bd919 100644 --- a/sc/source/filter/oox/excelfilter.cxx +++ b/sc/source/filter/oox/excelfilter.cxx @@ -227,7 +227,7 @@ sal_Bool SAL_CALL ExcelFilter::filter( const css::uno::Sequence< css::beans::Pro { bool bExportVBA = exportVBA(); Reference< XExporter > xExporter( - new XclExpXmlStream( getComponentContext(), bExportVBA ) ); + new XclExpXmlStream( getComponentContext(), bExportVBA, isExportTemplate() ) ); Reference< XComponent > xDocument( getModel(), UNO_QUERY ); Reference< XFilter > xFilter( xExporter, UNO_QUERY ); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits