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

Markus Mohrhard markus.mohrhard at collabora.co.uk
Tue Dec 23 19:28:38 PST 2014


 sc/qa/unit/data/xlsb/shared_formula.xlsb  |binary
 sc/qa/unit/subsequent_filters-test.cxx    |   23 +++++++++++++++++++++++
 sc/source/filter/inc/sheetdatabuffer.hxx  |   14 +++++++++-----
 sc/source/filter/inc/worksheethelper.hxx  |    2 +-
 sc/source/filter/oox/formulaparser.cxx    |    2 +-
 sc/source/filter/oox/sheetdatabuffer.cxx  |   19 ++++++++++++++-----
 sc/source/filter/oox/sheetdatacontext.cxx |    7 ++++++-
 7 files changed, 54 insertions(+), 13 deletions(-)

New commits:
commit 4bc2212a048cde9fc17728eaad4d8637468c1586
Author: Markus Mohrhard <markus.mohrhard at collabora.co.uk>
Date:   Wed Dec 24 04:25:03 2014 +0100

    add test for fdo#86734
    
    Change-Id: I1789f9a4ec2f1dec62ea0958bca03e5e2fcd1fc6

diff --git a/sc/qa/unit/data/xlsb/shared_formula.xlsb b/sc/qa/unit/data/xlsb/shared_formula.xlsb
new file mode 100644
index 0000000..b304e08
Binary files /dev/null and b/sc/qa/unit/data/xlsb/shared_formula.xlsb differ
diff --git a/sc/qa/unit/subsequent_filters-test.cxx b/sc/qa/unit/subsequent_filters-test.cxx
index d556335..f27a5c2 100644
--- a/sc/qa/unit/subsequent_filters-test.cxx
+++ b/sc/qa/unit/subsequent_filters-test.cxx
@@ -173,6 +173,7 @@ public:
     void testSharedFormulaHorizontalXLS();
     void testSharedFormulaWrappedRefsXLS();
     void testSharedFormulaBIFF5();
+    void testSharedFormulaXLSB();
     void testExternalRefCacheXLSX();
     void testExternalRefCacheODS();
     void testHybridSharedStringODS();
@@ -255,6 +256,7 @@ public:
     CPPUNIT_TEST(testSharedFormulaHorizontalXLS);
     CPPUNIT_TEST(testSharedFormulaWrappedRefsXLS);
     CPPUNIT_TEST(testSharedFormulaBIFF5);
+    CPPUNIT_TEST(testSharedFormulaXLSB);
     CPPUNIT_TEST(testExternalRefCacheXLSX);
     CPPUNIT_TEST(testExternalRefCacheODS);
     CPPUNIT_TEST(testHybridSharedStringODS);
@@ -2556,6 +2558,27 @@ void ScFiltersTest::testSharedFormulaBIFF5()
     xDocSh->DoClose();
 }
 
