[Libreoffice-commits] core.git: Branch 'libreoffice-4-3' - sc/source

Markus Mohrhard markus.mohrhard at collabora.co.uk
Thu Jan 8 05:44:47 PST 2015


 sc/source/filter/inc/sheetdatabuffer.hxx  |   14 +++++++++-----
 sc/source/filter/inc/worksheethelper.hxx  |    2 +-
 sc/source/filter/oox/sheetdatabuffer.cxx  |   19 ++++++++++++++-----
 sc/source/filter/oox/sheetdatacontext.cxx |    7 ++++++-
 4 files changed, 30 insertions(+), 12 deletions(-)

New commits:
commit c931268890fdd0e9aec1bdab939495f299e11011
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
    Reviewed-on: https://gerrit.libreoffice.org/13634
    Reviewed-by: Eike Rathke <erack at redhat.com>
    Tested-by: Eike Rathke <erack at redhat.com>

diff --git a/sc/source/filter/inc/sheetdatabuffer.hxx b/sc/source/filter/inc/sheetdatabuffer.hxx
index 1a3ae9a..9d05f64 100644
--- a/sc/source/filter/inc/sheetdatabuffer.hxx
+++ b/sc/source/filter/inc/sheetdatabuffer.hxx
@@ -126,6 +126,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,
@@ -151,17 +155,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(
@@ -234,7 +238,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 26c6999..3dd60c0 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 68b39db..c77f43f 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;
             }
         }
@@ -556,10 +564,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 f6ca6a4..4752995 100644
--- a/sc/source/filter/oox/sheetdatacontext.cxx
+++ b/sc/source/filter/oox/sheetdatacontext.cxx
@@ -558,8 +558,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 = mrFormulaParser.importFormula( maCellData.maCellAddr, FORMULATYPE_SHAREDFORMULA, rStrm );
+        mrSheetData.createSharedFormula( maCellData.maCellAddr, aTokens );
+    }
 }
 
 } // namespace xls


More information about the Libreoffice-commits mailing list