22#include <document.hxx>
29#include <tokenarray.hxx>
54 const XclAddress& GetAddress()
const {
return maXclPos;}
68 explicit XclImpSupbookTab( OUString aTabName );
70 const OUString& GetTabName()
const {
return maTabName; }
79 typedef std::shared_ptr< XclImpCrn > XclImpCrnRef;
81 std::vector< XclImpCrnRef > maCrnList;
116 bool GetLinkData( OUString& rApplic, OUString& rDoc )
const;
120 OUString
GetTabName( sal_uInt16 nXtiTab )
const;
130 std::vector< std::unique_ptr<XclImpSupbookTab> >
132 std::vector< std::unique_ptr<XclImpExtName> >
148 sal_uInt16 mnSupbook;
149 sal_uInt16 mnSBTabFirst;
150 sal_uInt16 mnSBTabLast;
156 rXti.mnSupbook =
rStrm.ReaduInt16();
157 rXti.mnSBTabFirst =
rStrm.ReaduInt16();
158 rXti.mnSBTabLast =
rStrm.ReaduInt16();
182 bool IsSelfRef( sal_uInt16 nXtiIndex )
const;
187 sal_uInt16 nXtiIndex )
const;
201 bool GetLinkData( OUString& rApplic, OUString& rTopic, sal_uInt16 nXtiIndex )
const;
203 OUString
GetMacroName( sal_uInt16 nExtSheet, sal_uInt16 nExtName )
const;
207 const XclImpXti*
GetXti( sal_uInt16 nXtiIndex )
const;
217 std::vector< std::unique_ptr<XclImpSupbook> >
235 if( rEntry.second >= nScTab )
241 XclTabNameMap::const_iterator aIt =
maTabNames.find( rXclTabName );
252 rStrm.EnableDecryption();
253 std::size_t nReadCount =
rStrm.GetRecLeft() / 2;
254 OSL_ENSURE( nReadCount <= 0xFFFF,
"XclImpTabInfo::ReadTabid - record too long" );
265 sal_uInt16 nReturn = 0;
268 if(
nValue == nCreatedId )
285 const size_t nMinRecordSize = 2;
286 const size_t nMaxRows =
rStrm.GetRecLeft() / (nMinRecordSize * (nLastCol+1));
287 if (nLastRow >= nMaxRows)
289 SAL_WARN(
"sc",
"Parsing error: " << nMaxRows <<
290 " max possible rows, but " << nLastRow <<
" index claimed, truncating");
292 nLastRow = nMaxRows-1;
297 mxCached->Resize(nLastCol+1, nLastRow+1);
298 for (
SCSIZE nRow = 0; nRow <= nLastRow; ++nRow)
300 for (
SCSIZE nCol = 0; nCol <= nLastCol; ++nCol)
303 nOp =
rStrm.ReaduInt8();
309 mxCached->PutDouble(fVal, nCol, nRow);
320 bool bVal =
rStrm.ReaduInt8();
321 mxCached->PutBoolean(bVal, nCol, nRow);
348 sal_uInt16 nFlags(0);
351 nFlags =
rStrm.ReaduInt16();
353 nLen =
rStrm.ReaduInt8();
363 maName.equalsIgnoreAsciiCase(
"EUROCONVERT" ) )
379 if (
rStrm.GetRecLeft() > 1)
387 std::unique_ptr<ScTokenArray> pArray;
389 nFmlaLen =
rStrm.ReaduInt16();
390 std::vector<OUString> aTabNames;
392 aTabNames.reserve(
nCount);
437bool extractSheetAndRange(
const OUString& rName, OUString& rSheet, OUString& rRange)
439 sal_Int32
n = rName.getLength();
442 bool bInSheet =
true;
443 for (sal_Int32 i = 0;
i <
n; ++
i, ++
p)
458 rSheet =
aBuf.makeStringAndClear();
466 rRange =
aBuf.makeStringAndClear();
473 sal_uInt16& rFileId, OUString& rTabName,
ScRange& rRange)
const
478 OUString aSheet, aRangeStr;
479 if (!extractSheetAndRange(
maName, aSheet, aRangeStr))
505 xTab->setWholeTableCached();
508 for (
SCSIZE j = 0; j < nC; ++j)
520 xTab->setCell(nCol, nRow, pToken, 0,
false);
526 xTab->setCell(nCol, nRow, pToken, 0,
false);
532 xTab->setCell(nCol, nRow, pToken, 0,
false);
562XclImpSupbookTab::XclImpSupbookTab( OUString aTabName ) :
563 maTabName(
std::move( aTabName ))
569 XclImpCrnRef crnRef = std::make_shared<XclImpCrn>(rStrm, rXclPos);
570 maCrnList.push_back( crnRef );
576 if (maCrnList.empty())
579 for (
const auto& rxCrn : maCrnList)
581 const XclImpCrn*
const pCrn = rxCrn.get();
583 switch (pCrn->GetType())
587 bool b = pCrn->GetBool();
589 pCacheTable->setCell(rAddr.
mnCol, rAddr.
mnRow, pToken, 0,
false);
594 double f = pCrn->GetValue();
596 pCacheTable->setCell(rAddr.
mnCol, rAddr.
mnRow, pToken, 0,
false);
603 pCacheTable->setCell(rAddr.
mnCol, rAddr.
mnRow, pToken, 0,
false);
610 pCacheTable->setCell(rAddr.
mnCol, rAddr.
mnRow, pToken, 0,
false);
626 sal_uInt16 nSBTabCnt;
627 nSBTabCnt =
rStrm.ReaduInt16();
629 if(
rStrm.GetRecLeft() == 2 )
631 switch(
rStrm.ReaduInt16() )
635 default: OSL_FAIL(
"XclImpSupbook::XclImpSupbook - unknown special SUPBOOK type" );
640 OUString aEncUrl(
rStrm.ReadUniString() );
644 if(
maXclUrl.equalsIgnoreAsciiCase(
"\010EUROTOOL.XLA" ) )
654 const size_t nMinRecordSize =
sizeof(sal_Int16);
655 const size_t nMaxRecords =
rStrm.GetRecLeft() / nMinRecordSize;
656 if (nSBTabCnt > nMaxRecords)
658 SAL_WARN(
"sc",
"Parsing error: " << nMaxRecords <<
659 " max possible entries, but " << nSBTabCnt <<
" claimed, truncating");
660 nSBTabCnt = nMaxRecords;
663 for( sal_uInt16 nSBTab = 0; nSBTab < nSBTabCnt; ++nSBTab )
665 OUString aTabName(
rStrm.ReadUniString() );
666 maSupbTabList.push_back( std::make_unique<XclImpSupbookTab>( aTabName ) );
690 nXclColLast =
rStrm.ReaduInt8();
691 nXclColFirst =
rStrm.ReaduInt8();
692 nXclRow =
rStrm.ReaduInt16();
694 for(
sal_uInt8 nXclCol = nXclColFirst; (nXclCol <= nXclColLast) && (
rStrm.GetRecLeft() > 1); ++nXclCol )
707 SAL_WARN(
"sc",
"XclImpSupbook::GetExternName - index must be >0");
722 OSL_ENSURE( nXclNameIdx > 0,
"XclImpSupbook::GetMacroName - index must be >0" );
751 const OUString& rTabName = rxTab->GetTabName();
754 pCacheTable->setWholeTableCached();
772 sal_uInt16 nXtiCount;
773 nXtiCount =
rStrm.ReaduInt16();
774 OSL_ENSURE(
static_cast< std::size_t
>( nXtiCount * 6 ) ==
rStrm.GetRecLeft(),
"XclImpLinkManagerImpl::ReadExternsheet - invalid count" );
775 nXtiCount =
static_cast< sal_uInt16
>( ::std::min< std::size_t >( nXtiCount,
rStrm.GetRecLeft() / 6 ) );
782 for(
auto& rNewEntry : aNewEntries )
784 if (!
rStrm.IsValid())
823 SCTAB& rnFirstScTab,
SCTAB& rnLastScTab, sal_uInt16 nXtiIndex )
const
825 if(
const XclImpXti* pXti =
GetXti( nXtiIndex ) )
829 rnFirstScTab = pXti->mnSBTabFirst;
830 rnLastScTab = pXti->mnSBTabLast;
840 return pSupbook ? pSupbook->
GetExternName( nExtName ) :
nullptr;
848 return &
p->GetXclUrl();
854 return p ?
p->GetTabName(nXtiTab) : OUString();
860 return pSupbook && pSupbook->
GetLinkData( rApplic, rTopic );
866 return pSupbook ? pSupbook->
GetMacroName( nExtName ) : OUString();
878 const XclImpXti* pXti =
GetXti( nXtiIndex );
889 rxSupbook->LoadCachedValues();
929 return mxImpl->IsSelfRef( nXtiIndex );
933 SCTAB& rnFirstScTab,
SCTAB& rnLastScTab, sal_uInt16 nXtiIndex )
const
935 return mxImpl->GetScTabRange( rnFirstScTab, rnLastScTab, nXtiIndex );
940 return mxImpl->GetExternName( nXtiIndex, nExtName );
945 return mxImpl->GetSupbookUrl(nXtiIndex);
950 return mxImpl->GetSupbookTabName(nXti, nXtiTab);
955 return mxImpl->GetLinkData( rApplic, rTopic, nXtiIndex );
960 return mxImpl->GetMacroName( nExtSheet, nExtName );
size_t SCSIZE
size_t typedef to be able to find places where code was changed from USHORT to size_t and is used to ...
virtual void ConvertExternName(std::unique_ptr< ScTokenArray > &rpArray, XclImpStream &rStrm, std::size_t nFormulaLen, const OUString &rUrl, const ::std::vector< OUString > &rTabNames)
SC_DLLPUBLIC bool CreateDdeLink(const OUString &rAppl, const OUString &rTopic, const OUString &rItem, sal_uInt8 nMode, const ScMatrixRef &pResults)
Tries to find a DDE link or creates a new, if not extant.
SC_DLLPUBLIC ScExternalRefManager * GetExternalRefManager() const
SC_DLLPUBLIC svl::SharedStringPool & GetSharedStringPool()
std::shared_ptr< Table > TableTypeRef
::formula::FormulaTokenRef TokenRef
sal_uInt16 getExternalFileId(const OUString &rFile)
ScExternalRefCache::TableTypeRef getCacheTable(sal_uInt16 nFileId, size_t nTabIndex) const
Get a cache table instance for specified table and table index.
void storeRangeNameTokens(sal_uInt16 nFileId, const OUString &rName, const ScTokenArray &rArray)
static SC_DLLPUBLIC OUString GetAbsDocName(const OUString &rFileName, const SfxObjectShell *pShell)
Matrix data type that can store values of mixed types.
ScMatrixValue Get(SCSIZE nC, SCSIZE nR) const
@ATTENTION: If bString the ScMatrixValue->pS may still be NULL to indicate an empty string!
void GetDimensions(SCSIZE &rC, SCSIZE &rR) const
ScRefFlags ParseAny(const OUString &, const ScDocument &, const ScAddress::Details &rDetails=ScAddress::detailsOOOa1)
SvStream & ReadDouble(double &rDouble)
Contains cached values in a 2-dimensional array.
This class stores one cached value of a cached value list (used for instance in CRN,...
MOper(svl::SharedStringPool &rPool, XclImpStream &rStrm)
const ScMatrix & GetCache() const
Stores contents of an external name.
XclImpCachedMatrixPtr mxDdeMatrix
void CreateDdeData(ScDocument &rDoc, const OUString &rApplc, const OUString &rExtDoc) const
Create and apply the cached list of this DDE Link to the document.
std::optional< MOper > moMOper
Cached results of the DDE link.
TokenArrayPtr mxArray
Cached values for OLE link.
bool CreateOleData(const ScDocument &rDoc, const OUString &rUrl, sal_uInt16 &rFileId, OUString &rTabName, ScRange &rRange) const
Create OLE link data.
bool HasFormulaTokens() const
XclImpExtNameType meType
Storage ID for OLE object storages.
XclImpExtName(XclImpSupbook &rSupbook, XclImpStream &rStrm, XclSupbookType eSubType, ExcelToSc *pFormulaConv)
Reads the external name from the stream.
OUString maName
Formula tokens for external name.
sal_uInt32 mnStorageId
The name of the external name.
void CreateExtNameData(const ScDocument &rDoc, sal_uInt16 nFileId) const
Implementation of the link manager.
bool GetLinkData(OUString &rApplic, OUString &rTopic, sal_uInt16 nXtiIndex) const
Tries to decode the URL of the specified XTI entry to OLE or DDE link components.
const XclImpSupbook * GetSupbook(sal_uInt16 nXtiIndex) const
Returns the specified SUPBOOK (external document).
void ReadSupbook(XclImpStream &rStrm)
Reads a SUPBOOK record.
bool GetScTabRange(SCTAB &rnFirstScTab, SCTAB &rnLastScTab, sal_uInt16 nXtiIndex) const
Returns the Calc sheet index range of the specified XTI entry.
void ReadExternname(XclImpStream &rStrm, ExcelToSc *pFormulaConv)
Reads an EXTERNNAME record and appends it to the current SUPBOOK.
std::vector< XclImpXti > XclImpXtiVector
void ReadCrn(XclImpStream &rStrm)
Reads a CRN record and appends it to the current SUPBOOK.
XclImpLinkManagerImpl(const XclImpRoot &rRoot)
std::vector< std::unique_ptr< XclImpSupbook > > maSupbookList
List of all XTI structures.
const OUString * GetSupbookUrl(sal_uInt16 nXtiIndex) const
Returns the absolute file URL of a supporting workbook specified by the index.
void ReadExternsheet(XclImpStream &rStrm)
Reads the EXTERNSHEET record.
const XclImpExtName * GetExternName(sal_uInt16 nXtiIndex, sal_uInt16 nExtName) const
Returns the specified external name or 0 on error.
void ReadXct(XclImpStream &rStrm)
Reads an XCT record and appends it to the current SUPBOOK.
XclImpXtiVector maXtiList
bool IsSelfRef(sal_uInt16 nXtiIndex) const
Returns true, if the specified XTI entry contains an internal reference.
OUString GetSupbookTabName(sal_uInt16 nXti, sal_uInt16 nXtiTab) const
const XclImpXti * GetXti(sal_uInt16 nXtiIndex) const
Returns the specified XTI (link entry from BIFF8 EXTERNSHEET record).
OUString GetMacroName(sal_uInt16 nExtSheet, sal_uInt16 nExtName) const
Returns the specified macro name or an empty string on error.
bool GetScTabRange(SCTAB &rnFirstScTab, SCTAB &rnLastScTab, sal_uInt16 nXtiIndex) const
Returns the Calc sheet index range of the specified XTI entry.
void ReadSupbook(XclImpStream &rStrm)
Reads a SUPBOOK record.
void ReadExternname(XclImpStream &rStrm, ExcelToSc *pFormulaConv)
Reads an EXTERNNAME record and appends it to the current SUPBOOK.
void ReadXct(XclImpStream &rStrm)
Reads an XCT record and appends it to the current SUPBOOK.
bool GetLinkData(OUString &rApplic, OUString &rTopic, sal_uInt16 nXtiIndex) const
Tries to decode the URL of the specified XTI entry to OLE or DDE link components.
void ReadCrn(XclImpStream &rStrm)
Reads a CRN record and appends it to the current SUPBOOK.
XclImpLinkManager(const XclImpRoot &rRoot)
const OUString * GetSupbookUrl(sal_uInt16 nXtiIndex) const
virtual ~XclImpLinkManager() override
void ReadExternsheet(XclImpStream &rStrm)
Reads the EXTERNSHEET record.
bool IsSelfRef(sal_uInt16 nXtiIndex) const
Returns true, if the specified XTI entry contains an internal reference.
OUString GetSupbookTabName(sal_uInt16 nXti, sal_uInt16 nXtiTab) const
OUString GetMacroName(sal_uInt16 nExtSheet, sal_uInt16 nExtName) const
Returns the specified macro name or an empty string on error.
const XclImpExtName * GetExternName(sal_uInt16 nXtiIndex, sal_uInt16 nExtName) const
Returns the specified external name or 0 on error.
XclImpLinkMgrImplPtr mxImpl
const XclImpName * GetName(sal_uInt16 nXclNameIdx) const
Returns the defined name specified by its Excel index.
Represents a defined name.
Access to global data from other classes.
XclImpNameManager & GetNameManager() const
Returns the buffer that contains internal defined names.
static OUString GetScAddInName(const OUString &rXclName)
Returns the Calc add-in function name for an Excel function name.
const XclImpRoot & GetRoot() const
Returns this root instance - for code readability in derived classes.
This class is used to import record oriented streams.
This class represents an external linked document (record SUPBOOK).
svl::SharedStringPool & GetSharedStringPool()
void ReadExternname(XclImpStream &rStrm, ExcelToSc *pFormulaConv)
Reads an EXTERNNAME record.
OUString maXclUrl
All external names of the document.
void ReadCrn(XclImpStream &rStrm)
Reads a CRN record (external referenced cell).
std::vector< std::unique_ptr< XclImpExtName > > maExtNameList
All sheet names of the document.
sal_uInt16 mnSBTab
Type of the supbook record.
bool GetLinkData(OUString &rApplic, OUString &rDoc) const
Tries to decode the URL to OLE or DDE link components.
OUString GetMacroName(sal_uInt16 nXclNameIdx) const
Returns the specified macro name (1-based) or an empty string on error.
const OUString & GetXclUrl() const
Returns the URL of the external document.
void ReadXct(XclImpStream &rStrm)
Reads an XCT record (count of following CRNs and current sheet).
const XclImpExtName * GetExternName(sal_uInt16 nXclIndex) const
Returns the external name specified by an index from the Excel document (one-based).
std::vector< std::unique_ptr< XclImpSupbookTab > > maSupbTabList
XclImpSupbook(XclImpStream &rStrm)
Reads the SUPBOOK record from stream.
XclSupbookType GetType() const
Returns the SUPBOOK record type.
XclSupbookType meType
URL of the external document (Excel mode).
sal_uInt16 GetTabCount() const
OUString GetTabName(sal_uInt16 nXtiTab) const
ScfUInt16Vec maTabIdVec
All Excel sheet names with Calc sheet index.
SCTAB GetScTabFromXclName(const OUString &rXclTabName) const
Returns the Calc sheet index from the passed original Excel sheet name.
sal_uInt16 GetCurrentIndex(sal_uInt16 nCreatedId, sal_uInt16 nMaxTabId) const
Returns the current sheet index calculated from creation index.
void ReadTabid(XclImpStream &rStrm)
Reads the TABID record.
void InsertScTab(SCTAB nScTab)
Inserts a Calc sheet index (increases all following sheet indexes).
void AppendXclTabName(const OUString &rXclTabName, SCTAB nScTab)
Appends an original Excel sheet name with corresponding Calc sheet index.
static void DecodeUrl(OUString &rUrl, OUString &rTabName, bool &rbSameWb, const XclImpRoot &rRoot, const OUString &rEncodedUrl)
Decodes an encoded external document URL with optional sheet name.
static bool DecodeLink(OUString &rApplic, OUString &rTopic, std::u16string_view aEncUrl)
Decodes the passed URL to OLE or DDE link components.
SfxObjectShell * GetDocShell() const
Returns the object shell of the Calc document.
ScExtDocOptions & GetExtDocOptions() const
Returns the extended document options.
ScDocument & GetDoc() const
Returns reference to the destination document (import) or source document (export).
SharedString intern(const OUString &rStr)
const sal_uInt8 SC_DDE_DEFAULT
#define SAL_WARN(area, stream)
Try NOT to use this struct.
const svl::SharedString & GetString() const
Only valid if ScMatrix methods indicate so!
bool GetBoolean() const
Only valid if ScMatrix methods indicate that this is a boolean.
A 2D cell address struct with Excel column and row indexes.
::boost::intrusive_ptr< ScMatrix > ScMatrixRef
XclImpStream & operator>>(XclImpStream &rStrm, XclImpDffPropSet &rPropSet)
@ xlExtOLE
A DDE link range.
@ xlExtDDE
An add-in function name.
@ xlExtAddIn
An external defined name.
@ xlExtEuroConvert
An OLE object link.
const SCTAB SCTAB_INVALID
An invalid Excel sheet index, for common use.
const sal_uInt8 EXC_CACHEDVAL_ERROR
const sal_uInt8 EXC_CACHEDVAL_STRING
@ EXC_BIFF8
MS Excel 5.0, MS Excel 7.0 (95)
const sal_uInt8 EXC_CACHEDVAL_BOOL
const sal_uInt8 EXC_CACHEDVAL_DOUBLE
const sal_uInt16 EXC_EXTN_OLE_OR_DDE
XclSupbookType
This enumeration specifies the type of a SUPBOOK record.
@ Extern
SUPBOOK is used for internal references.
@ Addin
SUPBOOK is used for external references.
@ Eurotool
SUPBOOK is used for DDE or OLE links.
@ Self
unknown SUPBOOK record type.
@ Special
SUPBOOK contains add-in functions.
const sal_uInt16 EXC_EXTN_OLE
const sal_uInt16 EXC_SUPB_ADDIN
const sal_uInt16 EXC_SUPB_SELF
const sal_uInt16 EXC_EXTN_BUILTIN
const sal_uInt16 EXC_TAB_DELETED
Special sheet index for external links.