diff options
author | Maxim Monastirsky <momonasmon@gmail.com> | 2020-02-21 02:35:55 +0200 |
---|---|---|
committer | Michael Stahl <michael.stahl@cib.de> | 2020-02-27 19:04:33 +0100 |
commit | 59ace23c367f83491a37e844d16f7d716eff6346 (patch) | |
tree | af47d9b808037e3af045678b60b73e47b6f1121f /xmloff/source/table | |
parent | 5352d45dd4a04f8f02cf7f6ad4169126d3b3586a (diff) |
tdf#101710 Fix invalid style:data-style-name attribute
There were two problems with this attribute:
1. It was written in style:table-cell-properties instead of
in style:style.
2. It was referencing a number format id, instead of a style
name. Moreover, the data style wasn't even exported as part
of office:styles (if at all).
Both import and export were affected. For export, it was easily
possible to reuse some related stuff from Calc, so that stuff
was moved into xmloff and used from there (there are no logic
changes for Calc). For import, loading of the invalid attribute
was kept for compat reasons. Although it's only useful for
automatic number formats, as the data styles weren't exported
properly anyway (e.g. see the document attached in bugzilla).
Change-Id: I8b70ad205972fada6f3845837d6ed5928d7d6406
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/89551
Tested-by: Jenkins
Reviewed-by: Michael Stahl <michael.stahl@cib.de>
Diffstat (limited to 'xmloff/source/table')
-rw-r--r-- | xmloff/source/table/XMLTableExport.cxx | 47 |
1 files changed, 45 insertions, 2 deletions
diff --git a/xmloff/source/table/XMLTableExport.cxx b/xmloff/source/table/XMLTableExport.cxx index 1970987f8129..a7d719ff1d75 100644 --- a/xmloff/source/table/XMLTableExport.cxx +++ b/xmloff/source/table/XMLTableExport.cxx @@ -31,6 +31,7 @@ #include <com/sun/star/table/XColumnRowRange.hpp> #include <com/sun/star/table/XMergeableCell.hpp> #include <com/sun/star/style/XStyle.hpp> +#include <com/sun/star/beans/XPropertyState.hpp> #include <com/sun/star/beans/XPropertySet.hpp> #include <com/sun/star/beans/XPropertySetInfo.hpp> #include <com/sun/star/lang/XMultiServiceFactory.hpp> @@ -142,6 +143,22 @@ sal_Int32 StringStatisticHelper::getModeString( OUString& rStyleName ) return nMax; } +namespace { + +class XMLCellExportPropertyMapper : public SvXMLExportPropertyMapper +{ +public: + using SvXMLExportPropertyMapper::SvXMLExportPropertyMapper; + /** this method is called for every item that has the + MID_FLAG_SPECIAL_ITEM_EXPORT flag set */ + virtual void handleSpecialItem(SvXMLAttributeList&, const XMLPropertyState&, const SvXMLUnitConverter&, + const SvXMLNamespaceMap&, const std::vector<XMLPropertyState>*, sal_uInt32) const override + { + // the SpecialItem NumberFormat must not be handled by this method + } +}; + +} XMLTableExport::XMLTableExport(SvXMLExport& rExp, const rtl::Reference< SvXMLExportPropertyMapper >& xExportPropertyMapper, const rtl::Reference< XMLPropertyHandlerFactory >& xFactoryRef ) : mrExport( rExp ) @@ -168,7 +185,7 @@ XMLTableExport::XMLTableExport(SvXMLExport& rExp, const rtl::Reference< SvXMLExp if (mbWriter) { - mxCellExportPropertySetMapper = new SvXMLExportPropertyMapper(new XMLTextPropertySetMapper(TextPropMap::CELL, true)); + mxCellExportPropertySetMapper = new XMLCellExportPropertyMapper(new XMLTextPropertySetMapper(TextPropMap::CELL, true)); } else { @@ -471,7 +488,7 @@ void XMLTableExport::exportTableStyles() if (mbWriter) { sCellStyleName = "CellStyles"; - aStEx.set(new XMLStyleExport(mrExport)); + aStEx.set(new XMLCellStyleExport(mrExport)); } else { @@ -662,4 +679,30 @@ void XMLTableExport::exportTableTemplates() } } +void XMLCellStyleExport::exportStyleContent(const Reference<XStyle>& /*rStyle*/) +{ +} + +void XMLCellStyleExport::exportStyleAttributes(const Reference<XStyle>& rStyle) +{ + Reference<XPropertySet> xPropSet(rStyle, UNO_QUERY); + if (xPropSet.is()) + { + Reference<XPropertySetInfo> xPropSetInfo(xPropSet->getPropertySetInfo()); + const OUString sNumberFormat("NumberFormat"); + if (xPropSetInfo->hasPropertyByName(sNumberFormat)) + { + Reference<XPropertyState> xPropState(xPropSet, UNO_QUERY); + if (xPropState.is() && (PropertyState_DIRECT_VALUE == + xPropState->getPropertyState(sNumberFormat))) + { + sal_Int32 nNumberFormat = 0; + if (xPropSet->getPropertyValue(sNumberFormat) >>= nNumberFormat) + GetExport().AddAttribute(XML_NAMESPACE_STYLE, XML_DATA_STYLE_NAME, + GetExport().getDataStyleName(nNumberFormat)); + } + } + } +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |