[Libreoffice-commits] core.git: Branch 'distro/lhm/libreoffice-6-1+backports' - filter/source sc/qa sc/source
Libreoffice Gerrit user
logerrit at kemper.freedesktop.org
Tue Dec 18 11:46:26 UTC 2018
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 33e7c210f6d1e676ebbc8bfa48a2284a3f32c5d3
Author: Vasily Melenchuk <vasily.melenchuk at cib.de>
AuthorDate: Thu Dec 13 15:47:38 2018 +0100
Commit: Thorsten Behrens <Thorsten.Behrens at CIB.de>
CommitDate: Tue Dec 18 12:46:04 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: I8041d861be6e0beefe683d01e7a63989cbdf7940
Reviewed-on: https://gerrit.libreoffice.org/65111
Tested-by: Jenkins
Reviewed-by: Thorsten Behrens <Thorsten.Behrens at CIB.de>
Reviewed-on: https://gerrit.libreoffice.org/65330
Tested-by: Thorsten Behrens <Thorsten.Behrens at 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 d414b1abfb96..a036931d1c0b 100644
--- a/sc/qa/unit/helper/qahelper.cxx
+++ b/sc/qa/unit/helper/qahelper.cxx
@@ -81,7 +81,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 f8d522e65387..410e8c7e80be 100644
--- a/sc/qa/unit/helper/qahelper.hxx
+++ b/sc/qa/unit/helper/qahelper.hxx
@@ -54,6 +54,7 @@
#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
@@ -67,6 +68,7 @@
#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 2fb53a18ac3c..3b006b1f5e12 100644
--- a/sc/qa/unit/subsequent_export-test.cxx
+++ b/sc/qa/unit/subsequent_export-test.cxx
@@ -212,6 +212,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)
{
@@ -4088,6 +4093,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 1bda7dc820ca..f3b2f5663240 100644
--- a/sc/source/filter/excel/xestream.cxx
+++ b/sc/source/filter/excel/xestream.cxx
@@ -912,10 +912,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)
{
}
@@ -1077,11 +1078,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 bb5192e22351..93f7b123b079 100644
--- a/sc/source/filter/inc/xestream.hxx
+++ b/sc/source/filter/inc/xestream.hxx
@@ -280,7 +280,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. */
@@ -360,6 +360,7 @@ private:
XclExpXmlPathToStateMap maOpenedStreamMap;
bool mbExportVBA;
+ bool const mbExportTemplate;
};
#endif
diff --git a/sc/source/filter/oox/excelfilter.cxx b/sc/source/filter/oox/excelfilter.cxx
index 006c4818e48a..725dcc8f3384 100644
--- a/sc/source/filter/oox/excelfilter.cxx
+++ b/sc/source/filter/oox/excelfilter.cxx
@@ -225,7 +225,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 );
More information about the Libreoffice-commits
mailing list