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

Kohei Yoshida libreoffice at kohei.us
Sun Sep 8 16:54:37 PDT 2013


 sc/source/filter/inc/formulabuffer.hxx |   13 ++--
 sc/source/filter/oox/formulabuffer.cxx |   88 +++++++++++----------------------
 2 files changed, 37 insertions(+), 64 deletions(-)

New commits:
commit 00adb9d393dd1f6dff6a6bd6e036d9e040fa37ee
Author: Kohei Yoshida <libreoffice at kohei.us>
Date:   Sun Sep 8 19:51:57 2013 -0400

    Import matrix formulas from xlsx without using UNO API.
    
    Change-Id: Ic13d08ad3a827ede0db73d8ba78b9cfa82c662e9

diff --git a/sc/source/filter/inc/formulabuffer.hxx b/sc/source/filter/inc/formulabuffer.hxx
index 381a65a..e847c3cf8 100644
--- a/sc/source/filter/inc/formulabuffer.hxx
+++ b/sc/source/filter/inc/formulabuffer.hxx
@@ -94,9 +94,6 @@ class FormulaBuffer : public WorkbookHelper
     SheetToSharedIdToTokenIndex maTokenIndexes;
     FormulaValueMap maCellFormulaValues;
 
-    com::sun::star::uno::Reference<com::sun::star::table::XCellRange>
-        getRange( const com::sun::star::table::CellRangeAddress& rRange );
-
     void                applyArrayFormulas(  const std::vector< TokenRangeAddressItem >& rVector );
     void                applyCellFormula( ScDocument& rDoc, const ApiTokenSequence& rTokens, const ::com::sun::star::table::CellAddress& rAddress );
     void                applyCellFormulas(  const std::vector< TokenAddressItem >& rVector );
diff --git a/sc/source/filter/oox/formulabuffer.cxx b/sc/source/filter/oox/formulabuffer.cxx
index 4f4042c..5de935e 100644
--- a/sc/source/filter/oox/formulabuffer.cxx
+++ b/sc/source/filter/oox/formulabuffer.cxx
@@ -47,20 +47,6 @@ FormulaBuffer::FormulaBuffer( const WorkbookHelper& rHelper ) : WorkbookHelper(
 {
 }
 
-Reference<XCellRange> FormulaBuffer::getRange( const CellRangeAddress& rRange )
-{
-    Reference<XCellRange> xRange;
-    try
-    {
-        xRange = mxCurrSheet->getCellRangeByPosition(
-            rRange.StartColumn, rRange.StartRow, rRange.EndColumn, rRange.EndRow);
-    }
-    catch( Exception& )
-    {
-    }
-    return xRange;
-}
-
 void FormulaBuffer::finalizeImport()
 {
     ISegmentProgressBarRef xFormulaBar = getProgressBar().createSegment( getProgressBar().getFreeLength() );
@@ -239,40 +225,27 @@ void FormulaBuffer::applySharedFormulas( sal_Int32 nTab )
     }
 }
 
-// bound to need this somewhere else, if so probably need to move it to
-// worksheethelper or somewhere else more suitable
-void StartCellListening( sal_Int16 nSheet, sal_Int32 nRow, sal_Int32 nCol, ScDocument& rDoc )
-{
-    ScAddress aCellPos;
-    CellAddress aAddress;
-    aAddress.Sheet = nSheet;
-    aAddress.Row = nRow;
-    aAddress.Column = nCol;
-    ScUnoConversion::FillScAddress( aCellPos, aAddress );
-    ScFormulaCell* pFCell = rDoc.GetFormulaCell( aCellPos );
-    if ( pFCell )
-        pFCell->StartListeningTo( &rDoc );
-}
-
 void FormulaBuffer::applyArrayFormulas( const std::vector< TokenRangeAddressItem >& rVector )
 {
     ScDocument& rDoc = getScDocument();
-    for ( std::vector< TokenRangeAddressItem >::const_iterator it = rVector.begin(), it_end = rVector.end(); it != it_end; ++it )
+    std::vector<TokenRangeAddressItem>::const_iterator it = rVector.begin(), itEnd = rVector.end();
+    for (; it != itEnd; ++it)
     {
-        Reference< XArrayFormulaTokens > xTokens( getRange( it->maCellRangeAddress ), UNO_QUERY );
-        OSL_ENSURE( xTokens.is(), "SheetDataBuffer::finalizeArrayFormula - missing formula token interface" );
-        ApiTokenSequence aTokens = getFormulaParser().importFormula( it->maTokenAndAddress.maCellAddress, it->maTokenAndAddress.maTokenStr );
-        if( xTokens.is() )
+        ScAddress aPos;
+        ScUnoConversion::FillScAddress(aPos, it->maTokenAndAddress.maCellAddress);
+        ScRange aRange;
+        ScUnoConversion::FillScRange(aRange, it->maCellRangeAddress);
+
+        ScCompiler aComp(&rDoc, aPos);
+        aComp.SetGrammar(formula::FormulaGrammar::GRAM_ENGLISH_XL_OOX);
+        ScTokenArray* pArray = aComp.CompileString(it->maTokenAndAddress.maTokenStr);
+        if (pArray)
         {
-            xTokens->setArrayTokens( aTokens );
-            // set dependencies, add listeners on the cells in array
-            for ( sal_Int32 nCol = it->maCellRangeAddress.StartColumn; nCol <=  it->maCellRangeAddress.EndColumn; ++nCol )
-            {
-                for ( sal_Int32 nRow = it->maCellRangeAddress.StartRow; nRow <=  it->maCellRangeAddress.EndRow; ++nRow )
-                {
-                    StartCellListening( it->maCellRangeAddress.Sheet, nRow, nCol, rDoc );
-                }
-            }
+            ScMarkData aMark;
+            aMark.SelectOneTable(aPos.Tab());
+            rDoc.InsertMatrixFormula(
+                aRange.aStart.Col(), aRange.aStart.Row(), aRange.aEnd.Col(), aRange.aEnd.Row(),
+                aMark, it->maTokenAndAddress.maTokenStr, pArray, formula::FormulaGrammar::GRAM_ENGLISH_XL_OOX);
         }
     }
 }
