summaryrefslogtreecommitdiff
path: root/sw/source
diff options
context:
space:
mode:
authorLászló Németh <nemeth@numbertext.org>2020-08-17 14:00:54 +0200
committerLászló Németh <nemeth@numbertext.org>2020-08-17 23:30:21 +0200
commit82189fdc93ac337e1de3379d678eca6b7654e6fc (patch)
tree69d804ea4a0df683ecefa426ff47f6d7114f4f94 /sw/source
parent7da32109ecf9a269764603f8a8855268d5b1f8e3 (diff)
tdf133647 tdf123386 tdf123389 fix DOCX table formula export
Keep original DOCX table formula during round-trip using grab-bagging. This is a temporary solution until fixing formula export and a proposed solution for formula cannot be converted. Follow-up of commit 68e74bdf63e992666016c790e8e4cfd5b28d6abe (tdf133647 tdf123386 tdf123389 Improved .docx table formula import). Change-Id: Ia4759e250c06e9cc0495fb0b57fccd1ee1f50da9 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/100872 Tested-by: Jenkins Reviewed-by: László Németh <nemeth@numbertext.org>
Diffstat (limited to 'sw/source')
-rw-r--r--sw/source/filter/ww8/docxattributeoutput.cxx35
1 files changed, 30 insertions, 5 deletions
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx
index fd3c9aeb360b..81760cc044ab 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -2150,11 +2150,36 @@ void DocxAttributeOutput::CmdField_Impl( const SwTextNode* pNode, sal_Int32 nPos
}
else if ( rInfos.eType == ww::eEquals )
{
- UErrorCode nErr(U_ZERO_ERROR);
- icu::UnicodeString sInput(sToken.getStr());
- // remove < and > around cell references, e.g. <A1> to A1, <A1:B2> to A1:B2
- icu::RegexMatcher aMatcher("<([A-Z]{1,3}[0-9]+(:[A-Z]{1,3}[0-9]+)?)>", sInput, 0, nErr);
- sToken = aMatcher.replaceAll(icu::UnicodeString("$1"), nErr).getTerminatedBuffer();
+ // Use original OOXML formula, if it exists and its conversion hasn't been changed
+ bool bIsChanged = true;
+ if ( pNode->GetTableBox() )
+ {
+ if ( const SfxGrabBagItem* pItem = pNode->GetTableBox()->GetFrameFormat()->GetAttrSet().GetItem<SfxGrabBagItem>(RES_FRMATR_GRABBAG) )
+ {
+ OUString sActualFormula = sToken.trim();
+ const std::map<OUString, uno::Any>& rGrabBag = pItem->GetGrabBag();
+ std::map<OUString, uno::Any>::const_iterator aStoredFormula = rGrabBag.find("CellFormulaConverted");
+ if ( aStoredFormula != rGrabBag.end() && sActualFormula.indexOf('=') == 0 &&
+ sActualFormula.copy(1).trim() == aStoredFormula->second.get<OUString>().trim() )
+ {
+ aStoredFormula = rGrabBag.find("CellFormula");
+ if ( aStoredFormula != rGrabBag.end() )
+ {
+ sToken = " = " + aStoredFormula->second.get<OUString>();
+ bIsChanged = false;
+ }
+ }
+ }
+ }
+
+ if ( bIsChanged )
+ {
+ UErrorCode nErr(U_ZERO_ERROR);
+ icu::UnicodeString sInput(sToken.getStr());
+ // remove < and > around cell references, e.g. <A1> to A1, <A1:B2> to A1:B2
+ icu::RegexMatcher aMatcher("<([A-Z]{1,3}[0-9]+(:[A-Z]{1,3}[0-9]+)?)>", sInput, 0, nErr);
+ sToken = aMatcher.replaceAll(icu::UnicodeString("$1"), nErr).getTerminatedBuffer();
+ }
}
// Write the Field command