24#include <document.hxx>
26#include <tokenarray.hxx>
37#include <oox/token/tokens.hxx>
50 explicit XclExpName(
const XclExpRoot& rRoot,
const OUString& rName );
57 void SetLocalTab(
SCTAB nScTab );
59 void SetHidden(
bool bHidden =
true );
63 void SetMacroCall(
bool bVBasic,
bool bFunc );
67 void SetSymbol(
const OUString& rValue );
70 const OUString& GetOrigName()
const {
return maOrigName; }
73 sal_Unicode GetBuiltInName()
const {
return mcBuiltIn; }
76 const OUString& GetSymbol()
const {
return msSymbol; }
81 SCTAB GetScTab()
const {
return mnScTab; }
84 bool IsVolatile()
const;
87 bool IsMacroCall(
bool bVBasic,
bool bFunc )
const;
98 OUString GetWithDefaultRangeSeparator(
const OUString& rSymbol )
const;
108 sal_uInt16 mnExtSheet;
136 sal_uInt16
InsertMacroCall(
const OUString& rMacroName,
bool bVBasic,
bool bFunc,
bool bHidden );
139 const XclExpName*
GetName( sal_uInt16 nNameIdx )
const;
153 typedef ::std::map< ::std::pair<SCTAB, OUString>, sal_uInt16>
NamedExpMap;
166 const OUString& sSymbol )
const;
172 sal_uInt16
Append( XclExpName* pName );
196XclExpName::XclExpName(
const XclExpRoot& rRoot,
const OUString& rName ) :
212 mcBuiltIn( cBuiltIn ),
242void XclExpName::SetLocalTab(
SCTAB nScTab )
244 OSL_ENSURE( GetTabInfo().IsExportTab( nScTab ),
"XclExpName::SetLocalTab - invalid sheet index" );
245 if( !GetTabInfo().IsExportTab( nScTab ) )
249 GetGlobalLinkManager().FindExtSheet( mnExtSheet, mnXclTab, nScTab );
255 mnExtSheet = ~mnExtSheet + 1;
267void XclExpName::SetHidden(
bool bHidden )
272void XclExpName::SetMacroCall(
bool bVBasic,
bool bFunc )
279void XclExpName::SetSymbol(
const OUString& rSymbol )
284bool XclExpName::IsVolatile()
const
286 return mxTokArr && mxTokArr->IsVolatile();
289bool XclExpName::IsMacroCall(
bool bVBasic,
bool bFunc )
const
298 OSL_ENSURE( mxName && (mxName->Len() > 0),
"XclExpName::Save - missing name" );
300 SetRecSize( 11 + mxName->GetSize() + (mxTokArr ? mxTokArr->GetSize() : 2) );
304OUString XclExpName::GetWithDefaultRangeSeparator(
const OUString& rSymbol )
const
306 sal_Int32
nPos = rSymbol.indexOf(
';');
312 ScRefFlags nRes = aRange.
Parse( rSymbol.copy(0, nPos), GetDoc(), detailsXL );
315 nRes = aRange.
Parse( rSymbol.copy(nPos+1), GetDoc(), detailsXL );
318 return rSymbol.replaceFirst(
";",
",");
333 rWorkbook->startElement( XML_definedName,
342 XML_name, maOrigName.toUtf8(),
350 rWorkbook->writeEscaped( GetWithDefaultRangeSeparator( msSymbol ) );
351 rWorkbook->endElement( XML_definedName );
356 sal_uInt16 nFmlaSize = mxTokArr ? mxTokArr->GetSize() : 0;
360 mxName->WriteLenField( rStrm );
365 mxName->WriteFlagField( rStrm );
366 mxName->WriteBuffer( rStrm );
368 mxTokArr->WriteArray( rStrm );
375 bool bFixRequired =
false;
430 sal_uInt16 nNameIdx = 0;
438 bool bEmulateGlobalRelativeTable =
false;
446 nNameIdx =
FindNamedExp( bEmulateGlobalRelativeTable ? nCurrTab : nTab,
pData->GetName() );
457 xName->SetTokenArray( xTokArr );
458 xName->SetLocalTab( aRange.
aStart.
Tab() );
460 xName->SetSymbol( sSymbol );
467 xName->SetTokenArray( xTokArr );
468 xName->SetLocalTab( nScTab );
471 xName->SetSymbol( sSymbol );
478 OSL_ENSURE( !rName.isEmpty(),
"XclExpNameManagerImpl::InsertUniqueName - empty name" );
480 xName->SetTokenArray( xTokArr );
481 xName->SetLocalTab( nScTab );
488 if( rName.isEmpty() )
495 if( xName->IsGlobal() && (xName->GetOrigName() == rName) )
496 return static_cast< sal_uInt16
>( nListIdx + 1 );
507 if( rMacroName.isEmpty() )
514 if( xName->IsMacroCall( bVBasic, bFunc ) && (xName->GetOrigName() == rMacroName) )
515 return static_cast< sal_uInt16
>( nListIdx + 1 );
520 xName->SetMacroCall( bVBasic, bFunc );
521 xName->SetHidden( bHidden );
532 OSL_ENSURE(
maNameList.
HasRecord( nNameIdx - 1 ),
"XclExpNameManagerImpl::GetName - wrong record index" );
546 rWorkbook->startElement(XML_definedNames);
548 rWorkbook->endElement( XML_definedNames );
555 NamedExpMap::key_type key(nTab,
sName);
561 const OUString& rName,
const OUString& sSymbol )
const
573 if( xName->GetBuiltInName() == cBuiltIn && xName->GetSymbol().replace(
';',
',') == sSymbol.replace(
';',
',') )
577 if ( xName->GetSymbol() != sSymbol )
579 xName->SetSymbol(xName->GetSymbol().replace(
';',
','));
581 return static_cast< sal_uInt16
>(
nPos + 1 );
590 OUString aNewName( rName );
591 sal_Int32 nAppIdx = 0;
600 bExist = xName->GetOrigName() == aNewName;
603 aNewName = rName +
"_" + OUString::number( ++nAppIdx );
619 const OUString& rName = rRangeData.
GetName();
627 xName->SetLocalTab(nTab);
628 sal_uInt16 nNameIdx =
Append( xName );
630 NamedExpMap::key_type key(nTab, rRangeData.
GetName());
658 &rRangeData.
GetPos() :
nullptr );
662 xName->SetTokenArray( xTokArr );
663 xName->SetSymbol( sSymbol );
671 if( nBuiltInIdx != 0 )
677 key = NamedExpMap::key_type(nTab, rRangeData.
GetName());
693 for(
SCTAB nScTabIdx = 0, nScTabCount = rTabInfo.
GetScTabCount(); nScTabIdx < nScTabCount; ++nScTabIdx )
710 ScRange aRange( *pPrintRange );
719 if( !aRangeList.
empty() )
729 oColRange->aStart.Col(), 0, nScTab,
734 0, oRowRange->aStart.Row(), nScTab,
738 if( !aTitleList.
empty() )
751 std::vector<ScRangeData*> vEmulateAsLocalRange;
753 for (
const auto& rEntry : rNamedRanges)
763 vEmulateAsLocalRange.emplace_back(rEntry.second.get());
772 for (
const auto& [rTab, pRangeName] : rLocalNames)
774 for (
const auto& rEntry : *pRangeName)
786 for (
auto rangeDataItr : vEmulateAsLocalRange )
811 return mxImpl->InsertName( nTab, nScNameIdx, nCurrTab );
817 return mxImpl->InsertBuiltInName( cBuiltIn, xTokArr, rRange );
822 sal_uInt16 nNameIdx = 0;
823 if( !rRangeList.
empty() )
826 nNameIdx =
mxImpl->InsertBuiltInName( cBuiltIn, xTokArr, rRangeList.
front().
aStart.
Tab(), rRangeList );
834 return mxImpl->InsertUniqueName( rName, xTokArr, nScTab );
839 return mxImpl->InsertRawName( rName );
844 return mxImpl->InsertMacroCall( rMacroName, bVBasic, bFunc, bHidden );
849 const XclExpName*
pName =
mxImpl->GetName( nNameIdx );
850 return pName ?
pName->GetOrigName() : OUString();
855 const XclExpName*
pName =
mxImpl->GetName( nNameIdx );
861 const XclExpName*
pName =
mxImpl->GetName( nNameIdx );
SC_DLLPUBLIC const ScRange * GetPrintRange(SCTAB nTab, sal_uInt16 nPos)
SC_DLLPUBLIC void GetAllTabRangeNames(ScRangeName::TabNameCopyMap &rRangeNames) const
Get all range names that are local to each table.
SC_DLLPUBLIC bool HasPrintRange()
SC_DLLPUBLIC std::optional< ScRange > GetRepeatColRange(SCTAB nTab)
SC_DLLPUBLIC std::optional< ScRange > GetRepeatRowRange(SCTAB nTab)
SC_DLLPUBLIC ScRangeName * GetRangeName(SCTAB nTab) const
SC_DLLPUBLIC sal_uInt16 GetPrintRangeCount(SCTAB nTab)
SC_DLLPUBLIC SCTAB GetTableCount() const
bool HasType(Type nType) const
void GetName(OUString &rName) const
const ScAddress & GetPos() const
SC_DLLPUBLIC OUString GetSymbol(const formula::FormulaGrammar::Grammar eGrammar=formula::FormulaGrammar::GRAM_DEFAULT) const
void Format(OUString &, ScRefFlags nFlags, const ScDocument &, formula::FormulaGrammar::AddressConvention eConv=formula::FormulaGrammar::CONV_OOO, sal_Unicode cDelimiter=0, bool bFullAddressNotation=false) const
void push_back(const ScRange &rRange)
SC_DLLPUBLIC ScRangeData * findByIndex(sal_uInt16 i) const
::std::map< SCTAB, const ScRangeName * > TabNameCopyMap
Map that stores non-managed pointers to ScRangeName instances.
OUString Format(const ScDocument &rDocument, ScRefFlags nFlags=ScRefFlags::ZERO, const ScAddress::Details &rDetails=ScAddress::detailsOOOa1, bool bFullAddressNotation=false) const
Returns string with formatted cell range from aStart to aEnd, according to provided address conventio...
ScRefFlags Parse(const OUString &, const ScDocument &, const ScAddress::Details &rDetails=ScAddress::detailsOOOa1, ScAddress::ExternalInfo *pExtInfo=nullptr, const css::uno::Sequence< css::sheet::ExternalLinkInfo > *pExternalLinks=nullptr, const OUString *pErrRef=nullptr)
void ValidateRangeList(ScRangeList &rScRanges, bool bWarn)
Checks and eventually crops the cell ranges to valid dimensions.
void InitTabFilter(SCTAB nScTab)
Creates the filter records for the specified sheet.
Implementation class of the name manager.
XclExpNameList maNameList
sal_uInt16 InsertBuiltInName(sal_Unicode cBuiltIn, const XclTokenArrayRef &xTokArr, SCTAB nScTab, const ScRangeList &aRangeList)
Inserts a new built-in defined name.
XclExpNameManagerImpl(const XclExpRoot &rRoot)
sal_uInt16 CreateName(SCTAB nTab, const ScRangeData &rRangeData)
Creates a new NAME record for the passed user-defined name.
NamedExpMap maNamedExpMap
Maps Calc's named range to Excel's NAME records.
size_t mnFirstUserIdx
List of NAME records.
void Initialize()
Creates NAME records for built-in and user defined names.
XclExpNameList::RecordRefType XclExpNameRef
sal_uInt16 FindBuiltInNameIdx(const OUString &rName, const OUString &sSymbol) const
Returns the index of an existing built-in NAME record with the passed definition, otherwise 0.
void CreateUserNames()
Creates NAME records for all user-defined names in the document.
sal_uInt16 FindNamedExp(SCTAB nTab, OUString sName)
sal_uInt16 Append(XclExpName *pName)
Appends a new NAME record to the record list.
const XclExpName * GetName(sal_uInt16 nNameIdx) const
Returns the NAME record at the specified position or 0 on error.
void SaveXml(XclExpXmlStream &rStrm)
sal_uInt16 InsertUniqueName(const OUString &rName, const XclTokenArrayRef &xTokArr, SCTAB nScTab)
Inserts a new defined name.
sal_uInt16 InsertRawName(const OUString &rName)
Returns index of an existing name, or creates a name without definition.
void Save(XclExpStream &rStrm)
Writes the entire list of NAME records.
void CreateBuiltInNames()
Creates NAME records for all built-in names in the document.
sal_uInt16 InsertName(SCTAB nTab, sal_uInt16 nScNameIdx, SCTAB nCurrTab)
Inserts the Calc name with the passed index and returns the Excel NAME index.
XclExpRecordList< XclExpName > XclExpNameList
sal_uInt16 Append(XclExpNameRef const &rxName)
::std::map< ::std::pair< SCTAB, OUString >, sal_uInt16 > NamedExpMap
sal_uInt16 InsertMacroCall(const OUString &rMacroName, bool bVBasic, bool bFunc, bool bHidden)
Searches or inserts a defined name describing a macro name.
OUString GetUnusedName(const OUString &rName) const
Returns an unused name for the passed name.
sal_uInt16 InsertRawName(const OUString &rName)
Returns index of an existing name, or creates a name without definition.
SCTAB GetScTab(sal_uInt16 nNameIdx) const
Returns the Calc sheet of a local defined name, or SCTAB_GLOBAL for global defined names.
sal_uInt16 InsertUniqueName(const OUString &rName, const XclTokenArrayRef &xTokArr, SCTAB nScTab)
Inserts a new defined name.
sal_uInt16 InsertName(SCTAB nTab, sal_uInt16 nScNameIdx, SCTAB nCurrTab)
Inserts the Calc name with the passed index and returns the Excel NAME index.
XclExpNameManager(const XclExpRoot &rRoot)
bool IsVolatile(sal_uInt16 nNameIdx) const
Returns true, if the specified defined name is volatile.
void Initialize()
Creates NAME records for built-in and user defined names.
virtual ~XclExpNameManager() override
virtual void Save(XclExpStream &rStrm) override
Writes the entire list of NAME records.
sal_uInt16 InsertBuiltInName(sal_Unicode cBuiltIn, const ScRange &rRange)
Inserts a new built-in defined name, referring to the passed sheet range.
sal_uInt16 InsertMacroCall(const OUString &rMacroName, bool bVBasic, bool bFunc, bool bHidden=false)
Searches or inserts a defined name describing a macro name.
OUString GetOrigName(sal_uInt16 nNameIdx) const
Returns the Calc sheet of a local defined name, or SCTAB_GLOBAL for global defined names.
virtual void SaveXml(XclExpXmlStream &rStrm) override
XclExpNameMgrImplRef mxImpl
virtual void SaveXml(XclExpXmlStream &rStrm)
virtual void SaveXml(XclExpXmlStream &rStrm) override
bool HasRecord(size_t nPos) const
Returns true, if the passed index points to an exiting record.
void RemoveRecord(size_t nPos)
Removes the record at the specified position from the list.
virtual void Save(XclExpStream &rStrm) override
Writes the complete record list.
void AppendRecord(RecType *pRec)
Appends a record to the list.
RecType * GetRecord(size_t nPos) const
Returns reference to an existing record or empty reference on error.
Base class for single records with any content.
virtual void Save(XclExpStream &rStrm) override
Writes the record header and calls WriteBody().
virtual void WriteBody(XclExpStream &rStrm)
Writes the body of the record (without record header).
Access to global data from other classes.
XclExpNameManager & GetNameManager() const
Returns the buffer that contains internal defined names.
XclExpFormulaCompiler & GetFormulaCompiler() const
Returns the formula compiler to produce formula token arrays.
XclExpAddressConverter & GetAddressConverter() const
Returns the address converter.
XclExpTabInfo & GetTabInfo() const
Returns the buffer for Calc->Excel sheet index conversion.
const XclExpRoot & GetRoot() const
Returns this root instance - for code readability in derived classes.
XclExpFilterManager & GetFilterManager() const
Returns the filter manager.
This class is used to export Excel record streams.
This class provides methods to create an XclExpString.
static XclExpStringRef CreateString(const XclExpRoot &rRoot, const OUString &rString, XclStrFlags nFlags=XclStrFlags::NONE, sal_uInt16 nMaxLen=EXC_STR_MAXLEN)
Creates a new unformatted string from the passed string.
Stores the correct Excel sheet index for each Calc sheet.
SCTAB GetScTabCount() const
Returns the number of Calc sheets.
SCTAB GetRealScTab(SCTAB nSortedScTab) const
Returns the Calc sheet index of the nSortedTab-th entry in the sorted sheet names list.
bool IsExportTab(SCTAB nScTab) const
Returns true, if the specified Calc sheet will be exported.
XclOutput GetOutput() const
Returns the current output format of the importer/exporter.
XclBiff GetBiff() const
Returns the current BIFF version of the importer/exporter.
ScRangeName & GetNamedRanges() const
Returns the defined names container of the Calc document.
const ScAddress & GetXclMaxPos() const
Returns the highest possible cell address in an Excel document (using current BIFF version).
ScDocument & GetDoc() const
Returns reference to the destination document (import) or source document (export).
std::unique_ptr< sal_Int32[]> pData
std::shared_ptr< T > make_shared(Args &&... args)
const char * UseIf(const char *s, bool bUse)
std::shared_ptr< FastSerializerHelper > FSHelperPtr
Single reference (one address) into the sheet.
void SetAbsTab(SCTAB nVal)
void SetFlag3D(bool bVal)
static bool lcl_EnsureAbs3DToken(const SCTAB nTab, formula::FormulaToken *pTok, const bool bFix=true)
Returns true (needed fixing) if FormulaToken was not absolute and 3D.
std::shared_ptr< XclExpString > XclExpStringRef
const SCTAB SCTAB_GLOBAL
An invalid Calc sheet index, for common use.
const sal_uInt8 EXC_ERR_NAME
@ EXC_BIFF8
MS Excel 5.0, MS Excel 7.0 (95)
@ EXC_OUTPUT_XML_2007
MS Excel binary .xls.
const sal_Unicode EXC_BUILTIN_UNKNOWN
const sal_uInt16 EXC_NAME_DEFAULT
const sal_uInt16 EXC_ID_NAME
const sal_uInt16 EXC_NAME_VB
const sal_Unicode EXC_BUILTIN_FILTERDATABASE
const sal_uInt16 EXC_NAME_HIDDEN
const sal_uInt16 EXC_NAME_BUILTIN
const sal_Unicode EXC_BUILTIN_PRINTTITLES
const sal_uInt16 EXC_NAME_GLOBAL
BIFF2 function/command flag.
const sal_uInt16 EXC_NAME_PROC
const sal_Unicode EXC_BUILTIN_PRINTAREA
const sal_uInt16 EXC_NAME_FUNC
XclStrFlags
Flags used to specify import/export mode of strings.
@ EightBitLength
Always use UCS-2 characters (default: try to compress). BIFF8 only.