commit ce29dbb48a5bc0b117528e0566888066b8dc6fb9
Author: Kohei Yoshida <libreoffice at kohei.us>
Date:   Sun Sep 8 19:00:12 2013 -0400

    Make data member names consistent.
    
    Change-Id: Icd949d84bb7a575b0e4adbe5c1c6f4d30e9b5213

diff --git a/sc/source/filter/inc/formulabuffer.hxx b/sc/source/filter/inc/formulabuffer.hxx
index c5d8f96..381a65a 100644
--- a/sc/source/filter/inc/formulabuffer.hxx
+++ b/sc/source/filter/inc/formulabuffer.hxx
@@ -86,14 +86,16 @@ class FormulaBuffer : public WorkbookHelper
     typedef ::std::pair< ::com::sun::star::table::CellAddress, double > ValueAddressPair;
     typedef ::std::map< sal_Int32, std::vector< ValueAddressPair > > FormulaValueMap;
 
-    ::com::sun::star::uno::Reference< com::sun::star::table::XCellRange > getRange( const ::com::sun::star::table::CellRangeAddress& rRange);
     com::sun::star::uno::Reference< com::sun::star::sheet::XSpreadsheet > mxCurrSheet;
-    FormulaDataMap      cellFormulas;
-    ArrayFormulaDataMap cellArrayFormulas;
-    SheetToFormulaEntryMap sharedFormulas;
-    SheetToSharedFormulaid sharedFormulaIds;
-    SheetToSharedIdToTokenIndex tokenIndexes;
-    FormulaValueMap        cellFormulaValues;
+    FormulaDataMap maCellFormulas;
+    ArrayFormulaDataMap maCellArrayFormulas;
+    SheetToFormulaEntryMap maSharedFormulas;
+    SheetToSharedFormulaid maSharedFormulaIds;
+    SheetToSharedIdToTokenIndex maTokenIndexes;
+    FormulaValueMap maCellFormulaValues;
+
+    com::sun::star::uno::Reference<com::sun::star::table::XCellRange>
+        getRange( const com::sun::star::table::CellRangeAddress& rRange );
 
     void                applyArrayFormulas(  const std::vector< TokenRangeAddressItem >& rVector );
     void                applyCellFormula( ScDocument& rDoc, const ApiTokenSequence& rTokens, const ::com::sun::star::table::CellAddress& rAddress );