+void ScFiltersTest::testSharedFormulaXLSB()
+{
+    ScDocShellRef xDocSh = loadDoc("shared_formula.", XLSB);
+    CPPUNIT_ASSERT(xDocSh.Is());
+    ScDocument& rDoc = xDocSh->GetDocument();
+    rDoc.CalcAll();
+
+    // E6:E376 should be all formulas, and they should belong to the same group.
+    const ScFormulaCell* pFC = rDoc.GetFormulaCell(ScAddress(0,0,0));
+    CPPUNIT_ASSERT(pFC);
+    CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(0), pFC->GetSharedTopRow());
+    CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(30), pFC->GetSharedLength());
+
+    for(SCROW nRow = 0; nRow < 30; ++nRow)
+    {
+        ASSERT_DOUBLES_EQUAL(3.0, rDoc.GetValue(0, nRow, 0));
+    }
+
+    xDocSh->DoClose();
+}
+
 void ScFiltersTest::testExternalRefCacheXLSX()
 {
     ScDocShellRef xDocSh = loadDoc("external-refs.", XLSX);
commit cb5509987469531f7a10544a3b793abd534d0c78
Author: Markus Mohrhard <markus.mohrhard at collabora.co.uk>
Date:   Wed Dec 24 04:12:18 2014 +0100

    OSL_ENSURE => SAL_WARN
    
    Change-Id: I175701912a4cf0d9c661327a31e37a43902b1915

diff --git a/sc/source/filter/oox/formulaparser.cxx b/sc/source/filter/oox/formulaparser.cxx
index 8bba050..51f79bc 100644
--- a/sc/source/filter/oox/formulaparser.cxx
+++ b/sc/source/filter/oox/formulaparser.cxx
@@ -596,7 +596,7 @@ ApiTokenSequence FormulaParserImpl::importOoxFormula( const CellAddress&, const
 
 ApiTokenSequence FormulaParserImpl::importBiff12Formula( const CellAddress&, FormulaType, SequenceInputStream& )
 {
-    OSL_FAIL( "FormulaParserImpl::importBiff12Formula - not implemented" );
+    SAL_WARN("sc", "FormulaParserImpl::importBiff12Formula - not implemented" );
     return ApiTokenSequence();
 }
 
commit e1351ed4c5f9152c80b32bbaa53e3eff56671331
Author: Markus Mohrhard <markus.mohrhard at collabora.co.uk>
Date:   Wed Dec 24 04:11:08 2014 +0100

    reimplement shared formula import for xlsb, fdo#86734
    
    Change-Id: Ic5d678a2b1197ce8d83b308b0a4387bf657052d5

diff --git a/sc/source/filter/inc/sheetdatabuffer.hxx b/sc/source/filter/inc/sheetdatabuffer.hxx
index c2e7550..1c89814 100644
--- a/sc/source/filter/inc/sheetdatabuffer.hxx
+++ b/sc/source/filter/inc/sheetdatabuffer.hxx
@@ -125,6 +125,10 @@ public:
     /** Inserts a ISO 8601 date cell into the sheet. */
     void                setDateCell( const CellModel& rModel, const OUString& rDateString );
 
+    void                createSharedFormula(
+            const com::sun::star::table::CellAddress& rRange,
+            const ApiTokenSequence& rTokens);
+
     /** Inserts the passed token array as array formula. */
     void                createArrayFormula(
                             const ::com::sun::star::table::CellRangeAddress& rRange,
@@ -149,17 +153,17 @@ public:
     /** Final processing after the sheet has been imported. */
     void                finalizeImport();
 
-private:
-    struct XfIdRowRange;
-
     /** Sets the passed formula token array into a cell. */
     void                setCellFormula(
                             const ::com::sun::star::table::CellAddress& rCellAddr,
                             const ApiTokenSequence& rTokens );
 
+private:
+    struct XfIdRowRange;
+
     /** Creates a formula token array representing the shared formula with the
         passed identifier. */
-    ApiTokenSequence    resolveSharedFormula( const BinAddress& rMapKey ) const;
+    ApiTokenSequence    resolveSharedFormula( const css::table::CellAddress& rMapKey ) const;
 
     /** Inserts the passed array formula into the sheet. */
     void                finalizeArrayFormula(
@@ -231,7 +235,7 @@ private:
     SharedFormulaMap    maSharedFormulas;       /// Maps shared formula base address to defined name token index.
     ::com::sun::star::table::CellAddress
                         maSharedFmlaAddr;       /// Address of a cell containing a pending shared formula.
-    BinAddress          maSharedBaseAddr;       /// Base address of the pending shared formula.
+    css::table::CellAddress maSharedBaseAddr;       /// Base address of the pending shared formula.
     XfIdRowRange        maXfIdRowRange;         /// Cached XF identifier for a range of rows.
     XfIdRangeListMap    maXfIdRangeLists;       /// Collected XF identifiers for cell rangelists.
     MergedRangeList     maMergedRanges;         /// Merged cell ranges.
diff --git a/sc/source/filter/inc/worksheethelper.hxx b/sc/source/filter/inc/worksheethelper.hxx
index 79ab964..a1bc389 100644
--- a/sc/source/filter/inc/worksheethelper.hxx
+++ b/sc/source/filter/inc/worksheethelper.hxx
@@ -59,7 +59,7 @@ class WorksheetSettings;
 
 typedef ::std::map< OUString, void* >  ExtLst;
 
-typedef ::std::map< BinAddress, sal_Int32 > SharedFormulaMap;
+typedef ::std::map< BinAddress, ApiTokenSequence > SharedFormulaMap;
 
 /** An enumeration for all types of sheets in a workbook. */
 enum WorksheetType
diff --git a/sc/source/filter/oox/sheetdatabuffer.cxx b/sc/source/filter/oox/sheetdatabuffer.cxx
index 45c9fa9..3adfc57 100644
--- a/sc/source/filter/oox/sheetdatabuffer.cxx
+++ b/sc/source/filter/oox/sheetdatabuffer.cxx
@@ -220,6 +220,14 @@ void SheetDataBuffer::setDateCell( const CellModel& rModel, const OUString& rDat
         setValueCell( rModel, fValue );
 }
 
+void SheetDataBuffer::createSharedFormula(const CellAddress& rAddr, const ApiTokenSequence& rTokens)
+{
+    BinAddress aAddr(rAddr);
+    maSharedFormulas[aAddr] = rTokens;
+    if( mbPendingSharedFmla )
+        setCellFormula( maSharedFmlaAddr, resolveSharedFormula( maSharedBaseAddr ) );
+}
+
 void SheetDataBuffer::setFormulaCell( const CellModel& rModel, const ApiTokenSequence& rTokens )
 {
     mbPendingSharedFmla = false;
@@ -249,11 +257,11 @@ void SheetDataBuffer::setFormulaCell( const CellModel& rModel, const ApiTokenSeq
                 reading the formula definition it will be retried to insert the
                 formula via retryPendingSharedFormulaCell(). */
             BinAddress aBaseAddr( aTokenInfo.First );
-            aTokens = resolveSharedFormula( aBaseAddr );
+            aTokens = resolveSharedFormula( aTokenInfo.First );
             if( !aTokens.hasElements() )
             {
                 maSharedFmlaAddr = rModel.maCellAddr;
-                maSharedBaseAddr = aBaseAddr;
+                maSharedBaseAddr = aTokenInfo.First;
                 mbPendingSharedFmla = true;
             }
         }
@@ -560,10 +568,11 @@ void SheetDataBuffer::setCellFormula( const CellAddress& rCellAddr, const ApiTok
     }
 }
 
-ApiTokenSequence SheetDataBuffer::resolveSharedFormula( const BinAddress& rMapKey ) const
+ApiTokenSequence SheetDataBuffer::resolveSharedFormula( const CellAddress& rAddr ) const
 {
-    sal_Int32 nTokenIndex = ContainerHelper::getMapElement( maSharedFormulas, rMapKey, -1 );
-    return (nTokenIndex >= 0) ? getFormulaParser().convertNameToFormula( nTokenIndex ) : ApiTokenSequence();
+    BinAddress aAddr(rAddr);
+    ApiTokenSequence aTokens = ContainerHelper::getMapElement( maSharedFormulas, aAddr, ApiTokenSequence() );
+    return aTokens;
 }
 
 void SheetDataBuffer::finalizeArrayFormula( const CellRangeAddress& rRange, const ApiTokenSequence& rTokens ) const
diff --git a/sc/source/filter/oox/sheetdatacontext.cxx b/sc/source/filter/oox/sheetdatacontext.cxx
index fad6d5d..e98abff 100644
--- a/sc/source/filter/oox/sheetdatacontext.cxx
+++ b/sc/source/filter/oox/sheetdatacontext.cxx
@@ -564,8 +564,13 @@ void SheetDataContext::importDataTable( SequenceInputStream& rStrm )
     }
 }
 
-void SheetDataContext::importSharedFmla( SequenceInputStream& /*rStrm*/ )
+void SheetDataContext::importSharedFmla( SequenceInputStream& rStrm )
 {
+    if( readFormulaRef( rStrm ) && maFmlaData.isValidSharedRef( maCellData.maCellAddr ) )
+    {
+        ApiTokenSequence aTokens = mxFormulaParser->importFormula( maCellData.maCellAddr, FORMULATYPE_SHAREDFORMULA, rStrm );
+        mrSheetData.createSharedFormula( maCellData.maCellAddr, aTokens );
+    }
 }
 
 } // namespace xls


More information about the Libreoffice-commits mailing list