sw/Library_msword.mk | 1 sw/qa/extras/ooxmlexport/data/tdf118682.fodt | 43 +++++++++++++++++++++++++++ sw/qa/extras/ooxmlexport/ooxmlexport.cxx | 14 ++++++++ sw/source/filter/ww8/docxattributeoutput.cxx | 9 +++++ sw/source/filter/ww8/ww8atr.cxx | 7 ++++ 5 files changed, 74 insertions(+)
New commits: commit 55f3e080909a874c6e977d0d95458f36bbd38037 Author: László Németh <nem...@numbertext.org> AuthorDate: Tue Aug 11 19:32:52 2020 +0200 Commit: Xisco Fauli <xiscofa...@libreoffice.org> CommitDate: Wed Sep 2 12:18:06 2020 +0200 tdf#118682 DOCX: export formula fields Convert also cell references by removing parenthesization: =<A1>+<B1> -> =A1*B1 =SUM(<A1:ZZ99> -> =SUM(A1:ZZ99) See tdf#133647 for fixing import of cell references. Change-Id: I5082198aaf8230989f99984f8129b54867b77859 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/100546 Tested-by: Jenkins Reviewed-by: László Németh <nem...@numbertext.org> Signed-off-by: Xisco Fauli <xiscofa...@libreoffice.org> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/101892 diff --git a/sw/Library_msword.mk b/sw/Library_msword.mk index 7433a839b303..74c66073c83f 100644 --- a/sw/Library_msword.mk +++ b/sw/Library_msword.mk @@ -68,6 +68,7 @@ $(eval $(call gb_Library_use_libraries,msword,\ $(eval $(call gb_Library_use_externals,msword,\ boost_headers \ + icui18n \ icuuc \ icu_headers \ libxml2 \ diff --git a/sw/qa/extras/ooxmlexport/data/tdf118682.fodt b/sw/qa/extras/ooxmlexport/data/tdf118682.fodt new file mode 100644 index 000000000000..8979d7b2e4d8 --- /dev/null +++ b/sw/qa/extras/ooxmlexport/data/tdf118682.fodt @@ -0,0 +1,43 @@ +<?xml version="1.0" encoding="UTF-8"?> +<office:document xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:officeooo="http://openoffice.org/2009/office" xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0" xmlns:ooow="http://openoffice.org/2004/writer" office:version="1.2" office:mimetype="application/vnd.oasis.opendocument.text"> + <office:styles> + <style:style style:name="Standard" style:family="paragraph" style:class="text"/> + <style:default-style style:family="paragraph"> + <style:text-properties fo:language="en" fo:country="US"/> + </style:default-style> + </office:styles> + <office:body> + <office:text> + <text:sequence-decls> + <text:sequence-decl text:display-outline-level="0" text:name="Illustration"/> + <text:sequence-decl text:display-outline-level="0" text:name="Table"/> + <text:sequence-decl text:display-outline-level="0" text:name="Text"/> + <text:sequence-decl text:display-outline-level="0" text:name="Drawing"/> + <text:sequence-decl text:display-outline-level="0" text:name="Figure"/> + </text:sequence-decls> + <table:table> + <table:table-column/> + <table:table-row> + <table:table-cell office:value-type="string"> + <text:p>1</text:p> + </table:table-cell> + </table:table-row> + <table:table-row> + <table:table-cell office:value-type="string"> + <text:p>2</text:p> + </table:table-cell> + </table:table-row> + <table:table-row> + <table:table-cell office:value-type="string"> + <text:p><text:table-formula text:formula="ooow: <A1>+<A2>" style:data-style-name="N0">3</text:table-formula></text:p> + </table:table-cell> + </table:table-row> + <table:table-row> + <table:table-cell office:value-type="string"> + <text:p><text:table-formula text:formula="ooow:SUM(<A1:A3>)" style:data-style-name="N0">6</text:table-formula></text:p> + </table:table-cell> + </table:table-row> + </table:table> + </office:text> + </office:body> +</office:document> diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx index 133c2add7822..0e66e4055be6 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx @@ -971,6 +971,20 @@ DECLARE_OOXMLEXPORT_TEST(testTdf44986, "tdf44986.docx") CPPUNIT_ASSERT_EQUAL(OUString(""), uno::Reference<text::XTextRange>(xTable->getCellByName("B1"), uno::UNO_QUERY_THROW)->getString()); } +DECLARE_OOXMLEXPORT_TEST(testTdf118682, "tdf118682.fodt") +{ + // Support cell references in table formulas + xmlDocUniquePtr pXmlDoc = parseExport(); + + // Formula fields were completely missing. + assertXPath(pXmlDoc, "/w:document/w:body/w:tbl/w:tr[3]/w:tc/w:p/w:r/w:fldChar", 3); + assertXPath(pXmlDoc, "/w:document/w:body/w:tbl/w:tr[4]/w:tc/w:p/w:r/w:fldChar", 3); + + // Cell references were parenthesized: <A1>+<A2> and SUM(<A1:A3>) + assertXPathContent(pXmlDoc, "/w:document/w:body/w:tbl/w:tr[3]/w:tc/w:p/w:r[2]/w:instrText", " = A1+A2"); + assertXPathContent(pXmlDoc, "/w:document/w:body/w:tbl/w:tr[4]/w:tc/w:p/w:r[2]/w:instrText", " = SUM(A1:A3)"); +} + DECLARE_OOXMLEXPORT_TEST(testTdf106953, "tdf106953.docx") { uno::Reference<container::XIndexAccess> xRules = getProperty< uno::Reference<container::XIndexAccess> >(getStyles("NumberingStyles")->getByName("WWNum1"), "NumberingRules"); diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx index 82727d587bc1..1ab5f3caf43a 100644 --- a/sw/source/filter/ww8/docxattributeoutput.cxx +++ b/sw/source/filter/ww8/docxattributeoutput.cxx @@ -146,6 +146,7 @@ #include <toolkit/helper/vclunohelper.hxx> #include <oox/mathml/export.hxx> +#include <unicode/regex.h> using ::editeng::SvxBorderLine; @@ -2149,6 +2150,14 @@ void DocxAttributeOutput::CmdField_Impl( const SwTextNode* pNode, sal_Int32 nPos sToken = sToken.replaceAll("NNNN", "dddd"); sToken = sToken.replaceAll("NN", "ddd"); } + 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 xMatch("<([A-Z]{1,3}[0-9]+(:[A-Z]{1,3}[0-9]+)?)>", sInput, 0, nErr); + sToken = xMatch.replaceAll(icu::UnicodeString("$1"), nErr).getTerminatedBuffer(); + } // Write the Field command DoWriteCmd( sToken ); diff --git a/sw/source/filter/ww8/ww8atr.cxx b/sw/source/filter/ww8/ww8atr.cxx index 4272bce9eebc..04f35eb23aaa 100644 --- a/sw/source/filter/ww8/ww8atr.cxx +++ b/sw/source/filter/ww8/ww8atr.cxx @@ -3260,6 +3260,13 @@ void AttributeOutputBase::TextField( const SwFormatField& rField ) GetExport().OutputField( pField, ww::eMACROBUTTON, sStr ); } break; + case SwFieldIds::Table: + { + ww::eField eField = ww::eEquals; + OUString aExpand = FieldString(eField) + pField->GetFieldName(); + GetExport().OutputField(pField, eField, aExpand); + } + break; case SwFieldIds::User: { ww::eField eField = ww::eDOCVARIABLE; _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits