From 00adb9d393dd1f6dff6a6bd6e036d9e040fa37ee Mon Sep 17 00:00:00 2001 From: Kohei Yoshida Date: Sun, 8 Sep 2013 19:51:57 -0400 Subject: Import matrix formulas from xlsx without using UNO API. Change-Id: Ic13d08ad3a827ede0db73d8ba78b9cfa82c662e9 --- sc/source/filter/inc/formulabuffer.hxx | 3 -- sc/source/filter/oox/formulabuffer.cxx | 59 +++++++++------------------------- 2 files changed, 16 insertions(+), 46 deletions(-) (limited to 'sc') 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 - 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 FormulaBuffer::getRange( const CellRangeAddress& rRange ) -{ - Reference 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::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); } } } -- cgit