diff options
author | Kohei Yoshida <kohei.yoshida@suse.com> | 2012-01-04 15:45:09 -0500 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@suse.com> | 2012-01-04 21:19:39 -0500 |
commit | 578292d707077c18079de050c928afaae268a25d (patch) | |
tree | 6924d920095d58773ca59e87896a472a47077281 /oox | |
parent | 39042cce6685fc9db5ee20957bcc7ac584c28554 (diff) |
Register chart data ranges via tokens rather than string.
Doing it this way avoids having to re-generate the data ranges in
Calc A1 before passing it to the chart backend in Calc. We need this
in order to remove the silly restriction that forces us to always pass
data range strings in Calc A1 format, which is error-prone.
This is also necessary in order to fix the bug that prevents editing
data ranges of an existing chart when the formula syntax is something
other than Calc A1.
Diffstat (limited to 'oox')
-rw-r--r-- | oox/source/xls/excelchartconverter.cxx | 67 |
1 files changed, 40 insertions, 27 deletions
diff --git a/oox/source/xls/excelchartconverter.cxx b/oox/source/xls/excelchartconverter.cxx index da938eafd1fc..2fb699dd46d3 100644 --- a/oox/source/xls/excelchartconverter.cxx +++ b/oox/source/xls/excelchartconverter.cxx @@ -31,6 +31,8 @@ #include <com/sun/star/lang/XMultiServiceFactory.hpp> #include <com/sun/star/chart2/data/XDataProvider.hpp> #include <com/sun/star/chart2/data/XDataReceiver.hpp> +#include <com/sun/star/chart2/data/XSheetDataProvider.hpp> + #include "oox/core/filterbase.hxx" #include "oox/drawingml/chart/datasourcemodel.hxx" #include "oox/helper/containerhelper.hxx" @@ -79,42 +81,53 @@ Reference< XDataSequence > ExcelChartConverter::createDataSequence( const Reference< XDataProvider >& rxDataProvider, const DataSequenceModel& rDataSeq ) { Reference< XDataSequence > xDataSeq; - if( rxDataProvider.is() ) + if (!rxDataProvider.is()) + return xDataSeq; + + Reference<XSheetDataProvider> xSheetProvider(rxDataProvider, UNO_QUERY); + if (!xSheetProvider.is()) + return xDataSeq; + + if (!rDataSeq.maFormula.isEmpty()) { - OUString aRangeRep; - if( !rDataSeq.maFormula.isEmpty() ) - { - // parse the formula string, create a token sequence - FormulaParser& rParser = getFormulaParser(); - CellAddress aBaseAddr( getCurrentSheetIndex(), 0, 0 ); - ApiTokenSequence aTokens = rParser.importFormula( aBaseAddr, rDataSeq.maFormula ); - - // create a range list from the token sequence - ApiCellRangeList aRanges; - rParser.extractCellRangeList( aRanges, aTokens, false ); - aRangeRep = rParser.generateApiRangeListString( aRanges ); - } - else if( !rDataSeq.maData.empty() ) - { - // create a single-row array from constant source data - Matrix< Any > aMatrix( rDataSeq.maData.size(), 1 ); - Matrix< Any >::iterator aMIt = aMatrix.begin(); - // TODO: how to handle missing values in the map? - for( DataSequenceModel::AnyMap::const_iterator aDIt = rDataSeq.maData.begin(), aDEnd = rDataSeq.maData.end(); aDIt != aDEnd; ++aDIt, ++aMIt ) - *aMIt = aDIt->second; - aRangeRep = FormulaProcessorBase::generateApiArray( aMatrix ); - } + // parse the formula string, create a token sequence + FormulaParser& rParser = getFormulaParser(); + CellAddress aBaseAddr( getCurrentSheetIndex(), 0, 0 ); + ApiTokenSequence aTokens = rParser.importFormula( aBaseAddr, rDataSeq.maFormula ); - if( !aRangeRep.isEmpty() ) try + try { // create the data sequence - xDataSeq = rxDataProvider->createDataSequenceByRangeRepresentation( aRangeRep ); + xDataSeq = xSheetProvider->createDataSequenceByFormulaTokens(aTokens); } - catch( Exception& ) + catch (Exception&) { OSL_FAIL( "ExcelChartConverter::createDataSequence - cannot create data sequence" ); } } + else if (!rDataSeq.maData.empty()) + { + // create a single-row array from constant source data + Matrix< Any > aMatrix( rDataSeq.maData.size(), 1 ); + Matrix< Any >::iterator aMIt = aMatrix.begin(); + // TODO: how to handle missing values in the map? + for( DataSequenceModel::AnyMap::const_iterator aDIt = rDataSeq.maData.begin(), aDEnd = rDataSeq.maData.end(); aDIt != aDEnd; ++aDIt, ++aMIt ) + *aMIt = aDIt->second; + OUString aRangeRep = FormulaProcessorBase::generateApiArray( aMatrix ); + + if (!aRangeRep.isEmpty()) + { + try + { + // create the data sequence + xDataSeq = rxDataProvider->createDataSequenceByRangeRepresentation( aRangeRep ); + } + catch (Exception&) + { + OSL_FAIL( "ExcelChartConverter::createDataSequence - cannot create data sequence" ); + } + } + } return xDataSeq; } |