[Libreoffice-commits] core.git: 2 commits - sc/inc sc/qa sc/source

Kohei Yoshida kohei.yoshida at collabora.com
Sat Feb 15 16:09:11 CET 2014


 sc/inc/tokenstringcontext.hxx                       |    1 
 sc/qa/unit/data/ods/formula-quote-in-sheet-name.ods |binary
 sc/qa/unit/subsequent_export-test.cxx               |   26 ++++++++++++++++++++
 sc/source/core/tool/compiler.cxx                    |    1 
 sc/source/core/tool/tokenstringcontext.cxx          |    6 ++++
 sc/source/filter/xml/xmlexprt.cxx                   |   20 ++++++++++-----
 sc/source/filter/xml/xmlexprt.hxx                   |    7 +++++
 7 files changed, 54 insertions(+), 7 deletions(-)

New commits:
commit 9a5ce676ede4828db0acde5db79d91320575ec08
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Sat Feb 15 10:12:52 2014 -0500

    fdo#74512: Fix the ODS export as well.
    
    Change-Id: I54a2b2f405f9172d2ec5646346ef4e8a7ae27cb2

diff --git a/sc/inc/tokenstringcontext.hxx b/sc/inc/tokenstringcontext.hxx
index 3740f60..aa61ada 100644
--- a/sc/inc/tokenstringcontext.hxx
+++ b/sc/inc/tokenstringcontext.hxx
@@ -56,6 +56,7 @@ class CompileFormulaContext
 
 public:
     CompileFormulaContext( ScDocument* pDoc );
+    CompileFormulaContext( ScDocument* pDoc, formula::FormulaGrammar::Grammar eGram );
 
     formula::FormulaGrammar::Grammar getGrammar() const;
     void setGrammar( formula::FormulaGrammar::Grammar eGram );
