diff options
author | RĂ¼diger Timm <rt@openoffice.org> | 2008-04-18 13:36:35 +0000 |
---|---|---|
committer | RĂ¼diger Timm <rt@openoffice.org> | 2008-04-18 13:36:35 +0000 |
commit | 1d079573981b5abec4f3ecfde5e46cd5a89904ca (patch) | |
tree | a0b5f879b1f92b168cdf7af317170e24d5a3569a /oox/source | |
parent | 2df072ed934475aaf020bb0805f13fe504958342 (diff) |
INTEGRATION: CWS xmlfilter04 (1.1.2); FILE ADDED
2008/04/18 13:05:08 rt 1.1.2.4: Change license header to LGPL v3.
2008/03/12 14:22:32 dr 1.1.2.3: more code finetuning
2008/03/05 11:05:12 dr 1.1.2.2: more source data import
2008/02/27 11:14:58 dr 1.1.2.1: first steps: chart API conversion
Diffstat (limited to 'oox/source')
-rw-r--r-- | oox/source/xls/excelchartconverter.cxx | 115 |
1 files changed, 115 insertions, 0 deletions
diff --git a/oox/source/xls/excelchartconverter.cxx b/oox/source/xls/excelchartconverter.cxx new file mode 100644 index 000000000000..82cd1afdd020 --- /dev/null +++ b/oox/source/xls/excelchartconverter.cxx @@ -0,0 +1,115 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: excelchartconverter.cxx,v $ + * + * $Revision: 1.2 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "oox/xls/excelchartconverter.hxx" +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/chart2/data/XDataProvider.hpp> +#include <com/sun/star/chart2/data/XDataReceiver.hpp> +#include "oox/xls/formulaparser.hxx" + +using ::rtl::OUString; +using ::com::sun::star::uno::Reference; +using ::com::sun::star::uno::Exception; +using ::com::sun::star::uno::UNO_QUERY_THROW; +using ::com::sun::star::lang::XMultiServiceFactory; +using ::com::sun::star::table::CellAddress; +using ::com::sun::star::chart2::XChartDocument; +using ::com::sun::star::chart2::data::XDataProvider; +using ::com::sun::star::chart2::data::XDataReceiver; +using ::com::sun::star::chart2::data::XDataSequence; +using ::oox::drawingml::chart::ChartConverter; + +namespace oox { +namespace xls { + +// ============================================================================ + +ExcelChartConverter::ExcelChartConverter( const WorkbookHelper& rHelper ) : + WorkbookHelper( rHelper ) +{ +} + +ExcelChartConverter::~ExcelChartConverter() +{ +} + +void ExcelChartConverter::createDataProvider( const Reference< XChartDocument >& rxChartDoc ) +{ + try + { + Reference< XDataReceiver > xDataRec( rxChartDoc, UNO_QUERY_THROW ); + Reference< XMultiServiceFactory > xFactory( getDocument(), UNO_QUERY_THROW ); + Reference< XDataProvider > xDataProv( xFactory->createInstance( + CREATE_OUSTRING( "com.sun.star.chart2.data.DataProvider" ) ), UNO_QUERY_THROW ); + xDataRec->attachDataProvider( xDataProv ); + } + catch( Exception& ) + { + } +} + +Reference< XDataSequence > ExcelChartConverter::createDataSequence( + const Reference< XDataProvider >& rxDataProvider, const OUString& rFormula ) +{ + OSL_ENSURE( rFormula.getLength() > 0, "ExcelChartConverter::createDataSequence - missing formula" ); + + Reference< XDataSequence > xDataSeq; + if( rxDataProvider.is() && (rFormula.getLength() > 0) ) + { + // parse the formula string, create a token sequence + FormulaParser& rParser = getFormulaParser(); + TokensFormulaContext aContext( true, true ); + aContext.setBaseAddress( CellAddress( getCurrentSheetIndex(), 0, 0 ) ); + rParser.importFormula( aContext, rFormula ); + + // create a range list from the token sequence + ApiCellRangeList aRanges; + rParser.extractCellRangeList( aRanges, aContext.getTokens() ); + + if( !aRanges.empty() ) try + { + // create the data sequence + OUString aRangeRep = rParser.generateApiRangeListString( aRanges, ';' ); + xDataSeq = rxDataProvider->createDataSequenceByRangeRepresentation( aRangeRep ); + } + catch( Exception& ) + { + OSL_ENSURE( false, "ExcelChartConverter::createDataSequence - cannot create data sequence" ); + } + } + return xDataSeq; +} + +// ============================================================================ + +} // namespace xls +} // namespace oox + |