summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLászló Németh <nemeth@numbertext.org>2020-08-13 12:05:20 +0200
committerLászló Németh <nemeth@numbertext.org>2020-08-14 09:13:03 +0200
commitcf596c43315bb96b5e7256a82256f1ccb8c9c4d0 (patch)
treeaa81fa39cefaeb670db98fc5278ea0bdadecc9d3
parent6457d46967f8dbb41199b750d59edde839f24b5d (diff)
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. Change-Id: Iecec75b2a36b94c2d3aa998603ac10ea2f2b8d4e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/100667 Tested-by: Jenkins Reviewed-by: László Németh <nemeth@numbertext.org>
-rw-r--r--sw/inc/cellfml.hxx2
-rw-r--r--sw/qa/extras/ooxmlexport/data/tdf118682.fodt7
-rw-r--r--sw/qa/extras/ooxmlexport/data/tdf133163.fodt36
-rw-r--r--sw/qa/extras/ooxmlexport/ooxmlexport.cxx14
-rw-r--r--sw/source/filter/ww8/docxattributeoutput.cxx4
-rw-r--r--sw/source/filter/ww8/wrtw8nds.cxx14
6 files changed, 66 insertions, 11 deletions
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:&lt;A1&gt;+&lt;A2&gt;" 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(&lt;A1:A3&gt;)" 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 f65b3afa0a3c..017fa21a6dec 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
@@ -996,6 +996,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")
+{
+ xmlDocUniquePtr 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 09bbad7e6e8b..5b44aec3c2c9 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -2153,8 +2153,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 cf719042ca9e..16add838383e 100644
--- a/sw/source/filter/ww8/wrtw8nds.cxx
+++ b/sw/source/filter/ww8/wrtw8nds.cxx
@@ -74,6 +74,7 @@
#include <fmtruby.hxx>
#include <breakit.hxx>
#include <txtatr.hxx>
+#include <cellatr.hxx>
#include <fmtrowsplt.hxx>
#include <com/sun/star/drawing/XShape.hpp>
#include <com/sun/star/i18n/BreakIterator.hpp>
@@ -2232,6 +2233,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 )
+ {
+ SwTableBoxFormula* pFormula = 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
@@ -2239,7 +2252,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() )
{