21 #include <document.hxx>
28 #include <tokenarray.hxx>
53 const XclAddress& GetAddress()
const {
return maXclPos;}
62 class XclImpSupbookTab
67 explicit XclImpSupbookTab(
const OUString& rTabName );
69 const OUString& GetTabName()
const {
return maTabName; }
78 typedef std::shared_ptr< XclImpCrn > XclImpCrnRef;
80 std::vector< XclImpCrnRef > maCrnList;
115 bool GetLinkData( OUString& rApplic, OUString& rDoc )
const;
117 const OUString&
GetMacroName( sal_uInt16 nXclNameIdx )
const;
119 const OUString&
GetTabName( sal_uInt16 nXtiTab )
const;
129 std::vector< std::unique_ptr<XclImpSupbookTab> >
131 std::vector< std::unique_ptr<XclImpExtName> >
147 sal_uInt16 mnSupbook;
148 sal_uInt16 mnSBTabFirst;
149 sal_uInt16 mnSBTabLast;
181 bool IsSelfRef( sal_uInt16 nXtiIndex )
const;
186 sal_uInt16 nXtiIndex )
const;
200 bool GetLinkData( OUString& rApplic, OUString& rTopic, sal_uInt16 nXtiIndex )
const;
202 const OUString&
GetMacroName( sal_uInt16 nExtSheet, sal_uInt16 nExtName )
const;
206 const XclImpXti*
GetXti( sal_uInt16 nXtiIndex )
const;
216 std::vector< std::unique_ptr<XclImpSupbook> >
234 if( rEntry.second >= nScTab )
240 XclTabNameMap::const_iterator aIt =
maTabNames.find( rXclTabName );
252 std::size_t nReadCount = rStrm.
GetRecLeft() / 2;
253 OSL_ENSURE( nReadCount <= 0xFFFF,
"XclImpTabInfo::ReadTabid - record too long" );
264 sal_uInt16 nReturn = 0;
267 if(
nValue == nCreatedId )
284 const size_t nMinRecordSize = 2;
285 const size_t nMaxRows = rStrm.
GetRecLeft() / (nMinRecordSize * (nLastCol+1));
286 if (nLastRow >= nMaxRows)
288 SAL_WARN(
"sc",
"Parsing error: " << nMaxRows <<
289 " max possible rows, but " << nLastRow <<
" index claimed, truncating");
291 nLastRow = nMaxRows-1;
296 mxCached->Resize(nLastCol+1, nLastRow+1);
297 for (
SCSIZE nRow = 0; nRow <= nLastRow; ++nRow)
299 for (
SCSIZE nCol = 0; nCol <= nLastCol; ++nCol)
308 mxCached->PutDouble(fVal, nCol, nRow);
320 mxCached->PutBoolean(bVal, nCol, nRow);
347 sal_uInt16 nFlags(0);
362 maName.equalsIgnoreAsciiCase(
"EUROCONVERT" ) )
386 std::unique_ptr<ScTokenArray> pArray;
389 std::vector<OUString> aTabNames;
391 aTabNames.reserve(nCount);
392 for (sal_uInt16
i = 0;
i < nCount; ++
i)
436 bool extractSheetAndRange(
const OUString& rName, OUString& rSheet, OUString& rRange)
438 sal_Int32
n = rName.getLength();
441 bool bInSheet =
true;
442 for (sal_Int32 i = 0;
i < n; ++
i, ++p)
457 rSheet = aBuf.makeStringAndClear();
465 rRange = aBuf.makeStringAndClear();
472 sal_uInt16& rFileId, OUString& rTabName,
ScRange& rRange)
const
477 OUString aSheet, aRangeStr;
478 if (!extractSheetAndRange(
maName, aSheet, aRangeStr))
504 xTab->setWholeTableCached();
507 for (
SCSIZE j = 0; j < nC; ++j)
519 xTab->setCell(nCol, nRow, pToken, 0,
false);
525 xTab->setCell(nCol, nRow, pToken, 0,
false);
531 xTab->setCell(nCol, nRow, pToken, 0,
false);
561 XclImpSupbookTab::XclImpSupbookTab(
const OUString& rTabName ) :
562 maTabName( rTabName )
568 XclImpCrnRef crnRef = std::make_shared<XclImpCrn>(rStrm, rXclPos);
569 maCrnList.push_back( crnRef );
575 if (maCrnList.empty())
578 for (
const auto& rxCrn : maCrnList)
580 const XclImpCrn*
const pCrn = rxCrn.get();
582 switch (pCrn->GetType())
586 bool b = pCrn->GetBool();
588 pCacheTable->setCell(rAddr.
mnCol, rAddr.
mnRow, pToken, 0,
false);
593 double f = pCrn->GetValue();
595 pCacheTable->setCell(rAddr.
mnCol, rAddr.
mnRow, pToken, 0,
false);
602 pCacheTable->setCell(rAddr.
mnCol, rAddr.
mnRow, pToken, 0,
false);
609 pCacheTable->setCell(rAddr.
mnCol, rAddr.
mnRow, pToken, 0,
false);
625 sal_uInt16 nSBTabCnt;
634 default: OSL_FAIL(
"XclImpSupbook::XclImpSupbook - unknown special SUPBOOK type" );
643 if(
maXclUrl.equalsIgnoreAsciiCase(
"\010EUROTOOL.XLA" ) )
653 const size_t nMinRecordSize =
sizeof(sal_Int16);
654 const size_t nMaxRecords = rStrm.
GetRecLeft() / nMinRecordSize;
655 if (nSBTabCnt > nMaxRecords)
657 SAL_WARN(
"sc",
"Parsing error: " << nMaxRecords <<
658 " max possible entries, but " << nSBTabCnt <<
" claimed, truncating");
659 nSBTabCnt = nMaxRecords;
662 for( sal_uInt16 nSBTab = 0; nSBTab < nSBTabCnt; ++nSBTab )
665 maSupbTabList.push_back( std::make_unique<XclImpSupbookTab>( aTabName ) );
693 for(
sal_uInt8 nXclCol = nXclColFirst; (nXclCol <= nXclColLast) && (rStrm.
GetRecLeft() > 1); ++nXclCol )
694 rSbTab.ReadCrn( rStrm,
XclAddress( nXclCol, nXclRow ) );
699 maExtNameList.push_back( std::make_unique<XclImpExtName>( *
this, rStrm,
meType, pFormulaConv ) );
706 SAL_WARN(
"sc",
"XclImpSupbook::GetExternName - index must be >0");
721 OSL_ENSURE( nXclNameIdx > 0,
"XclImpSupbook::GetMacroName - index must be >0" );
750 const OUString& rTabName = rxTab->GetTabName();
753 pCacheTable->setWholeTableCached();
771 sal_uInt16 nXtiCount;
773 OSL_ENSURE( static_cast< std::size_t >( nXtiCount * 6 ) == rStrm.
GetRecLeft(),
"XclImpLinkManagerImpl::ReadExternsheet - invalid count" );
774 nXtiCount =
static_cast< sal_uInt16
>( ::std::min< std::size_t >( nXtiCount, rStrm.
GetRecLeft() / 6 ) );
781 for(
auto& rNewEntry : aNewEntries )
794 maSupbookList.push_back( std::make_unique<XclImpSupbook>( rStrm ) );
822 SCTAB& rnFirstScTab,
SCTAB& rnLastScTab, sal_uInt16 nXtiIndex )
const
824 if(
const XclImpXti* pXti =
GetXti( nXtiIndex ) )
828 rnFirstScTab = pXti->mnSBTabFirst;
829 rnLastScTab = pXti->mnSBTabLast;
839 return pSupbook ? pSupbook->
GetExternName( nExtName ) :
nullptr;
859 return pSupbook && pSupbook->
GetLinkData( rApplic, rTopic );
877 const XclImpXti* pXti =
GetXti( nXtiIndex );
888 rxSupbook->LoadCachedValues();
903 mxImpl->ReadExternsheet( rStrm );
908 mxImpl->ReadSupbook( rStrm );
923 mxImpl->ReadExternname( rStrm, pFormulaConv );
928 return mxImpl->IsSelfRef( nXtiIndex );
932 SCTAB& rnFirstScTab,
SCTAB& rnLastScTab, sal_uInt16 nXtiIndex )
const
934 return mxImpl->GetScTabRange( rnFirstScTab, rnLastScTab, nXtiIndex );
939 return mxImpl->GetExternName( nXtiIndex, nExtName );
944 return mxImpl->GetSupbookUrl(nXtiIndex);
949 return mxImpl->GetSupbookTabName(nXti, nXtiTab);
954 return mxImpl->GetLinkData( rApplic, rTopic, nXtiIndex );
959 return mxImpl->GetMacroName( nExtSheet, nExtName );
SC_DLLPUBLIC ScRefFlags ParseAny(const OUString &, const ScDocument &, const ScAddress::Details &rDetails=ScAddress::detailsOOOa1)
Matrix data type that can store values of mixed types.
const XclImpSupbook * GetSupbook(sal_uInt16 nXtiIndex) const
Returns the specified SUPBOOK (external document).
MOper, multiple operands, stores cached values of external range specified in the record...
static bool DecodeLink(OUString &rApplic, OUString &rTopic, const OUString &rEncUrl)
Decodes the passed URL to OLE or DDE link components.
XclImpSupbook(XclImpStream &rStrm)
Reads the SUPBOOK record from stream.
void storeRangeNameTokens(sal_uInt16 nFileId, const OUString &rName, const ScTokenArray &rArray)
SharedString intern(const OUString &rStr)
void ReadExternsheet(XclImpStream &rStrm)
Reads the EXTERNSHEET record.
SC_DLLPUBLIC svl::SharedStringPool & GetSharedStringPool()
const OUString & GetMacroName(sal_uInt16 nExtSheet, sal_uInt16 nExtName) const
Returns the specified macro name or an empty string on error.
void ReadExternsheet(XclImpStream &rStrm)
Reads the EXTERNSHEET record.
void ReadExternname(XclImpStream &rStrm, ExcelToSc *pFormulaConv)
Reads an EXTERNNAME record.
void ReadXct(XclImpStream &rStrm)
Reads an XCT record and appends it to the current SUPBOOK.
static OUString GetScAddInName(const OUString &rXclName)
Returns the Calc add-in function name for an Excel function name.
std::vector< std::unique_ptr< XclImpSupbookTab > > maSupbTabList
const sal_uInt8 SC_DDE_DEFAULT
ScMatrixValue Get(SCSIZE nC, SCSIZE nR) const
: If bString the ScMatrixValue->pS may still be NULL to indicate an empty string! ...
bool IsValid() const
Returns record reading state: false = record overread.
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.
const OUString & GetScName() const
const sal_uInt16 EXC_EXTN_OLE_OR_DDE
const ScMatrix & GetCache() const
sal_uInt16 getExternalFileId(const OUString &rFile)
SUPBOOK is used for DDE or OLE links.
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 sal_uInt8 EXC_CACHEDVAL_ERROR
ScDocument & GetDoc() const
Returns reference to the destination document (import) or source document (export).
const XclImpName * GetName(sal_uInt16 nXclNameIdx) const
Returns the defined name specified by its Excel index.
XclImpLinkManagerImpl(const XclImpRoot &rRoot)
const XclImpRoot & GetRoot() const
Returns this root instance - for code readability in derived classes.
MOper(svl::SharedStringPool &rPool, XclImpStream &rStrm)
XclImpXtiVector maXtiList
This class represents an external linked document (record SUPBOOK).
Try NOT to use this struct.
sal_uInt16 GetTabCount() const
const OUString & GetMacroName(sal_uInt16 nExtSheet, sal_uInt16 nExtName) const
Returns the specified macro name or an empty string on error.
const sal_uInt16 EXC_SUPB_ADDIN
XclImpExtNameType meType
Storage ID for OLE object storages.
const XclImpExtName * GetExternName(sal_uInt16 nXclIndex) const
Returns the external name specified by an index from the Excel document (one-based).
void ReadTabid(XclImpStream &rStrm)
Reads the TABID record.
bool GetBoolean() const
Only valid if ScMatrix methods indicate that this is a boolean.
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 ...
void ReadExternname(XclImpStream &rStrm, ExcelToSc *pFormulaConv)
Reads an EXTERNNAME record and appends it to the current SUPBOOK.
const SCTAB SCTAB_INVALID
An invalid Excel sheet index, for common use.
bool GetScTabRange(SCTAB &rnFirstScTab, SCTAB &rnLastScTab, sal_uInt16 nXtiIndex) const
Returns the Calc sheet index range of the specified XTI entry.
void ReadXct(XclImpStream &rStrm)
Reads an XCT record and appends it to the current SUPBOOK.
SC_DLLPUBLIC ScExternalRefManager * GetExternalRefManager() const
::boost::intrusive_ptr< ScMatrix > ScMatrixRef
void CreateDdeData(ScDocument &rDoc, const OUString &rApplc, const OUString &rExtDoc) const
Create and apply the cached list of this DDE Link to the document.
SUPBOOK contains add-in functions.
void ReadSupbook(XclImpStream &rStrm)
Reads a SUPBOOK record.
void ReadCrn(XclImpStream &rStrm)
Reads a CRN record (external referenced cell).
SUPBOOK is used for external references.
XclImpLinkManager(const XclImpRoot &rRoot)
const sal_uInt16 EXC_SUPB_SELF
virtual void ConvertExternName(std::unique_ptr< ScTokenArray > &rpArray, XclImpStream &rStrm, std::size_t nFormulaLen, const OUString &rUrl, const ::std::vector< OUString > &rTabNames)
static SC_DLLPUBLIC OUString GetAbsDocName(const OUString &rFileName, const SfxObjectShell *pShell)
sal_uInt16 GetCurrentIndex(sal_uInt16 nCreatedId, sal_uInt16 nMaxTabId) const
Returns the current sheet index calculated from creation index.
MS Excel 5.0, MS Excel 7.0 (95)
void ReadExternname(XclImpStream &rStrm, ExcelToSc *pFormulaConv)
Reads an EXTERNNAME record and appends it to the current SUPBOOK.
bool GetLinkData(OUString &rApplic, OUString &rDoc) const
Tries to decode the URL to OLE or DDE link components.
const OUString & GetTabName(sal_uInt16 nXtiTab) const
ScExtDocOptions & GetExtDocOptions() const
Returns the extended document options.
bool IsSelfRef(sal_uInt16 nXtiIndex) const
Returns true, if the specified XTI entry contains an internal reference.
void GetDimensions(SCSIZE &rC, SCSIZE &rR) const
Stores contents of an external name.
bool HasFormulaTokens() const
const XclImpXti * GetXti(sal_uInt16 nXtiIndex) const
Returns the specified XTI (link entry from BIFF8 EXTERNSHEET record).
svl::SharedStringPool & GetSharedStringPool()
const sal_uInt8 EXC_CACHEDVAL_BOOL
void InsertScTab(SCTAB nScTab)
Inserts a Calc sheet index (increases all following sheet indexes).
sal_uInt32 mnStorageId
The name of the external name.
XclImpStream & operator>>(XclImpStream &rStrm, XclImpDffPropSet &rPropSet)
Contains cached values in a 2-dimensional array.
ScExternalRefCache::TableTypeRef getCacheTable(sal_uInt16 nFileId, size_t nTabIndex) const
Get a cache table instance for specified table and table index.
std::vector< std::unique_ptr< XclImpSupbook > > maSupbookList
List of all XTI structures.
XclImpNameManager & GetNameManager() const
Returns the buffer that contains internal defined names.
A 2D cell address struct with Excel column and row indexes.
const OUString & GetSupbookTabName(sal_uInt16 nXti, sal_uInt16 nXtiTab) const
std::unique_ptr< MOper > mpMOper
Cached results of the DDE link.
void EnableDecryption(bool bEnable=true)
Switches usage of current decryption algorithm on/off.
std::vector< XclImpXti > XclImpXtiVector
const XclImpExtName * GetExternName(sal_uInt16 nXtiIndex, sal_uInt16 nExtName) const
Returns the specified external name or 0 on error.
XclSupbookType GetType() const
Returns the SUPBOOK record type.
unknown SUPBOOK record type.
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. ...
XclImpLinkMgrImplPtr mxImpl
const svl::SharedString & GetString() const
Only valid if ScMatrix methods indicate so!
const sal_uInt8 EXC_CACHEDVAL_DOUBLE
virtual ~XclImpLinkManager() override
const XclImpRoot & GetRoot() const
Returns the filter root data.
::formula::FormulaTokenRef TokenRef
std::size_t GetRecLeft()
Returns remaining data size of the whole record without record headers.
OUString maName
Formula tokens for external name.
OUString ReadUniString(sal_uInt16 nChars, sal_uInt8 nFlags)
Reads ext.
const OUString & GetMacroName(sal_uInt16 nXclNameIdx) const
Returns the specified macro name (1-based) or an empty string on error.
bool CreateOleData(const ScDocument &rDoc, const OUString &rUrl, sal_uInt16 &rFileId, OUString &rTabName, ScRange &rRange) const
Create OLE link data.
XclSupbookType meType
URL of the external document (Excel mode).
void ReadSupbook(XclImpStream &rStrm)
Reads a SUPBOOK record.
const sal_uInt8 EXC_CACHEDVAL_STRING
void Ignore(std::size_t nBytes)
Seeks forward inside the current record.
std::shared_ptr< Table > TableTypeRef
const OUString & GetXclUrl() const
Returns the URL of the external document.
std::vector< std::unique_ptr< XclImpExtName > > maExtNameList
All sheet names of the document.
XclBiff GetBiff() const
Returns the current BIFF version of the importer/exporter.
const sal_uInt16 EXC_TAB_DELETED
Special sheet index for external links.
const sal_uInt16 EXC_EXTN_OLE
const OUString * GetSupbookUrl(sal_uInt16 nXtiIndex) const
XclImpExtName(XclImpSupbook &rSupbook, XclImpStream &rStrm, XclSupbookType eSubType, ExcelToSc *pFormulaConv)
Reads the external name from the stream.
const sal_uInt16 EXC_EXTN_BUILTIN
#define SAL_WARN(area, stream)
const XclImpExtName * GetExternName(sal_uInt16 nXtiIndex, sal_uInt16 nExtName) const
Returns the specified external name or 0 on error.
void(* f)(TrueTypeTable *)
SfxObjectShell * GetDocShell() const
Returns the object shell of the Calc document.
SCTAB GetScTabFromXclName(const OUString &rXclTabName) const
Returns the Calc sheet index from the passed original Excel sheet name.
bool GetScTabRange(SCTAB &rnFirstScTab, SCTAB &rnLastScTab, sal_uInt16 nXtiIndex) const
Returns the Calc sheet index range of the specified XTI entry.
This class is used to import record oriented streams.
TokenArrayPtr mxArray
Cached values for OLE link.
const OUString * GetSupbookUrl(sal_uInt16 nXtiIndex) const
Returns the absolute file URL of a supporting workbook specified by the index.
XclImpCachedMatrixPtr mxDdeMatrix
Implementation of the link manager.
bool IsSelfRef(sal_uInt16 nXtiIndex) const
Returns true, if the specified XTI entry contains an internal reference.
This class stores one cached value of a cached value list (used for instance in CRN, EXTERNNAME, tArray).
void CreateExtNameData(const ScDocument &rDoc, sal_uInt16 nFileId) const
sal_uInt16 mnSBTab
Type of the supbook record.
Access to global data from other classes.
XclSupbookType
This enumeration specifies the type of a SUPBOOK record.
void ReadCrn(XclImpStream &rStrm)
Reads a CRN record and appends it to the current SUPBOOK.
void ReadXct(XclImpStream &rStrm)
Reads an XCT record (count of following CRNs and current sheet).
ScfUInt16Vec maTabIdVec
All Excel sheet names with Calc sheet index.
Represents a defined name.
An external defined name.
const OUString & GetSupbookTabName(sal_uInt16 nXti, sal_uInt16 nXtiTab) const
OUString maXclUrl
All external names of the document.
void ReadCrn(XclImpStream &rStrm)
Reads a CRN record and appends it to the current SUPBOOK.
SUPBOOK is used for internal references.
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.