summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoel Power <noel.power@novell.com>2012-03-28 22:47:22 +0100
committerNoel Power <noel.power@novell.com>2012-03-28 22:56:28 +0100
commit3043cc87ad5570eaea404f220e42547b5efa7713 (patch)
treece76990339dca1e7c896eb2dcea5bd512de20751
parentbb070c05b6e2d09b15fed673507a523c11eb2a19 (diff)
some performance improvements
a) directly access core for creating named ranges ( the import code still uses uno for accessing the named ranges ) b) combine ranges with equal formats so that format can be applied to a multirange ( to avoid multiple uno calls )
-rw-r--r--sc/inc/tokenuno.hxx2
-rw-r--r--sc/source/filter/inc/defnamesbuffer.hxx4
-rw-r--r--sc/source/filter/inc/sheetdatabuffer.hxx1
-rw-r--r--sc/source/filter/inc/stylesbuffer.hxx6
-rw-r--r--sc/source/filter/inc/workbookhelper.hxx9
-rw-r--r--sc/source/filter/oox/defnamesbuffer.cxx28
-rw-r--r--sc/source/filter/oox/sheetdatabuffer.cxx59
-rw-r--r--sc/source/filter/oox/stylesbuffer.cxx35
-rw-r--r--sc/source/filter/oox/workbookhelper.cxx79
9 files changed, 183 insertions, 40 deletions
diff --git a/sc/inc/tokenuno.hxx b/sc/inc/tokenuno.hxx
index 8f68d0762db4..36486c404dc1 100644
--- a/sc/inc/tokenuno.hxx
+++ b/sc/inc/tokenuno.hxx
@@ -49,7 +49,7 @@ class ScDocShell;
class ScTokenConversion
{
public:
- static bool ConvertToTokenArray(
+ static SC_DLLPUBLIC bool ConvertToTokenArray(
ScDocument& rDoc,
ScTokenArray& rTokenArray,
const com::sun::star::uno::Sequence< com::sun::star::sheet::FormulaToken >& rSequence );
diff --git a/sc/source/filter/inc/defnamesbuffer.hxx b/sc/source/filter/inc/defnamesbuffer.hxx
index 0d28b6ab747e..5ef1a403fcf3 100644
--- a/sc/source/filter/inc/defnamesbuffer.hxx
+++ b/sc/source/filter/inc/defnamesbuffer.hxx
@@ -128,10 +128,10 @@ public:
void importDefinedName( BiffInputStream& rStrm, sal_Int16 nCalcSheet );
/** Creates a defined name in the Calc document. */
- void createNameObject();
+ void createNameObject( sal_Int32 nIndex );
/** Converts the formula string or BIFF token array for this defined name. */
void convertFormula();
-
+ ApiTokenSequence getTokens();
/** Returns true, if this defined name is global in the document. */
inline bool isGlobalName() const { return mnCalcSheet < 0; }
/** Returns true, if this defined name is a special builtin name. */
diff --git a/sc/source/filter/inc/sheetdatabuffer.hxx b/sc/source/filter/inc/sheetdatabuffer.hxx
index 3e83420301c7..743c6c008c01 100644
--- a/sc/source/filter/inc/sheetdatabuffer.hxx
+++ b/sc/source/filter/inc/sheetdatabuffer.hxx
@@ -323,6 +323,7 @@ private:
MergedRangeList maMergedRanges; /// Merged cell ranges.
MergedRangeList maCenterFillRanges; /// Merged cell ranges from 'center across' or 'fill' alignment.
bool mbPendingSharedFmla; /// True = maSharedFmlaAddr and maSharedBaseAddr are valid.
+ std::map< sal_Int32, std::vector< ValueRange > > maXfIdRowRangeList; /// Cached XF identifiers for a ranges of rows, we try and process rowranges with the same XF id together
};
// ============================================================================
diff --git a/sc/source/filter/inc/stylesbuffer.hxx b/sc/source/filter/inc/stylesbuffer.hxx
index 59895e5c25e4..af5d6ff6e274 100644
--- a/sc/source/filter/inc/stylesbuffer.hxx
+++ b/sc/source/filter/inc/stylesbuffer.hxx
@@ -744,6 +744,8 @@ struct XfModel
explicit XfModel();
};
+bool operator==( const XfModel& rXfModel1, const XfModel& rXfModel2 );
+
// ============================================================================
/** Represents a cell format or a cell style (called XF, extended format).
@@ -755,6 +757,7 @@ struct XfModel
*/
class Xf : public WorkbookHelper
{
+ friend bool operator==( const Xf& rXf1, const Xf& rXf2 );
public:
explicit Xf( const WorkbookHelper& rHelper );
@@ -796,7 +799,6 @@ public:
static void writeBiff2CellFormatToPropertySet(
const WorkbookHelper& rHelper, PropertySet& rPropSet,
sal_uInt8 nFlags1, sal_uInt8 nFlags2, sal_uInt8 nFlags3 );
-
private:
/** Sets 'attribute used' flags from the passed BIFF bit field. */
void setBiffUsedFlags( sal_uInt8 nUsedFlags );
@@ -808,6 +810,8 @@ private:
sal_Int32 meRotationRef; /// Rotation reference dependent on border.
};
+bool operator==( const Xf& rXf1, const Xf& rXf2 );
+
typedef ::boost::shared_ptr< Xf > XfRef;
// ============================================================================
diff --git a/sc/source/filter/inc/workbookhelper.hxx b/sc/source/filter/inc/workbookhelper.hxx
index 89b180e2a47e..1bdd96db0fce 100644
--- a/sc/source/filter/inc/workbookhelper.hxx
+++ b/sc/source/filter/inc/workbookhelper.hxx
@@ -42,6 +42,7 @@ namespace com { namespace sun { namespace star {
namespace sheet { class XNamedRange; }
namespace sheet { class XSpreadsheet; }
namespace sheet { class XSpreadsheetDocument; }
+ namespace sheet { struct FormulaToken; }
namespace style { class XStyle; }
namespace table { struct CellAddress; }
namespace table { struct CellRangeAddress; }
@@ -66,6 +67,8 @@ namespace oox { namespace drawingml {
class Theme;
} }
+class ScDocument;
+
namespace oox {
namespace xls {
@@ -154,7 +157,7 @@ public:
void finalizeWorkbookImport();
// document model ---------------------------------------------------------
-
+ ScDocument& getScDocument() const;
/** Returns a reference to the source/target spreadsheet document model. */
::com::sun::star::uno::Reference< ::com::sun::star::sheet::XSpreadsheetDocument >
getDocument() const;
@@ -184,6 +187,8 @@ public:
::com::sun::star::uno::Reference< ::com::sun::star::sheet::XNamedRange >
createNamedRangeObject(
::rtl::OUString& orName,
+ const ::com::sun::star::uno::Sequence< ::com::sun::star::sheet::FormulaToken>& rTokens,
+ sal_Int32 nIndex,
sal_Int32 nNameFlags = 0 ) const;
/** Creates and returns a defined name on-the-fly in the sheet.
@@ -192,6 +197,8 @@ public:
::com::sun::star::uno::Reference< ::com::sun::star::sheet::XNamedRange >
createLocalNamedRangeObject(
::rtl::OUString& orName,
+ const ::com::sun::star::uno::Sequence< ::com::sun::star::sheet::FormulaToken>& rTokens,
+ sal_Int32 nIndex,
sal_Int32 nNameFlags = 0, sal_Int32 nTab = -1 ) const;
/** Creates and returns a database range on-the-fly in the Calc document.
diff --git a/sc/source/filter/oox/defnamesbuffer.cxx b/sc/source/filter/oox/defnamesbuffer.cxx
index ab0ed199a8f8..e823e73aba20 100644
--- a/sc/source/filter/oox/defnamesbuffer.cxx
+++ b/sc/source/filter/oox/defnamesbuffer.cxx
@@ -474,7 +474,7 @@ void DefinedName::importDefinedName( BiffInputStream& rStrm, sal_Int16 nCalcShee
}
}
-void DefinedName::createNameObject()
+void DefinedName::createNameObject( sal_Int32 nIndex )
{
// do not create names for (macro) functions or VBA procedures
// #163146# do not ignore hidden names (may be regular names created by VBA scripts)
@@ -502,20 +502,15 @@ void DefinedName::createNameObject()
// create the name and insert it into the document, maCalcName will be changed to the resulting name
if (maModel.mnSheet >= 0)
- mxNamedRange = createLocalNamedRangeObject( maCalcName, nNameFlags, maModel.mnSheet );
+ mxNamedRange = createLocalNamedRangeObject( maCalcName, getTokens(), nIndex, 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 );
+ mxNamedRange = createNamedRangeObject( maCalcName, getTokens(), nIndex, nNameFlags );
+ mnTokenIndex = nIndex;
}
-void DefinedName::convertFormula()
+ApiTokenSequence
+DefinedName::getTokens()
{
- Reference< XFormulaTokens > xTokens( mxNamedRange, UNO_QUERY );
- if( !xTokens.is() )
- return;
-
// convert and set formula of the defined name
ApiTokenSequence aTokens;
switch( getFilterType() )
@@ -546,8 +541,14 @@ void DefinedName::convertFormula()
case FILTER_UNKNOWN:
break;
}
- xTokens->setTokens( aTokens );
+ return aTokens;
+}
+void DefinedName::convertFormula()
+{
+ Reference< XFormulaTokens > xTokens( mxNamedRange, UNO_QUERY );
+ if( !xTokens.is() )
+ return;
// set built-in names (print ranges, repeated titles, filter ranges)
if( !isGlobalName() ) switch( mcBuiltinId )
{
@@ -636,10 +637,11 @@ void DefinedNamesBuffer::importDefinedName( BiffInputStream& rStrm )
void DefinedNamesBuffer::finalizeImport()
{
// first insert all names without formula definition into the document, and insert them into the maps
+ int index = 0;
for( DefNameVector::iterator aIt = maDefNames.begin(), aEnd = maDefNames.end(); aIt != aEnd; ++aIt )
{
DefinedNameRef xDefName = *aIt;
- xDefName->createNameObject();
+ xDefName->createNameObject( ++index );
// map by sheet index and original model name
maModelNameMap[ SheetNameKey( xDefName->getLocalCalcSheet(), xDefName->getUpcaseModelName() ) ] = xDefName;
// map by sheet index and built-in identifier
diff --git a/sc/source/filter/oox/sheetdatabuffer.cxx b/sc/source/filter/oox/sheetdatabuffer.cxx
index 3b152433cd31..4904a0cac9f5 100644
--- a/sc/source/filter/oox/sheetdatabuffer.cxx
+++ b/sc/source/filter/oox/sheetdatabuffer.cxx
@@ -396,14 +396,15 @@ void SheetDataBuffer::setRowFormat( sal_Int32 nRow, sal_Int32 nXfId, bool bCusto
// try to expand cached row range, if formatting is equal
if( (maXfIdRowRange.maRowRange.mnLast < 0) || !maXfIdRowRange.tryExpand( nRow, nXfId ) )
{
- writeXfIdRowRangeProperties( maXfIdRowRange );
+
+ maXfIdRowRangeList[ maXfIdRowRange.mnXfId ].push_back( maXfIdRowRange.maRowRange );
maXfIdRowRange.set( nRow, nXfId );
}
}
else if( maXfIdRowRange.maRowRange.mnLast >= 0 )
{
// finish last cached row range
- writeXfIdRowRangeProperties( maXfIdRowRange );
+ maXfIdRowRangeList[ maXfIdRowRange.mnXfId ].push_back( maXfIdRowRange.maRowRange );
maXfIdRowRange.set( -1, -1 );
}
}
@@ -428,6 +429,30 @@ void SheetDataBuffer::setStandardNumFmt( const CellAddress& rCellAddr, sal_Int16
}
}
+void addIfNotInMyMap( StylesBuffer& rStyles, std::map< std::pair< sal_Int32, sal_Int32 >, ApiCellRangeList >& rMap, sal_Int32 nXfId, sal_Int32 nFormatId, const ApiCellRangeList& rRangeList )
+{
+ Xf* pXf1 = rStyles.getCellXf( nXfId ).get();
+ if ( pXf1 )
+ {
+ for ( std::map< std::pair< sal_Int32, sal_Int32 >, ApiCellRangeList >::iterator it = rMap.begin(), it_end = rMap.end(); it != it_end; ++it )
+ {
+ if ( it->first.second == nFormatId )
+ {
+ Xf* pXf2 = rStyles.getCellXf( it->first.first ).get();
+ if ( *pXf1 == *pXf2 ) // already exists
+ {
+ // add ranges from the rangelist to the existing rangelist for the
+ // matching style ( should we check if they overlap ? )
+ for ( ApiCellRangeList::const_iterator iter = rRangeList.begin(), iter_end = rRangeList.end(); iter != iter_end; ++iter )
+ it->second.push_back( *iter );
+ return;
+ }
+ }
+ }
+ rMap[ std::pair<sal_Int32, sal_Int32>( nXfId, nFormatId ) ] = rRangeList;
+ }
+}
+
void SheetDataBuffer::finalizeImport()
{
// insert all cells of all open cell blocks
@@ -442,11 +467,26 @@ void SheetDataBuffer::finalizeImport()
finalizeTableOperation( aIt->first, aIt->second );
// write default formatting of remaining row range
- writeXfIdRowRangeProperties( maXfIdRowRange );
-
+ maXfIdRowRangeList[ maXfIdRowRange.mnXfId ].push_back( maXfIdRowRange.maRowRange );
+ for ( std::map< sal_Int32, std::vector< ValueRange > >::iterator it = maXfIdRowRangeList.begin(), it_end = maXfIdRowRangeList.end(); it != it_end; ++it )
+ {
+ ApiCellRangeList rangeList;
+ AddressConverter& rAddrConv = getAddressConverter();
+ // get all row ranges for id
+ for ( std::vector< ValueRange >::iterator rangeIter = it->second.begin(), rangeIter_end = it->second.end(); rangeIter != rangeIter_end; ++rangeIter )
+ {
+ CellRangeAddress aRange( getSheetIndex(), 0, rangeIter->mnFirst, rAddrConv.getMaxApiAddress().Column, rangeIter->mnLast );
+ rangeList.push_back( aRange );
+ }
+ PropertySet aPropSet( getCellRangeList( rangeList ) );
+ getStyles().writeCellXfToPropertySet( aPropSet, it->first );
+ }
+ std::map< std::pair< sal_Int32, sal_Int32 >, ApiCellRangeList > rangeStyleListMap;
+ // gather all ranges that have the same style and apply them in bulk
for( XfIdRangeListMap::const_iterator aIt = maXfIdRangeLists.begin(), aEnd = maXfIdRangeLists.end(); aIt != aEnd; ++aIt )
- writeXfIdRangeListProperties( aIt->first.first, aIt->first.second, aIt->second );
-
+ addIfNotInMyMap( getStyles(), rangeStyleListMap, aIt->first.first, aIt->first.second, aIt->second );
+ for ( std::map< std::pair< sal_Int32, sal_Int32 >, ApiCellRangeList >::iterator it = rangeStyleListMap.begin(), it_end = rangeStyleListMap.end(); it != it_end; ++it )
+ writeXfIdRangeListProperties( it->first.first, it->first.second, it->second );
// merge all cached merged ranges and update right/bottom cell borders
for( MergedRangeList::iterator aIt = maMergedRanges.begin(), aEnd = maMergedRanges.end(); aIt != aEnd; ++aIt )
finalizeMergedRange( aIt->maRange );
@@ -530,7 +570,7 @@ void SheetDataBuffer::createSharedFormula( const BinAddress& rMapKey, const ApiT
append( static_cast< sal_Int32 >( getSheetIndex() + 1 ) ).
append( sal_Unicode( '_' ) ).append( rMapKey.mnRow ).
append( sal_Unicode( '_' ) ).append( rMapKey.mnCol ).makeStringAndClear();
- Reference< XNamedRange > xNamedRange = createNamedRangeObject( aName );
+ Reference< XNamedRange > xNamedRange = createNamedRangeObject( aName, rTokens, 0 );
OSL_ENSURE( xNamedRange.is(), "SheetDataBuffer::createSharedFormula - cannot create shared formula" );
PropertySet aNameProps( xNamedRange );
aNameProps.setProperty( PROP_IsSharedFormula, true );
@@ -542,9 +582,6 @@ void SheetDataBuffer::createSharedFormula( const BinAddress& rMapKey, const ApiT
{
// store the token index in the map
maSharedFormulas[ rMapKey ] = nTokenIndex;
- // set the formula definition
- Reference< XFormulaTokens > xTokens( xNamedRange, UNO_QUERY_THROW );
- xTokens->setTokens( rTokens );
// retry to insert a pending shared formula cell
if( mbPendingSharedFmla )
setCellFormula( maSharedFmlaAddr, resolveSharedFormula( maSharedBaseAddr ) );
@@ -737,8 +774,8 @@ void SheetDataBuffer::finalizeMergedRange( const CellRangeAddress& rRange )
{
// merge the cell range
Reference< XMergeable > xMerge( getCellRange( rRange ), UNO_QUERY_THROW );
- xMerge->merge( sal_True );
+ xMerge->merge( sal_True );
// if merging this range worked (no overlapping merged ranges), update cell borders
Reference< XCell > xTopLeft( getCell( CellAddress( getSheetIndex(), rRange.StartColumn, rRange.StartRow ) ), UNO_SET_THROW );
PropertySet aTopLeftProp( xTopLeft );
diff --git a/sc/source/filter/oox/stylesbuffer.cxx b/sc/source/filter/oox/stylesbuffer.cxx
index 21bb1e13aee3..4d2b6189fc40 100644
--- a/sc/source/filter/oox/stylesbuffer.cxx
+++ b/sc/source/filter/oox/stylesbuffer.cxx
@@ -3406,6 +3406,41 @@ void StylesBuffer::writeFillToPropertyMap( PropertyMap& rPropMap, sal_Int32 nFil
pFill->writeToPropertyMap( rPropMap );
}
+bool operator==( const XfModel& rXfModel1, const XfModel& rXfModel2 )
+{
+ return ( rXfModel1.mbCellXf == rXfModel2.mbCellXf &&
+ rXfModel1.mnStyleXfId == rXfModel2.mnStyleXfId &&
+ rXfModel1.mbFontUsed == rXfModel2.mbFontUsed &&
+ rXfModel1.mnFontId == rXfModel2.mnFontId &&
+ rXfModel1.mbNumFmtUsed == rXfModel2.mbNumFmtUsed &&
+ rXfModel1.mnNumFmtId == rXfModel2.mnNumFmtId &&
+ rXfModel1.mbAlignUsed == rXfModel2.mbAlignUsed &&
+ rXfModel1.mbBorderUsed == rXfModel2.mbBorderUsed &&
+ rXfModel1.mnBorderId == rXfModel2.mnBorderId &&
+ rXfModel1.mbAreaUsed == rXfModel2.mbAreaUsed &&
+ rXfModel1.mnFillId == rXfModel2.mnFillId &&
+ rXfModel1.mbProtUsed == rXfModel2.mbProtUsed );
+}
+
+bool operator==( const Xf& rXf1, const Xf& rXf2 )
+{
+ if ( rXf1.maModel == rXf2.maModel )
+ {
+ if ( rXf1.maModel.mbAlignUsed )
+ {
+ if ( !( rXf1.maAlignment.getApiData() == rXf2.maAlignment.getApiData() ) )
+ return false;
+ }
+ if ( rXf1.maModel.mbProtUsed )
+ {
+ if ( !( rXf1.maProtection.getApiData() == rXf2.maProtection.getApiData() ) )
+ return false;
+ }
+ return true;
+ }
+ return false;
+}
+
void StylesBuffer::writeCellXfToPropertyMap( PropertyMap& rPropMap, sal_Int32 nXfId ) const
{
if( Xf* pXf = maCellXfs.get( nXfId ).get() )
diff --git a/sc/source/filter/oox/workbookhelper.cxx b/sc/source/filter/oox/workbookhelper.cxx
index 9760b45b1c82..c3c5134c9ace 100644
--- a/sc/source/filter/oox/workbookhelper.cxx
+++ b/sc/source/filter/oox/workbookhelper.cxx
@@ -38,6 +38,7 @@
#include <com/sun/star/sheet/XNamedRanges.hpp>
#include <com/sun/star/sheet/XSpreadsheet.hpp>
#include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
+#include <com/sun/star/sheet/NamedRangeFlag.hpp>
#include <com/sun/star/style/XStyle.hpp>
#include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
#include <com/sun/star/table/CellAddress.hpp>
@@ -68,6 +69,13 @@
#include "viewsettings.hxx"
#include "workbooksettings.hxx"
#include "worksheetbuffer.hxx"
+#include "scmod.hxx"
+#include "docsh.hxx"
+#include "document.hxx"
+#include "docuno.hxx"
+#include "rangenam.hxx"
+#include "tokenarray.hxx"
+#include "tokenuno.hxx"
namespace oox {
namespace xls {
@@ -132,6 +140,25 @@ public:
// document model ---------------------------------------------------------
+ inline ScDocument& getScDocument() const
+ {
+ if ( !mpDoc )
+ {
+ if ( mxDoc.get() )
+ {
+ ScModelObj* pModel = dynamic_cast< ScModelObj* >( mxDoc.get() );
+ ScDocShell* pDocShell = NULL;
+ if ( pModel )
+ pDocShell = (ScDocShell*)pModel->GetEmbeddedObject();
+ if ( pDocShell )
+ mpDoc = pDocShell->GetDocument();
+ }
+ }
+ if ( !mpDoc )
+ throw RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Workbookhelper::getScDocument(): Failed to access ScDocument from model" ) ), Reference< XInterface >() );
+ return *mpDoc;
+ }
+
/** Returns a reference to the source/target spreadsheet document model. */
inline Reference< XSpreadsheetDocument > getDocument() const { return mxDoc; }
/** Returns the cell or page styles container from the Calc document. */
@@ -139,9 +166,9 @@ public:
/** Returns the specified cell or page style from the Calc document. */
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;
+ Reference< XNamedRange > createNamedRangeObject( OUString& orName, const Sequence< FormulaToken>& rTokens, sal_Int32 nIndex, 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;
+ Reference< XNamedRange > createLocalNamedRangeObject( OUString& orName, const ::com::sun::star::uno::Sequence< ::com::sun::star::sheet::FormulaToken>& rTokens, sal_Int32 nIndex, 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. */
@@ -289,6 +316,7 @@ private:
BiffType meBiff; /// BIFF version for BIFF import/export.
rtl_TextEncoding meTextEnc; /// BIFF byte string text encoding.
bool mbHasCodePage; /// True = CODEPAGE record exists in imported stream.
+ mutable ScDocument* mpDoc;
};
// ----------------------------------------------------------------------------
@@ -299,7 +327,8 @@ WorkbookGlobals::WorkbookGlobals( ExcelFilter& rFilter ) :
meFilterType( FILTER_OOXML ),
mpOoxFilter( &rFilter ),
mpBiffFilter( 0 ),
- meBiff( BIFF_UNKNOWN )
+ meBiff( BIFF_UNKNOWN ),
+ mpDoc( NULL )
{
// register at the filter, needed for virtual callbacks (even during construction)
mrExcelBase.registerWorkbookGlobals( *this );
@@ -344,8 +373,27 @@ Reference< XStyle > WorkbookGlobals::getStyleObject( const OUString& rStyleName,
OSL_ENSURE( xStyle.is(), "WorkbookGlobals::getStyleObject - cannot access style object" );
return xStyle;
}
+void lcl_addNewByNameAndTokens( ScDocument& rDoc, ScRangeName* pNames, const OUString& rName, const Sequence<FormulaToken>& rTokens, sal_Int16 nIndex, sal_Int32 nUnoType )
+{
+ bool bDone = false;
+ sal_uInt16 nNewType = RT_NAME;
+ if ( nUnoType & NamedRangeFlag::FILTER_CRITERIA ) nNewType |= RT_CRITERIA;
+ if ( nUnoType & NamedRangeFlag::PRINT_AREA ) nNewType |= RT_PRINTAREA;
+ if ( nUnoType & NamedRangeFlag::COLUMN_HEADER ) nNewType |= RT_COLHEADER;
+ if ( nUnoType & NamedRangeFlag::ROW_HEADER ) nNewType |= RT_ROWHEADER;
+ ScTokenArray aTokenArray;
+ (void)ScTokenConversion::ConvertToTokenArray( rDoc, aTokenArray, rTokens );
+ ScRangeData* pNew = new ScRangeData( &rDoc, rName, aTokenArray, ScAddress(), nNewType );
+ pNew->GuessPosition();
+ if ( nIndex )
+ pNew->SetIndex( nIndex );
+ if ( pNames->insert(pNew) )
+ bDone = true;
+ if (!bDone)
+ throw RuntimeException();
+}
-Reference< XNamedRange > WorkbookGlobals::createNamedRangeObject( OUString& orName, sal_Int32 nNameFlags ) const
+Reference< XNamedRange > WorkbookGlobals::createNamedRangeObject( OUString& orName, const Sequence< FormulaToken>& rTokens, sal_Int32 nIndex, sal_Int32 nNameFlags ) const
{
// create the name and insert it into the Calc document
Reference< XNamedRange > xNamedRange;
@@ -357,7 +405,9 @@ Reference< XNamedRange > WorkbookGlobals::createNamedRangeObject( OUString& orNa
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 );
+ ScDocument& rDoc = getScDocument();
+ ScRangeName* pNames = rDoc.GetRangeName();
+ lcl_addNewByNameAndTokens( rDoc, pNames, orName, rTokens, nIndex, nNameFlags );
xNamedRange.set( xNamedRanges->getByName( orName ), UNO_QUERY );
}
catch( Exception& )
@@ -367,7 +417,7 @@ Reference< XNamedRange > WorkbookGlobals::createNamedRangeObject( OUString& orNa
return xNamedRange;
}
-Reference< XNamedRange > WorkbookGlobals::createLocalNamedRangeObject( OUString& orName, sal_Int32 nNameFlags, sal_Int32 nTab ) const
+Reference< XNamedRange > WorkbookGlobals::createLocalNamedRangeObject( OUString& orName, const ::com::sun::star::uno::Sequence< ::com::sun::star::sheet::FormulaToken>& rTokens, sal_Int32 nIndex, sal_Int32 nNameFlags, sal_Int32 nTab ) const
{
// create the name and insert it into the Calc document
Reference< XNamedRange > xNamedRange;
@@ -383,7 +433,9 @@ Reference< XNamedRange > WorkbookGlobals::createLocalNamedRangeObject( OUString&
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 );
+ ScDocument& rDoc = getScDocument();
+ ScRangeName* pNames = rDoc.GetRangeName( nTab );
+ lcl_addNewByNameAndTokens( rDoc, pNames, orName, rTokens, nIndex, nNameFlags );
xNamedRange.set( xNamedRanges->getByName( orName ), UNO_QUERY );
}
catch( Exception& )
@@ -704,6 +756,11 @@ void WorkbookHelper::finalizeWorkbookImport()
// document model -------------------------------------------------------------
+ScDocument& WorkbookHelper::getScDocument() const
+{
+ return mrBookGlob.getScDocument();
+}
+
Reference< XSpreadsheetDocument > WorkbookHelper::getDocument() const
{
return mrBookGlob.getDocument();
@@ -761,14 +818,14 @@ Reference< XStyle > WorkbookHelper::getStyleObject( const OUString& rStyleName,
return mrBookGlob.getStyleObject( rStyleName, bPageStyle );
}
-Reference< XNamedRange > WorkbookHelper::createNamedRangeObject( OUString& orName, sal_Int32 nNameFlags ) const
+Reference< XNamedRange > WorkbookHelper::createNamedRangeObject( OUString& orName, const Sequence< FormulaToken>& rTokens, sal_Int32 nIndex, sal_Int32 nNameFlags ) const
{
- return mrBookGlob.createNamedRangeObject( orName, nNameFlags );
+ return mrBookGlob.createNamedRangeObject( orName, rTokens, nIndex, nNameFlags );
}
-Reference< XNamedRange > WorkbookHelper::createLocalNamedRangeObject( OUString& orName, sal_Int32 nNameFlags, sal_Int32 nTab ) const
+Reference< XNamedRange > WorkbookHelper::createLocalNamedRangeObject( OUString& orName, const ::com::sun::star::uno::Sequence< ::com::sun::star::sheet::FormulaToken>& rTokens, sal_Int32 nIndex, sal_Int32 nNameFlags, sal_Int32 nTab ) const
{
- return mrBookGlob.createLocalNamedRangeObject( orName, nNameFlags, nTab );
+ return mrBookGlob.createLocalNamedRangeObject( orName, rTokens, nIndex, nNameFlags, nTab );
}
Reference< XDatabaseRange > WorkbookHelper::createDatabaseRangeObject( OUString& orName, const CellRangeAddress& rRangeAddr ) const