diff --git a/sc/source/core/tool/compiler.cxx b/sc/source/core/tool/compiler.cxx
index 03be402..8835026 100644
--- a/sc/source/core/tool/compiler.cxx
+++ b/sc/source/core/tool/compiler.cxx
@@ -1612,6 +1612,7 @@ void ScCompiler::CheckTabQuotes( OUString& rString,
         case FormulaGrammar::CONV_XL_A1 :
         case FormulaGrammar::CONV_XL_R1C1 :
         case FormulaGrammar::CONV_XL_OOX :
+        case FormulaGrammar::CONV_ODF :
             if( bNeedsQuote )
             {
                 const OUString one_quote('\'');
diff --git a/sc/source/core/tool/tokenstringcontext.cxx b/sc/source/core/tool/tokenstringcontext.cxx
index 841867e..31bca19 100644
--- a/sc/source/core/tool/tokenstringcontext.cxx
+++ b/sc/source/core/tool/tokenstringcontext.cxx
@@ -111,6 +111,12 @@ CompileFormulaContext::CompileFormulaContext( ScDocument* pDoc ) :
     updateTabNames();
 }
 
+CompileFormulaContext::CompileFormulaContext( ScDocument* pDoc, formula::FormulaGrammar::Grammar eGram ) :
+    mpDoc(pDoc), meGram(eGram)
+{
+    updateTabNames();
+}
+
 void CompileFormulaContext::updateTabNames()
 {
     // Fetch all sheet names.
diff --git a/sc/source/filter/xml/xmlexprt.cxx b/sc/source/filter/xml/xmlexprt.cxx
index f1d247c..fa4c440 100644
--- a/sc/source/filter/xml/xmlexprt.cxx
+++ b/sc/source/filter/xml/xmlexprt.cxx
@@ -63,6 +63,7 @@
 #include <arealink.hxx>
 #include <datastream.hxx>
 #include <documentlinkmgr.hxx>
+#include <tokenstringcontext.hxx>
 
 #include <xmloff/xmltoken.hxx>
 #include <xmloff/xmlnmspe.hxx>
@@ -3177,21 +3178,26 @@ void ScXMLExport::WriteCell(ScMyCell& aCell, sal_Int32 nEqualCellCount)
             {
                 if (aCell.maBaseCell.meType == CELLTYPE_FORMULA)
                 {
-                    OUStringBuffer sFormula;
                     ScFormulaCell* pFormulaCell = aCell.maBaseCell.mpFormula;
                     if (!bIsMatrix || (bIsMatrix && bIsFirstMatrixCell))
                     {
-                        const formula::FormulaGrammar::Grammar eGrammar = pDoc->GetStorageGrammar();
-                        sal_uInt16 nNamespacePrefix = (eGrammar == formula::FormulaGrammar::GRAM_ODFF ? XML_NAMESPACE_OF : XML_NAMESPACE_OOOC);
-                        pFormulaCell->GetFormula(sFormula, eGrammar);
-                        OUString sOUFormula(sFormula.makeStringAndClear());
+                        if (!mpCompileFormulaCxt)
+                        {
+                            const formula::FormulaGrammar::Grammar eGrammar = pDoc->GetStorageGrammar();
+                            mpCompileFormulaCxt.reset(new sc::CompileFormulaContext(pDoc, eGrammar));
+                        }
+
+                        OUString aFormula = pFormulaCell->GetFormula(*mpCompileFormulaCxt);
+                        sal_uInt16 nNamespacePrefix =
+                            (mpCompileFormulaCxt->getGrammar() == formula::FormulaGrammar::GRAM_ODFF ? XML_NAMESPACE_OF : XML_NAMESPACE_OOOC);
+
                         if (!bIsMatrix)
                         {
-                            AddAttribute(sAttrFormula, GetNamespaceMap().GetQNameByKey( nNamespacePrefix, sOUFormula, false ));
+                            AddAttribute(sAttrFormula, GetNamespaceMap().GetQNameByKey(nNamespacePrefix, aFormula, false));
                         }
                         else
                         {
-                            AddAttribute(sAttrFormula, GetNamespaceMap().GetQNameByKey( nNamespacePrefix, sOUFormula.copy(1, sOUFormula.getLength() - 2), false ));
+                            AddAttribute(sAttrFormula, GetNamespaceMap().GetQNameByKey(nNamespacePrefix, aFormula.copy(1, aFormula.getLength()-2), false));
                         }
                     }
                     if (pFormulaCell->GetErrCode())
diff --git a/sc/source/filter/xml/xmlexprt.hxx b/sc/source/filter/xml/xmlexprt.hxx
index b4b2681..6f60531 100644
--- a/sc/source/filter/xml/xmlexprt.hxx
+++ b/sc/source/filter/xml/xmlexprt.hxx
@@ -63,6 +63,12 @@ class ScXMLEditAttributeMap;
 class EditTextObject;
 class ScFormulaCell;
 
+namespace sc {
+
+class CompileFormulaContext;
+
+}
+
 typedef std::vector< com::sun::star::uno::Reference < com::sun::star::drawing::XShapes > > ScMyXShapesVec;
 
 class ScXMLExport : public SvXMLExport
@@ -76,6 +82,7 @@ class ScXMLExport : public SvXMLExport
 
     mutable boost::scoped_ptr<ScXMLEditAttributeMap> mpEditAttrMap;
     boost::scoped_ptr<ScMyNotEmptyCellsIterator> mpCellsItr;
+    boost::scoped_ptr<sc::CompileFormulaContext> mpCompileFormulaCxt;
     UniReference < XMLPropertyHandlerFactory >  xScPropHdlFactory;
     UniReference < XMLPropertySetMapper >       xCellStylesPropertySetMapper;
     UniReference < XMLPropertySetMapper >       xColumnStylesPropertySetMapper;
commit f45ce989589654128c08294dd4e7ba5c89dcb255
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Sat Feb 15 09:34:57 2014 -0500

    fdo#74512: Add export test for this.
    
    Change-Id: I7582ff84c3a31f294f241ca642915361509768a1

diff --git a/sc/qa/unit/data/ods/formula-quote-in-sheet-name.ods b/sc/qa/unit/data/ods/formula-quote-in-sheet-name.ods
new file mode 100644
index 0000000..ef66f21
Binary files /dev/null and b/sc/qa/unit/data/ods/formula-quote-in-sheet-name.ods differ
diff --git a/sc/qa/unit/subsequent_export-test.cxx b/sc/qa/unit/subsequent_export-test.cxx
index 2db6307..26fc12a 100644
--- a/sc/qa/unit/subsequent_export-test.cxx
+++ b/sc/qa/unit/subsequent_export-test.cxx
@@ -67,6 +67,7 @@ public:
     void testMiscRowHeightExport();
     void testNamedRangeBugfdo62729();
     void testRichTextExportODS();
+    void testFormulaRefSheetNameODS();
 
     void testCellValuesExportODS();
     void testCellNoteExportODS();
@@ -90,6 +91,7 @@ public:
     CPPUNIT_TEST(testMiscRowHeightExport);
     CPPUNIT_TEST(testNamedRangeBugfdo62729);
     CPPUNIT_TEST(testRichTextExportODS);
+    CPPUNIT_TEST(testFormulaRefSheetNameODS);
     CPPUNIT_TEST(testCellValuesExportODS);
     CPPUNIT_TEST(testCellNoteExportODS);
     CPPUNIT_TEST(testCellNoteExportXLS);
@@ -674,6 +676,30 @@ void ScExportTest::testRichTextExportODS()
     xNewDocSh3->DoClose();
 }
 
+void ScExportTest::testFormulaRefSheetNameODS()
+{
+    ScDocShellRef xDocSh = loadDoc("formula-quote-in-sheet-name.", ODS, true);
+    ScDocument* pDoc = xDocSh->GetDocument();
+
+    sc::AutoCalcSwitch aACSwitch(*pDoc, true); // turn on auto calc.
+    pDoc->SetString(ScAddress(1,1,0), "='90''s Data'.B2");
+    CPPUNIT_ASSERT_EQUAL(1.1, pDoc->GetValue(ScAddress(1,1,0)));
+    if (!checkFormula(*pDoc, ScAddress(1,1,0), "'90''s Data'.B2"))
+        CPPUNIT_FAIL("Wrong formula");
+
+    // Now, save and reload this document.
+    ScDocShellRef xNewDocSh = saveAndReload(xDocSh, ODS);
+    xDocSh->DoClose();
+
+    pDoc = xNewDocSh->GetDocument();
+    pDoc->CalcAll();
+    CPPUNIT_ASSERT_EQUAL(1.1, pDoc->GetValue(ScAddress(1,1,0)));
+    if (!checkFormula(*pDoc, ScAddress(1,1,0), "'90''s Data'.B2"))
+        CPPUNIT_FAIL("Wrong formula");
+
+    xNewDocSh->DoClose();
+}
+
 void ScExportTest::testCellValuesExportODS()
 {
     // Start with an empty document


More information about the Libreoffice-commits mailing list