summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorKohei Yoshida <libreoffice@kohei.us>2013-09-08 19:51:57 -0400
committerKohei Yoshida <libreoffice@kohei.us>2013-09-08 19:58:39 -0400
commit00adb9d393dd1f6dff6a6bd6e036d9e040fa37ee (patch)
tree3351a70677f17912c650d1d412ba443d42d19ad8 /sc
parentce29dbb48a5bc0b117528e0566888066b8dc6fb9 (diff)
Import matrix formulas from xlsx without using UNO API.
Change-Id: Ic13d08ad3a827ede0db73d8ba78b9cfa82c662e9
Diffstat (limited to 'sc')
-rw-r--r--sc/source/filter/inc/formulabuffer.hxx3
-rw-r--r--sc/source/filter/oox/formulabuffer.cxx59
2 files changed, 16 insertions, 46 deletions
diff --git a/sc/source/filter/inc/formulabuffer.hxx b/sc/source/filter/inc/formulabuffer.hxx
index 381a65ab87a2..e847c3cf852c 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 4f4042c18fbb..5de935e7d451 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);
}
}
}