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 d42776e01b87f12fddbcf78101bca1e10a6e4f97
Author:     László Németh <nem...@numbertext.org>
AuthorDate: Tue Aug 11 19:32:52 2020 +0200
Commit:     László Németh <nem...@numbertext.org>
CommitDate: Wed Aug 12 09:40:46 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>

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: &lt;A1&gt;+&lt;A2&gt;" 
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(&lt;A1:A3&gt;)" 
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 e97482af86cc..f65b3afa0a3c 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
@@ -982,6 +982,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 4d59477f9d68..7c15faf5e424 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -144,6 +144,7 @@
 #include <stdarg.h>
 
 #include <toolkit/helper/vclunohelper.hxx>
+#include <unicode/regex.h>
 
 using ::editeng::SvxBorderLine;
 
@@ -2145,6 +2146,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 2fa8d29d8807..16068c0e3c52 100644
--- a/sw/source/filter/ww8/ww8atr.cxx
+++ b/sw/source/filter/ww8/ww8atr.cxx
@@ -3211,6 +3211,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

Reply via email to