diff options
author | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2011-10-27 23:52:35 +0200 |
---|---|---|
committer | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2011-10-27 23:54:24 +0200 |
commit | 35896a678b004a84bafc54fd3e08dfc97a0d4886 (patch) | |
tree | 4ee34cf2d87290cd70174d51835a9a75b991786c /oox | |
parent | 3852a6f54880af8ed9161227baa555580c7d4517 (diff) |
add xlsx local range name import
Diffstat (limited to 'oox')
-rw-r--r-- | oox/inc/oox/xls/workbookhelper.hxx | 8 | ||||
-rw-r--r-- | oox/source/xls/defnamesbuffer.cxx | 11 | ||||
-rw-r--r-- | oox/source/xls/workbookhelper.cxx | 37 |
3 files changed, 49 insertions, 7 deletions
diff --git a/oox/inc/oox/xls/workbookhelper.hxx b/oox/inc/oox/xls/workbookhelper.hxx index bb9a3d29e398..e0310b8143e7 100644 --- a/oox/inc/oox/xls/workbookhelper.hxx +++ b/oox/inc/oox/xls/workbookhelper.hxx @@ -192,6 +192,14 @@ public: ::rtl::OUString& orName, sal_Int32 nNameFlags = 0 ) const; + /** Creates and returns a defined name on-the-fly in the sheet. + The name will not be buffered in the global defined names buffer. + @param orName (in/out-parameter) Returns the resulting used name. */ + ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XNamedRange > + createLocalNamedRangeObject( + ::rtl::OUString& orName, + sal_Int32 nNameFlags = 0, sal_Int32 nTab = -1 ) const; + /** Creates and returns a database range on-the-fly in the Calc document. The range will not be buffered in the global table buffer. @param orName (in/out-parameter) Returns the resulting used name. */ diff --git a/oox/source/xls/defnamesbuffer.cxx b/oox/source/xls/defnamesbuffer.cxx index fce1bfb589ef..e2319ca79a9d 100644 --- a/oox/source/xls/defnamesbuffer.cxx +++ b/oox/source/xls/defnamesbuffer.cxx @@ -489,12 +489,6 @@ void DefinedName::createNameObject() maCalcName = isBuiltinName() ? lclGetPrefixedName( mcBuiltinId ) : maModel.maName; // #163146# do not rename sheet-local names by default, this breaks VBA scripts -#if 0 - // append sheet index for local names in multi-sheet documents - if( isWorkbookFile() && !isGlobalName() ) - maCalcName = OUStringBuffer( maCalcName ).append( sal_Unicode( '_' ) ). - append( static_cast< sal_Int32 >( mnCalcSheet + 1 ) ).makeStringAndClear(); -#endif // special flags for this name sal_Int32 nNameFlags = 0; @@ -507,7 +501,10 @@ void DefinedName::createNameObject() } // create the name and insert it into the document, maCalcName will be changed to the resulting name - mxNamedRange = createNamedRangeObject( maCalcName, nNameFlags ); + if (maModel.mnSheet >= 0) + mxNamedRange = createLocalNamedRangeObject( maCalcName, nNameFlags, maModel.mnSheet ); + else + mxNamedRange = createNamedRangeObject( maCalcName, nNameFlags ); // index of this defined name used in formula token arrays PropertySet aPropSet( mxNamedRange ); aPropSet.getProperty( mnTokenIndex, PROP_TokenIndex ); diff --git a/oox/source/xls/workbookhelper.cxx b/oox/source/xls/workbookhelper.cxx index 3c45aeb50437..3cc56cdce7be 100644 --- a/oox/source/xls/workbookhelper.cxx +++ b/oox/source/xls/workbookhelper.cxx @@ -41,6 +41,7 @@ #include <com/sun/star/style/XStyle.hpp> #include <com/sun/star/style/XStyleFamiliesSupplier.hpp> #include <com/sun/star/table/CellAddress.hpp> +#include <com/sun/star/container/XNamed.hpp> #include <osl/thread.h> #include "oox/drawingml/theme.hxx" #include "oox/helper/progressbar.hxx" @@ -68,6 +69,8 @@ #include "oox/xls/workbooksettings.hxx" #include "oox/xls/worksheetbuffer.hxx" +#include <iostream> + namespace oox { namespace xls { @@ -140,6 +143,8 @@ public: Reference< XStyle > getStyleObject( const OUString& rStyleName, bool bPageStyle ) const; /** Creates and returns a defined name on-the-fly in the Calc document. */ Reference< XNamedRange > createNamedRangeObject( OUString& orName, sal_Int32 nNameFlags ) const; + /** Creates and returns a defined name on the-fly in the correct Calc sheet. */ + Reference< XNamedRange > createLocalNamedRangeObject( OUString& orName, sal_Int32 nNameFlags, sal_Int32 nTab ) const; /** Creates and returns a database range on-the-fly in the Calc document. */ Reference< XDatabaseRange > createDatabaseRangeObject( OUString& orName, const CellRangeAddress& rRangeAddr ) const; /** Creates and returns an unnamed database range on-the-fly in the Calc document. */ @@ -378,6 +383,33 @@ Reference< XNamedRange > WorkbookGlobals::createNamedRangeObject( OUString& orNa return xNamedRange; } +Reference< XNamedRange > WorkbookGlobals::createLocalNamedRangeObject( OUString& orName, sal_Int32 nNameFlags, sal_Int32 nTab ) const +{ + // create the name and insert it into the Calc document + Reference< XNamedRange > xNamedRange; + if( orName.getLength() > 0 ) try + { + // find an unused name + Reference< XIndexAccess > xSheets(mxDoc->getSheets(), UNO_QUERY_THROW); + Reference< XSpreadsheet > xSheet (xSheets->getByIndex(nTab), UNO_QUERY_THROW); + Reference< com::sun::star::container::XNamed > xNamed(xSheet, UNO_QUERY_THROW); + rtl::OUString aName = xNamed->getName(); + std::cout << "sheetName: " << rtl::OUStringToOString( aName, RTL_TEXTENCODING_UTF8).getStr() << std::endl; + PropertySet aSheetProps( xSheet ); + Reference< XNamedRanges > xNamedRanges( aSheetProps.getAnyProperty( PROP_NamedRanges ), UNO_QUERY_THROW ); + Reference< XNameAccess > xNameAccess( xNamedRanges, UNO_QUERY_THROW ); + orName = ContainerHelper::getUnusedName( xNameAccess, orName, '_' ); + // create the named range + xNamedRanges->addNewByName( orName, OUString(), CellAddress( 0, 0, 0 ), nNameFlags ); + xNamedRange.set( xNamedRanges->getByName( orName ), UNO_QUERY ); + } + catch( Exception& ) + { + } + OSL_ENSURE( xNamedRange.is(), "WorkbookGlobals::createLocalNamedRangeObject - cannot create defined name" ); + return xNamedRange; +} + Reference< XDatabaseRange > WorkbookGlobals::createDatabaseRangeObject( OUString& orName, const CellRangeAddress& rRangeAddr ) const { // validate cell range @@ -773,6 +805,11 @@ Reference< XNamedRange > WorkbookHelper::createNamedRangeObject( OUString& orNam return mrBookGlob.createNamedRangeObject( orName, nNameFlags ); } +Reference< XNamedRange > WorkbookHelper::createLocalNamedRangeObject( OUString& orName, sal_Int32 nNameFlags, sal_Int32 nTab ) const +{ + return mrBookGlob.createLocalNamedRangeObject( orName, nNameFlags, nTab ); +} + Reference< XDatabaseRange > WorkbookHelper::createDatabaseRangeObject( OUString& orName, const CellRangeAddress& rRangeAddr ) const { return mrBookGlob.createDatabaseRangeObject( orName, rRangeAddr ); |