[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.4' - sw/inc sw/qa sw/source

László Németh (via logerrit) logerrit at kemper.freedesktop.org
Wed Nov 11 10:36:25 UTC 2020


 sw/inc/cellfml.hxx                           |    2 -
 sw/qa/extras/ooxmlexport/data/tdf118682.fodt |    7 -----
 sw/qa/extras/ooxmlexport/data/tdf133163.fodt |   36 +++++++++++++++++++++++++++
 sw/qa/extras/ooxmlexport/ooxmlexport.cxx     |   14 ++++++++++
 sw/source/filter/ww8/docxattributeoutput.cxx |    4 +--
 sw/source/filter/ww8/wrtw8nds.cxx            |   14 +++++++++-
 6 files changed, 66 insertions(+), 11 deletions(-)

New commits:
commit 5c01715ad63ff850e1094a1d2536cea71690dbc8
Author:     László Németh <nemeth at numbertext.org>
AuthorDate: Thu Aug 13 12:05:20 2020 +0200
Commit:     Miklos Vajna <vmiklos at collabora.com>
CommitDate: Wed Nov 11 11:35:48 2020 +0100

    tdf#133163 DOCX: export formula cells
    
    as formula fields instead of exporting only cell
    text content.
    
    Only unmodified formula fields were exported from
    commit d42776e01b87f12fddbcf78101bca1e10a6e4f97
    (tdf#118682 DOCX: export formula fields).
    
    Now newly added Writer formula cells or modified
    table formula fields imported from DOCX (which are
    converted to formula cells after formula editing)
    are exported.
    
    (cherry picked from commit cf596c43315bb96b5e7256a82256f1ccb8c9c4d0)
    
    Conflicts:
            sw/source/filter/ww8/wrtw8nds.cxx
    
    Change-Id: Iecec75b2a36b94c2d3aa998603ac10ea2f2b8d4e
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/105576
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
    Reviewed-by: Miklos Vajna <vmiklos at collabora.com>

diff --git a/sw/inc/cellfml.hxx b/sw/inc/cellfml.hxx
index 67c2cee65d92..e37b9304bc11 100644
--- a/sw/inc/cellfml.hxx
+++ b/sw/inc/cellfml.hxx
@@ -119,7 +119,7 @@ public:
     SwTableFormula & operator =(SwTableFormula &&) = default;
 
     /// create from the internal formula (for CORE) the external formula (for UI)
-    void PtrToBoxNm( const SwTable* pTable );
+    SW_DLLPUBLIC void PtrToBoxNm( const SwTable* pTable );
     /// create from the external formula the internal
     void BoxNmToPtr( const SwTable* pTable );
     /// create from the external/internal formula the relative formula
diff --git a/sw/qa/extras/ooxmlexport/data/tdf118682.fodt b/sw/qa/extras/ooxmlexport/data/tdf118682.fodt
index 8979d7b2e4d8..b80074592da2 100644
--- a/sw/qa/extras/ooxmlexport/data/tdf118682.fodt
+++ b/sw/qa/extras/ooxmlexport/data/tdf118682.fodt
@@ -8,13 +8,6 @@
  </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>
diff --git a/sw/qa/extras/ooxmlexport/data/tdf133163.fodt b/sw/qa/extras/ooxmlexport/data/tdf133163.fodt
new file mode 100644
index 000000000000..8fdda1cdc556
--- /dev/null
+++ b/sw/qa/extras/ooxmlexport/data/tdf133163.fodt
@@ -0,0 +1,36 @@
+<?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>
+   <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 table:formula="ooow:<A1>+<A2>" office:value-type="float" office:value="3">
+      <text:p>3</text:p>
+     </table:table-cell>
+    </table:table-row>
+    <table:table-row>
+     <table:table-cell table:formula="ooow:SUM(<A1:A3>)" office:value-type="float" office:value="6">
+      <text:p>6</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 d9fe041ba24b..6c701c36d274 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
@@ -982,6 +982,20 @@ DECLARE_OOXMLEXPORT_TEST(testTdf118682, "tdf118682.fodt")
     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(testTdf133163, "tdf133163.fodt")
+{
+    xmlDocPtr pXmlDoc = parseExport();
+
+    // Formula cells 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 f2750d7c08b3..bce9737c7737 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -2138,8 +2138,8 @@ void DocxAttributeOutput::CmdField_Impl( const SwTextNode* pNode, sal_Int32 nPos
                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();
+               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
diff --git a/sw/source/filter/ww8/wrtw8nds.cxx b/sw/source/filter/ww8/wrtw8nds.cxx
index 74783f3e7110..2f6ff3c14cef 100644
--- a/sw/source/filter/ww8/wrtw8nds.cxx
+++ b/sw/source/filter/ww8/wrtw8nds.cxx
@@ -84,6 +84,7 @@
 #include <breakit.hxx>
 #include <txtatr.hxx>
 #include <fmtsrnd.hxx>
+#include <cellatr.hxx>
 #include <fmtrowsplt.hxx>
 #include <com/sun/star/drawing/XShape.hpp>
 #include <com/sun/star/i18n/BreakIterator.hpp>
@@ -2248,6 +2249,18 @@ void MSWordExportBase::OutputTextNode( SwTextNode& rNode )
         if ( pTableNode )
         {
             const SwTable& rTable = pTableNode->GetTable();
+            const SwTableBox* pBox = rNode.GetTableBox();
+
+            // export formula cell as formula field instead of only its cell content in DOCX
+            if ( pBox->IsFormulaOrValueBox() == RES_BOXATR_FORMULA &&
+                 GetExportFormat() == MSWordExportBase::ExportFormat::DOCX )
+            {
+                auto pFormula = static_cast<SwTableBoxFormula*>(pBox->GetFrameFormat()->GetTableBoxFormula().Clone());
+                pFormula->PtrToBoxNm( &pTableNode->GetTable() );
+                OutputField( nullptr, ww::eEquals, " = " + pFormula->GetFormula(),
+                    FieldFlags::Start | FieldFlags::CmdStart | FieldFlags::CmdEnd | FieldFlags::Close );
+            }
+
             const bool bKeep = rTable.GetFrameFormat()->GetKeep().GetValue();
             const bool bDontSplit = !rTable.GetFrameFormat()->GetLayoutSplit().GetValue();
             // bKeep handles this a different way later on, so ignore now
@@ -2255,7 +2268,6 @@ void MSWordExportBase::OutputTextNode( SwTextNode& rNode )
             {
                 // bDontSplit : set don't split once for the row
                 // but only for non-complex tables
-                const SwTableBox* pBox = rNode.GetTableBox();
                 const SwTableLine* pLine = pBox ? pBox->GetUpper() : nullptr;
                 if ( pLine && !pLine->GetUpper() )
                 {


More information about the Libreoffice-commits mailing list