diff --git a/sc/source/filter/oox/formulabuffer.cxx b/sc/source/filter/oox/formulabuffer.cxx
index dce36d7..4f4042c 100644
--- a/sc/source/filter/oox/formulabuffer.cxx
+++ b/sc/source/filter/oox/formulabuffer.cxx
@@ -47,12 +47,13 @@ FormulaBuffer::FormulaBuffer( const WorkbookHelper& rHelper ) : WorkbookHelper(
 {
 }
 
-Reference< XCellRange > FormulaBuffer::getRange( const CellRangeAddress& rRange)
+Reference<XCellRange> FormulaBuffer::getRange( const CellRangeAddress& rRange )
 {
-    Reference< XCellRange > xRange;
+    Reference<XCellRange> xRange;
     try
     {
-        xRange = mxCurrSheet->getCellRangeByPosition( rRange.StartColumn, rRange.StartRow, rRange.EndColumn, rRange.EndRow );
+        xRange = mxCurrSheet->getCellRangeByPosition(
+            rRange.StartColumn, rRange.StartRow, rRange.EndColumn, rRange.EndRow);
     }
     catch( Exception& )
     {
@@ -75,20 +76,20 @@ void FormulaBuffer::finalizeImport()
 
         applySharedFormulas(nTab);
 
-        FormulaDataMap::iterator cellIt = cellFormulas.find( nTab );
-        if ( cellIt != cellFormulas.end() )
+        FormulaDataMap::iterator cellIt = maCellFormulas.find( nTab );
+        if ( cellIt != maCellFormulas.end() )
         {
             applyCellFormulas( cellIt->second );
         }
 
-        ArrayFormulaDataMap::iterator itArray = cellArrayFormulas.find( nTab );
-        if ( itArray != cellArrayFormulas.end() )
+        ArrayFormulaDataMap::iterator itArray = maCellArrayFormulas.find( nTab );
+        if ( itArray != maCellArrayFormulas.end() )
         {
             applyArrayFormulas( itArray->second );
         }
 
-        FormulaValueMap::iterator itValues = cellFormulaValues.find( nTab );
-        if ( itValues != cellFormulaValues.end() )
+        FormulaValueMap::iterator itValues = maCellFormulaValues.find( nTab );
+        if ( itValues != maCellFormulaValues.end() )
         {
             std::vector< ValueAddressPair > & rVector = itValues->second;
             applyCellFormulaValues( rVector );
@@ -140,13 +141,13 @@ void FormulaBuffer::applyCellFormulaValues( const std::vector< ValueAddressPair
 
 void FormulaBuffer::applySharedFormulas( sal_Int32 nTab )
 {
-    SheetToFormulaEntryMap::const_iterator itShared = sharedFormulas.find(nTab);
-    if (itShared == sharedFormulas.end())
+    SheetToFormulaEntryMap::const_iterator itShared = maSharedFormulas.find(nTab);
+    if (itShared == maSharedFormulas.end())
         // There is no shared formulas for this sheet.
         return;
 
-    SheetToSharedFormulaid::const_iterator itCells = sharedFormulaIds.find(nTab);
-    if (itCells == sharedFormulaIds.end())
+    SheetToSharedFormulaid::const_iterator itCells = maSharedFormulaIds.find(nTab);
+    if (itCells == maSharedFormulaIds.end())
         // There is no formula cells that use shared formulas for this sheet.
         return;
 
@@ -280,20 +281,20 @@ void FormulaBuffer::createSharedFormulaMapEntry(
     const table::CellAddress& rAddress, const table::CellRangeAddress& rRange,
     sal_Int32 nSharedId, const OUString& rTokens )
 {
-    std::vector<SharedFormulaEntry>& rSharedFormulas = sharedFormulas[ rAddress.Sheet ];
+    std::vector<SharedFormulaEntry>& rSharedFormulas = maSharedFormulas[ rAddress.Sheet ];
     SharedFormulaEntry aEntry(rAddress, rRange, rTokens, nSharedId);
     rSharedFormulas.push_back( aEntry );
 }
 
 void FormulaBuffer::setCellFormula( const ::com::sun::star::table::CellAddress& rAddress, const OUString& rTokenStr )
 {
-    cellFormulas[ rAddress.Sheet ].push_back( TokenAddressItem( rTokenStr, rAddress ) );
+    maCellFormulas[ rAddress.Sheet ].push_back( TokenAddressItem( rTokenStr, rAddress ) );
 }
 
 void FormulaBuffer::setCellFormula(
     const table::CellAddress& rAddress, sal_Int32 nSharedId, const OUString& rCellValue, sal_Int32 nValueType )
 {
-    sharedFormulaIds[rAddress.Sheet].push_back(
+    maSharedFormulaIds[rAddress.Sheet].push_back(
         SharedFormulaDesc(rAddress, nSharedId, rCellValue, nValueType));
 }
 
@@ -301,12 +302,12 @@ void FormulaBuffer::setCellArrayFormula( const ::com::sun::star::table::CellRang
 {
 
     TokenAddressItem tokenPair( rTokenStr, rTokenAddress );
-    cellArrayFormulas[ rRangeAddress.Sheet ].push_back( TokenRangeAddressItem( tokenPair, rRangeAddress ) );
+    maCellArrayFormulas[ rRangeAddress.Sheet ].push_back( TokenRangeAddressItem( tokenPair, rRangeAddress ) );
 }
 
 void FormulaBuffer::setCellFormulaValue( const ::com::sun::star::table::CellAddress& rAddress, double fValue )
 {
-    cellFormulaValues[ rAddress.Sheet ].push_back( ValueAddressPair( rAddress, fValue ) );
+    maCellFormulaValues[ rAddress.Sheet ].push_back( ValueAddressPair( rAddress, fValue ) );
 }
 
 }}


More information about the Libreoffice-commits mailing list