24 #include <oox/token/namespaces.hxx>
29 #include <document.hxx>
32 #include <tokenarray.hxx>
41 #include <string_view>
43 using ::std::unique_ptr;
45 using ::com::sun::star::uno::Any;
61 explicit XclExpExtNameBase(
const XclExpRoot& rRoot,
62 const OUString& rName, sal_uInt16 nFlags = 0 );
65 const OUString& GetName()
const {
return maName; }
81 class XclExpExtNameAddIn :
public XclExpExtNameBase
84 explicit XclExpExtNameAddIn(
const XclExpRoot& rRoot,
const OUString& rName );
88 virtual void WriteAddData(
XclExpStream& rStrm )
override;
92 class XclExpExtNameDde :
public XclExpExtNameBase
95 explicit XclExpExtNameDde(
const XclExpRoot& rRoot,
const OUString& rName,
96 sal_uInt16 nFlags,
const ScMatrix* pResults =
nullptr );
100 virtual void WriteAddData(
XclExpStream& rStrm )
override;
103 typedef std::shared_ptr< XclExpCachedMatrix > XclExpCachedMatRef;
104 XclExpCachedMatRef mxMatrix;
109 class XclExpExtName :
public XclExpExtNameBase
112 explicit XclExpExtName(
const XclExpRoot& rRoot,
const XclExpSupbook& rSupbook,
const OUString& rName,
119 virtual void WriteAddData(
XclExpStream& rStrm )
override;
122 const XclExpSupbook& mrSupbook;
123 unique_ptr<ScTokenArray>
mpArray;
132 explicit XclExpExtNameBuffer(
const XclExpRoot& rRoot );
136 sal_uInt16 InsertAddIn(
const OUString& rName );
138 sal_uInt16 InsertEuroTool(
const OUString& rName );
141 sal_uInt16 InsertDde( std::u16string_view rApplic, std::u16string_view rTopic,
const OUString& rItem );
152 sal_uInt16 GetIndex( std::u16string_view rName )
const;
155 sal_uInt16 AppendNew( XclExpExtNameBase* pExtName );
166 explicit XclExpCrn(
SCCOL nScCol,
SCROW nScRow,
const Any& rValue );
169 bool InsertValue(
SCCOL nScCol,
SCROW nScRow,
const Any& rValue );
177 static void WriteBool(
XclExpStream& rStrm,
bool bValue );
178 static void WriteDouble(
XclExpStream& rStrm,
double fValue );
179 static void WriteString(
XclExpStream& rStrm,
const OUString& rValue );
184 typedef ::std::vector< Any > CachedValues;
199 const OUString& rTabName, sal_uInt16 nSBTab,
203 const XclExpString& GetTabName()
const {
return maTabName; }
206 void StoreCellRange(
const ScRange& rRange );
208 void StoreCell_(
const ScAddress& rCell );
209 void StoreCellRange_(
const ScRange& rRange );
225 bool BuildCrnList( XclExpCrnList& rCrnRecs );
240 explicit XclExpExternSheetBase(
const XclExpRoot& rRoot,
241 sal_uInt16 nRecId, sal_uInt32 nRecSize = 0 );
245 XclExpExtNameBuffer& GetExtNameBuffer();
252 typedef std::shared_ptr< XclExpExtNameBuffer > XclExpExtNameBfrRef;
253 XclExpExtNameBfrRef mxExtNameBfr;
261 class XclExpExternSheet :
public XclExpExternSheetBase
267 explicit XclExpExternSheet(
const XclExpRoot& rRoot, std::u16string_view rTabName );
271 sal_uInt16 InsertAddIn(
const OUString& rName );
278 void Init( std::u16string_view rEncUrl );
289 class XclExpSupbook :
public XclExpExternSheetBase
293 explicit XclExpSupbook(
const XclExpRoot& rRoot, sal_uInt16 nXclTabCount );
295 explicit XclExpSupbook(
const XclExpRoot& rRoot );
299 explicit XclExpSupbook(
const XclExpRoot& rRoot,
const OUString& rUrl );
301 explicit XclExpSupbook(
const XclExpRoot& rRoot,
const OUString& rApplic,
const OUString& rTopic );
304 bool IsUrlLink( std::u16string_view rUrl )
const;
306 bool IsDdeLink( std::u16string_view rApplic, std::u16string_view rTopic )
const;
309 sal_uInt16 nFirstSBTab, sal_uInt16 nLastSBTab )
const;
312 void StoreCellRange(
const ScRange& rRange, sal_uInt16 nSBTab );
314 void StoreCell_( sal_uInt16 nSBTab,
const ScAddress& rCell );
315 void StoreCellRange_( sal_uInt16 nSBTab,
const ScRange& rRange );
317 sal_uInt16 GetTabIndex(
const OUString& rTabName )
const;
318 sal_uInt16 GetTabCount()
const;
324 sal_uInt16 InsertAddIn(
const OUString& rName );
326 sal_uInt16 InsertEuroTool(
const OUString& rName );
329 sal_uInt16 InsertDde(
const OUString& rItem );
337 sal_uInt16 GetFileId()
const;
340 const OUString& GetUrl()
const;
350 const XclExpString* GetTabName( sal_uInt16 nSBTab )
const;
357 typedef XclExpXctList::RecordRefType XclExpXctRef;
359 XclExpXctList maXctList;
364 sal_uInt16 mnXclTabCount;
375 sal_uInt16 mnSupbook;
376 sal_uInt16 mnFirstSBTab;
377 sal_uInt16 mnLastSBTab;
379 explicit XclExpXti() : mnSupbook( 0 ), mnFirstSBTab( 0 ), mnLastSBTab( 0 ) {}
380 explicit XclExpXti( sal_uInt16 nSupbook, sal_uInt16 nFirstSBTab, sal_uInt16 nLastSBTab ) :
381 mnSupbook( nSupbook ), mnFirstSBTab( nFirstSBTab ), mnLastSBTab( nLastSBTab ) {}
385 { rStrm << mnSupbook << mnFirstSBTab << mnLastSBTab; }
388 bool operator==(
const XclExpXti& rLeft,
const XclExpXti& rRight )
391 (rLeft.mnSupbook == rRight.mnSupbook) &&
392 (rLeft.mnFirstSBTab == rRight.mnFirstSBTab) &&
393 (rLeft.mnLastSBTab == rRight.mnLastSBTab);
400 explicit XclExpSupbookBuffer(
const XclExpRoot& rRoot );
404 XclExpXti GetXti( sal_uInt16 nFirstXclTab, sal_uInt16 nLastXclTab,
408 void StoreCellRange(
const ScRange& rRange );
410 void StoreCell( sal_uInt16 nFileId,
const OUString& rTabName,
const ScAddress& rCell );
411 void StoreCellRange( sal_uInt16 nFileId,
const OUString& rTabName,
const ScRange& rRange );
417 sal_uInt16& rnSupbook, sal_uInt16& rnExtName,
418 const OUString& rName );
421 sal_uInt16& rnSupbook, sal_uInt16& rnExtName,
422 const OUString& rName );
427 sal_uInt16& rnSupbook, sal_uInt16& rnExtName,
428 const OUString& rApplic,
const OUString& rTopic,
const OUString& rItem );
431 sal_uInt16& rnSupbook, sal_uInt16& rnExtName,
const OUString& rUrl,
434 XclExpXti GetXti( sal_uInt16 nFileId,
const OUString& rTabName, sal_uInt16 nXclTabSpan,
444 bool HasExternalReferences()
const;
448 sal_uInt16 mnSupbook;
450 void Set( sal_uInt16 nSupbook, sal_uInt16 nSBTab )
451 { mnSupbook = nSupbook; mnSBTab = nSBTab; }
456 typedef XclExpSupbookList::RecordRefType XclExpSupbookRef;
463 bool GetSupbookUrl( XclExpSupbookRef& rxSupbook, sal_uInt16& rnIndex,
464 std::u16string_view rUrl )
const;
469 bool GetSupbookDde( XclExpSupbookRef& rxSupbook, sal_uInt16& rnIndex,
470 std::u16string_view rApplic, std::u16string_view rTopic )
const;
474 sal_uInt16
Append( XclExpSupbookRef
const & xSupbook );
477 XclExpSupbookList maSupbookList;
478 std::vector< XclExpSBIndex >
480 sal_uInt16 mnOwnDocSB;
481 sal_uInt16 mnAddInSB;
493 virtual void FindExtSheet( sal_uInt16& rnExtSheet,
494 sal_uInt16& rnFirstXclTab, sal_uInt16& rnLastXclTab,
498 virtual sal_uInt16 FindExtSheet(
sal_Unicode cCode ) = 0;
500 virtual void FindExtSheet( sal_uInt16 nFileId,
const OUString& rTabName, sal_uInt16 nXclTabSpan,
501 sal_uInt16& rnExtSheet, sal_uInt16& rnFirstSBTab, sal_uInt16& rnLastSBTab,
507 virtual void StoreCell( sal_uInt16 nFileId,
const OUString& rTabName,
const ScAddress& rPos ) = 0;
508 virtual void StoreCellRange( sal_uInt16 nFileId,
const OUString& rTabName,
const ScRange& rRange ) = 0;
511 virtual bool InsertAddIn(
512 sal_uInt16& rnExtSheet, sal_uInt16& rnExtName,
513 const OUString& rName ) = 0;
515 virtual bool InsertEuroTool(
516 sal_uInt16& rnExtSheet, sal_uInt16& rnExtName,
517 const OUString& rName ) = 0;
520 virtual bool InsertDde(
521 sal_uInt16& rnExtSheet, sal_uInt16& rnExtName,
522 const OUString& rApplic,
const OUString& rTopic,
const OUString& rItem ) = 0;
524 virtual bool InsertExtName(
525 sal_uInt16& rnExtSheet, sal_uInt16& rnExtName,
const OUString& rUrl,
544 explicit XclExpLinkManagerImpl5(
const XclExpRoot& rRoot );
546 virtual void FindExtSheet( sal_uInt16& rnExtSheet,
547 sal_uInt16& rnFirstXclTab, sal_uInt16& rnLastXclTab,
550 virtual sal_uInt16 FindExtSheet(
sal_Unicode cCode )
override;
552 virtual void FindExtSheet( sal_uInt16 nFileId,
const OUString& rTabName, sal_uInt16 nXclTabSpan,
553 sal_uInt16& rnExtSheet, sal_uInt16& rnFirstSBTab, sal_uInt16& rnLastSBTab,
558 virtual void StoreCell( sal_uInt16 nFileId,
const OUString& rTabName,
const ScAddress& rPos )
override;
559 virtual void StoreCellRange( sal_uInt16 nFileId,
const OUString& rTabName,
const ScRange& rRange )
override;
561 virtual bool InsertAddIn(
562 sal_uInt16& rnExtSheet, sal_uInt16& rnExtName,
563 const OUString& rName )
override;
566 virtual bool InsertEuroTool(
567 sal_uInt16& rnExtSheet, sal_uInt16& rnExtName,
568 const OUString& rName )
override;
570 virtual bool InsertDde(
571 sal_uInt16& rnExtSheet, sal_uInt16& rnExtName,
572 const OUString& rApplic,
const OUString& rTopic,
const OUString& rItem )
override;
574 virtual bool InsertExtName(
575 sal_uInt16& rnExtSheet, sal_uInt16& rnExtName,
const OUString& rUrl,
584 typedef XclExpExtSheetList::RecordRefType XclExpExtSheetRef;
585 typedef ::std::map< SCTAB, sal_uInt16 > XclExpIntTabMap;
586 typedef ::std::map< sal_Unicode, sal_uInt16 > XclExpCodeMap;
590 sal_uInt16 GetExtSheetCount()
const;
593 sal_uInt16 AppendInternal( XclExpExtSheetRef
const & xExtSheet );
595 void CreateInternal();
598 XclExpExtSheetRef GetInternal( sal_uInt16 nExtSheet );
600 XclExpExtSheetRef FindInternal( sal_uInt16& rnExtSheet, sal_uInt16& rnXclTab,
SCTAB nScTab );
602 XclExpExtSheetRef FindInternal( sal_uInt16& rnExtSheet,
sal_Unicode cCode );
605 XclExpExtSheetList maExtSheetList;
606 XclExpIntTabMap maIntTabMap;
607 XclExpCodeMap maCodeMap;
614 explicit XclExpLinkManagerImpl8(
const XclExpRoot& rRoot );
616 virtual void FindExtSheet( sal_uInt16& rnExtSheet,
617 sal_uInt16& rnFirstXclTab, sal_uInt16& rnLastXclTab,
620 virtual sal_uInt16 FindExtSheet(
sal_Unicode cCode )
override;
622 virtual void FindExtSheet( sal_uInt16 nFileId,
const OUString& rTabName, sal_uInt16 nXclTabSpan,
623 sal_uInt16& rnExtSheet, sal_uInt16& rnFirstSBTab, sal_uInt16& rnLastSBTab,
628 virtual void StoreCell( sal_uInt16 nFileId,
const OUString& rTabName,
const ScAddress& rPos )
override;
629 virtual void StoreCellRange( sal_uInt16 nFileId,
const OUString& rTabName,
const ScRange& rRange )
override;
631 virtual bool InsertAddIn(
632 sal_uInt16& rnExtSheet, sal_uInt16& rnExtName,
633 const OUString& rName )
override;
635 virtual bool InsertEuroTool(
636 sal_uInt16& rnExtSheet, sal_uInt16& rnExtName,
637 const OUString& rName )
override;
639 virtual bool InsertDde(
640 sal_uInt16& rnExtSheet, sal_uInt16& rnExtName,
641 const OUString& rApplic,
const OUString& rTopic,
const OUString& rItem )
override;
643 virtual bool InsertExtName(
644 sal_uInt16& rnExtSheet, sal_uInt16& rnExtName,
const OUString& rUrl,
654 sal_uInt16 InsertXti(
const XclExpXti& rXti );
658 XclExpSupbookBuffer maSBBuffer;
659 std::vector< XclExpXti > maXtiVec;
676 mnFirstVisXclTab( 0 )
690 for( nScTab = 0; nScTab <
mnScCnt; ++nScTab )
712 nFirstExpScTab = nScTab;
715 nFirstVisScTab = nScTab;
734 if (nDisplScTab == -1 )
741 nFirstVisScTab = nFirstExpScTab;
745 nFirstVisScTab = nDisplScTab;
753 nDisplScTab = nFirstVisScTab;
757 for( nScTab = 0; nScTab <
mnScCnt; ++nScTab )
797 OSL_ENSURE( nScTab < mnScCnt && nScTab >= 0,
"XclExpTabInfo::IsActiveTab - sheet out of range" );
808 OSL_ENSURE( nScTab < mnScCnt && nScTab >= 0,
"XclExpTabInfo::IsActiveTab - sheet out of range" );
809 return (nScTab < mnScCnt && nScTab >= 0) ?
maTabInfoVec[ nScTab ].maScName : OUString();
819 OSL_ENSURE( nSortedScTab < mnScCnt && nSortedScTab >= 0,
"XclExpTabInfo::GetRealScTab - sheet out of range" );
825 OSL_ENSURE( nScTab < mnScCnt && nScTab >= 0,
"XclExpTabInfo::GetFlag - sheet out of range" );
826 return (nScTab < mnScCnt && nScTab >= 0) && (
maTabInfoVec[ nScTab ].mnFlags & nFlags);
831 OSL_ENSURE( nScTab < mnScCnt && nScTab >= 0,
"XclExpTabInfo::SetFlag - sheet out of range" );
832 if( nScTab < mnScCnt && nScTab >= 0 )
843 sal_uInt16 nXclTab = 0;
847 for( nScTab = 0; nScTab <
mnScCnt; ++nScTab )
860 for( nScTab = 0; nScTab <
mnScCnt; ++nScTab )
877 struct XclExpTabNameSort {
878 bool operator ()(
const XclExpTabName& rArg1,
const XclExpTabName& rArg2 )
890 ::std::vector< XclExpTabName > aVec(
mnScCnt );
894 for( nScTab = 0; nScTab <
mnScCnt; ++nScTab )
897 aVec[ nScTab ].second = nScTab;
899 ::std::sort( aVec.begin(), aVec.end(), XclExpTabNameSort() );
904 for( nScTab = 0; nScTab <
mnScCnt; ++nScTab )
913 XclExpExtNameBase::XclExpExtNameBase(
914 const XclExpRoot& rRoot,
const OUString& rName, sal_uInt16 nFlags ) :
921 OSL_ENSURE(
maName.getLength() <= 255,
"XclExpExtNameBase::XclExpExtNameBase - string too long" );
922 SetRecSize( 6 + mxName->GetSize() );
925 void XclExpExtNameBase::WriteBody(
XclExpStream& rStrm )
930 WriteAddData( rStrm );
937 XclExpExtNameAddIn::XclExpExtNameAddIn(
const XclExpRoot& rRoot,
const OUString& rName ) :
938 XclExpExtNameBase( rRoot, rName )
943 void XclExpExtNameAddIn::WriteAddData(
XclExpStream& rStrm )
949 XclExpExtNameDde::XclExpExtNameDde(
const XclExpRoot& rRoot,
950 const OUString& rName, sal_uInt16 nFlags,
const ScMatrix* pResults ) :
951 XclExpExtNameBase( rRoot, rName, nFlags )
955 mxMatrix = std::make_shared<XclExpCachedMatrix>( *pResults );
956 AddRecSize( mxMatrix->GetSize() );
960 void XclExpExtNameDde::WriteAddData(
XclExpStream& rStrm )
963 mxMatrix->Save( rStrm );
966 XclExpExtName::XclExpExtName(
const XclExpRoot& rRoot,
const XclExpSupbook& rSupbook,
968 XclExpExtNameBase( rRoot, rName ),
1000 sal_uInt16 nCol =
static_cast<sal_uInt16
>(rRef.
Col());
1001 sal_uInt16 nRow =
static_cast<sal_uInt16
>(rRef.
Row());
1002 if (bColRel) nCol |= 0x4000;
1003 if (bRowRel) nCol |= 0x8000;
1006 sal_uInt16 nSBTab = mrSupbook.GetTabIndex(aTabName);
1009 rStrm << static_cast<sal_uInt16>(9);
1011 rStrm << static_cast<sal_uInt8>(0x3A);
1013 rStrm << nSBTab << nSBTab << nRow << nCol;
1024 sal_uInt16 nTab1 = r1.
Tab();
1025 sal_uInt16 nTab2 = r2.
Tab();
1031 sal_uInt16 nCol1 =
static_cast<sal_uInt16
>(r1.
Col());
1032 sal_uInt16 nCol2 =
static_cast<sal_uInt16
>(r2.
Col());
1033 sal_uInt16 nRow1 =
static_cast<sal_uInt16
>(r1.
Row());
1034 sal_uInt16 nRow2 =
static_cast<sal_uInt16
>(r2.
Row());
1035 if (bCol1Rel) nCol1 |= 0x4000;
1036 if (bRow1Rel) nCol1 |= 0x8000;
1037 if (bCol2Rel) nCol2 |= 0x4000;
1038 if (bRow2Rel) nCol2 |= 0x8000;
1041 sal_uInt16 nSBTab = mrSupbook.GetTabIndex(aTabName);
1044 rStrm << static_cast<sal_uInt16>(13);
1046 rStrm << static_cast<sal_uInt8>(0x3B);
1048 sal_uInt16 nSBTab2 = nSBTab + nTab2 - nTab1;
1049 rStrm << nSBTab << nSBTab2 << nRow1 << nRow2 << nCol1 << nCol2;
1066 pExternalLink->startElement(XML_definedName,
1067 XML_name,
maName.toUtf8(),
1068 XML_refersTo,
nullptr,
1069 XML_sheetId,
nullptr);
1071 pExternalLink->endElement(XML_definedName);
1076 XclExpExtNameBuffer::XclExpExtNameBuffer(
const XclExpRoot& rRoot ) :
1081 sal_uInt16 XclExpExtNameBuffer::InsertAddIn(
const OUString& rName )
1083 sal_uInt16
nIndex = GetIndex( rName );
1084 return nIndex ? nIndex : AppendNew(
new XclExpExtNameAddIn( GetRoot(), rName ) );
1087 sal_uInt16 XclExpExtNameBuffer::InsertEuroTool(
const OUString& rName )
1089 sal_uInt16 nIndex = GetIndex( rName );
1090 return nIndex ? nIndex : AppendNew(
new XclExpExtNameBase( GetRoot(), rName ) );
1093 sal_uInt16 XclExpExtNameBuffer::InsertDde(
1094 std::u16string_view rApplic, std::u16string_view rTopic,
const OUString& rItem )
1096 sal_uInt16 nIndex = GetIndex( rItem );
1103 if( maNameList.IsEmpty() )
1104 AppendNew(
new XclExpExtNameDde(
1108 const ScMatrix* pScMatrix = GetDoc().GetDdeLinkResultMatrix( nPos );
1109 nIndex = AppendNew(
new XclExpExtNameDde( GetRoot(), rItem,
EXC_EXTN_EXPDDE, pScMatrix ) );
1115 sal_uInt16 XclExpExtNameBuffer::InsertExtName(
const XclExpSupbook& rSupbook,
1118 sal_uInt16 nIndex = GetIndex( rName );
1119 return nIndex ? nIndex : AppendNew(
new XclExpExtName( GetRoot(), rSupbook, rName, rArray ) );
1124 maNameList.Save( rStrm );
1129 maNameList.SaveXml(rStrm);
1132 sal_uInt16 XclExpExtNameBuffer::GetIndex( std::u16string_view rName )
const
1134 for(
size_t nPos = 0, nSize = maNameList.GetSize(); nPos < nSize; ++nPos )
1135 if( maNameList.GetRecord( nPos )->GetName() == rName )
1136 return static_cast< sal_uInt16 >( nPos + 1 );
1140 sal_uInt16 XclExpExtNameBuffer::AppendNew( XclExpExtNameBase* pExtName )
1142 size_t nSize = maNameList.GetSize();
1143 if( nSize < 0x7FFF )
1145 maNameList.AppendRecord( pExtName );
1146 return static_cast< sal_uInt16
>( nSize + 1 );
1153 XclExpCrn::XclExpCrn(
SCCOL nScCol,
SCROW nScRow,
const Any& rValue ) :
1161 bool XclExpCrn::InsertValue(
SCCOL nScCol,
SCROW nScRow,
const Any& rValue )
1163 if( (nScRow != mnScRow) || (nScCol != static_cast< SCCOL >( mnScCol +
maValues.size() )) )
1171 rStrm << static_cast< sal_uInt8 >( mnScCol +
maValues.size() - 1 )
1172 << static_cast< sal_uInt8 >( mnScCol )
1173 <<
static_cast< sal_uInt16
>( mnScRow );
1174 for(
const auto& rValue : maValues )
1176 if( rValue.has<
bool >() )
1177 WriteBool( rStrm, rValue.get<
bool >() );
1178 else if( rValue.has<
double >() )
1179 WriteDouble( rStrm, rValue.get<
double >() );
1180 else if( rValue.has< OUString >() )
1181 WriteString( rStrm, rValue.get< OUString >() );
1183 WriteEmpty( rStrm );
1187 void XclExpCrn::WriteBool(
XclExpStream& rStrm,
bool bValue )
1193 void XclExpCrn::WriteDouble(
XclExpStream& rStrm,
double fValue )
1195 if( !std::isfinite( fValue ) )
1206 void XclExpCrn::WriteString(
XclExpStream& rStrm,
const OUString& rValue )
1227 pFS->startElement(XML_row, XML_r, OString::number(mnScRow + 1));
1230 for(
const auto& rValue : maValues )
1232 bool bCloseCell =
true;
1233 if( rValue.has<
double >() )
1235 double fVal = rValue.get<
double >();
1236 if (std::isfinite( fVal))
1240 pFS->startElement(XML_v);
1246 pFS->startElement(XML_v);
1247 pFS->write(
"#VALUE!" );
1250 else if( rValue.has< OUString >() )
1253 pFS->startElement(XML_v);
1254 pFS->write( rValue.get< OUString >() );
1256 else if( rValue.has<
bool >() )
1259 pFS->startElement(XML_v);
1260 pFS->write( rValue.get<
bool >() ?
"1" :
"0" );
1270 pFS->endElement(XML_v);
1271 pFS->endElement(XML_cell);
1276 pFS->endElement( XML_row);
1281 XclExpXct::XclExpXct(
const XclExpRoot& rRoot,
const OUString& rTabName,
1284 mxCacheTable( xCacheTable ),
1285 maUsedCells( rRoot.GetDoc().GetSheetLimits() ),
1286 maBoundRange(
ScAddress::INITIALIZE_INVALID ),
1287 maTabName( rTabName ),
1292 void XclExpXct::StoreCellRange(
const ScRange& rRange )
1298 maUsedCells.SetMultiMarkArea( rRange );
1299 maBoundRange.ExtendTo( rRange );
1302 void XclExpXct::StoreCell_(
const ScAddress& rCell )
1304 maUsedCells.SetMultiMarkArea(
ScRange( rCell ) );
1305 maBoundRange.ExtendTo(
ScRange( rCell ) );
1308 void XclExpXct::StoreCellRange_(
const ScRange& rRange )
1310 maUsedCells.SetMultiMarkArea( rRange );
1311 maBoundRange.ExtendTo( rRange );
1321 bool InsertValue(
SCCOL nScCol,
SCROW nScRow,
const Any& rValue );
1324 bool XclExpCrnList::InsertValue(
SCCOL nScCol,
SCROW nScRow,
const Any& rValue )
1326 RecordRefType xLastRec = GetLastRecord();
1327 if( xLastRec && xLastRec->InsertValue( nScCol, nScRow, rValue ) )
1331 AppendNewRecord(
new XclExpCrn( nScCol, nScRow, rValue ) );
1337 bool XclExpXct::BuildCrnList( XclExpCrnList& rCrnRecs )
1346 ::std::pair< SCROW, SCROW > aRowRange = mxCacheTable->getRowRange();
1347 if( aRowRange.first >= aRowRange.second )
1352 if( !GetAddressConverter().ValidateRange( maBoundRange,
false ) )
1356 SCROW nScRow1 = ::std::max( aRowRange.first, maBoundRange.aStart.Row() );
1357 SCROW nScRow2 = ::std::min( aRowRange.second - 1, maBoundRange.aEnd.Row() );
1358 if( nScRow1 > nScRow2 )
1367 for(
SCROW nScRow = nScRow1; bValid && (nScRow <= nScRow2); ++nScRow )
1369 ::std::pair< SCCOL, SCCOL > aColRange = mxCacheTable->getColRange( nScRow );
1371 for(
SCCOL nScCol = aColRange.first; bValid && (nScCol < nScEnd); ++nScCol )
1373 if( maUsedCells.IsCellMarked( nScCol, nScRow,
true ) )
1375 sal_uInt32 nScNumFmt = 0;
1379 switch( xToken->GetType() )
1382 bValid = (rFormatter.
GetType( nScNumFmt ) == SvNumFormatType::LOGICAL) ?
1383 rCrnRecs.InsertValue( nScCol, nScRow,
Any( xToken->GetDouble() != 0 ) ) :
1384 rCrnRecs.InsertValue( nScCol, nScRow,
Any( xToken->GetDouble() ) );
1388 if( !xToken->GetString().isEmpty() )
1389 bValid = rCrnRecs.InsertValue( nScCol, nScRow,
Any( xToken->GetString().getString() ) );
1402 XclExpCrnList aCrnRecs;
1403 if (!BuildCrnList( aCrnRecs))
1408 rStrm << static_cast< sal_uInt16 >( aCrnRecs.GetSize() ) << mnSBTab;
1410 aCrnRecs.Save( rStrm );
1415 XclExpCrnList aCrnRecs;
1419 bool bValid = BuildCrnList( aCrnRecs);
1420 pFS->startElement(XML_sheetData, XML_sheetId, OString::number(mnSBTab));
1424 aCrnRecs.SaveXml( rStrm );
1426 pFS->endElement( XML_sheetData);
1431 XclExpExternSheetBase::XclExpExternSheetBase(
const XclExpRoot& rRoot, sal_uInt16 nRecId, sal_uInt32 nRecSize ) :
1437 XclExpExtNameBuffer& XclExpExternSheetBase::GetExtNameBuffer()
1440 mxExtNameBfr = std::make_shared<XclExpExtNameBuffer>( GetRoot() );
1441 return *mxExtNameBfr;
1444 void XclExpExternSheetBase::WriteExtNameBuffer(
XclExpStream& rStrm )
1447 mxExtNameBfr->Save( rStrm );
1450 void XclExpExternSheetBase::WriteExtNameBufferXml(
XclExpXmlStream& rStrm )
1453 mxExtNameBfr->SaveXml( rStrm );
1461 Init( OUStringChar(cCode) );
1464 XclExpExternSheet::XclExpExternSheet(
const XclExpRoot& rRoot, std::u16string_view rTabName ) :
1476 WriteExtNameBuffer( rStrm );
1479 void XclExpExternSheet::Init( std::u16string_view rEncUrl )
1483 SetRecSize( maTabName.GetSize() );
1486 sal_uInt16 XclExpExternSheet::InsertAddIn(
const OUString& rName )
1488 return GetExtNameBuffer().InsertAddIn( rName );
1491 void XclExpExternSheet::WriteBody(
XclExpStream& rStrm )
1498 maTabName.WriteBuffer( rStrm );
1503 XclExpSupbook::XclExpSupbook(
const XclExpRoot& rRoot, sal_uInt16 nXclTabCount ) :
1506 mnXclTabCount( nXclTabCount ),
1511 XclExpSupbook::XclExpSupbook(
const XclExpRoot& rRoot ) :
1522 maUrlEncoded( rUrl ),
1527 SetRecSize( 2 + maUrlEncoded.GetSize() );
1530 XclExpSupbook::XclExpSupbook(
const XclExpRoot& rRoot,
const OUString& rUrl ) :
1538 SetRecSize( 2 + maUrlEncoded.GetSize() );
1543 mnFileId = nFileId + 1;
1545 pRefMgr->getAllCachedTableNames( nFileId, aTabNames );
1546 size_t nTabIndex = 0;
1547 for(
const auto& rTabName : aTabNames )
1549 InsertTabName( rTabName, pRefMgr->getCacheTable( nFileId, nTabIndex ) );
1554 XclExpSupbook::XclExpSupbook(
const XclExpRoot& rRoot,
const OUString& rApplic,
const OUString& rTopic ) :
1557 maDdeTopic( rTopic ),
1563 SetRecSize( 2 + maUrlEncoded.GetSize() );
1566 bool XclExpSupbook::IsUrlLink( std::u16string_view rUrl )
const
1571 bool XclExpSupbook::IsDdeLink( std::u16string_view rApplic, std::u16string_view rTopic )
const
1577 sal_uInt16 nFirstSBTab, sal_uInt16 nLastSBTab )
const
1579 rRefLogEntry.
mpUrl = maUrlEncoded.
IsEmpty() ?
nullptr : &maUrlEncoded;
1580 rRefLogEntry.
mpFirstTab = GetTabName( nFirstSBTab );
1581 rRefLogEntry.
mpLastTab = GetTabName( nLastSBTab );
1584 void XclExpSupbook::StoreCellRange(
const ScRange& rRange, sal_uInt16 nSBTab )
1586 if( XclExpXct* pXct = maXctList.GetRecord( nSBTab ) )
1587 pXct->StoreCellRange( rRange );
1590 void XclExpSupbook::StoreCell_( sal_uInt16 nSBTab,
const ScAddress& rCell )
1592 if( XclExpXct* pXct = maXctList.GetRecord( nSBTab ) )
1593 pXct->StoreCell_( rCell );
1596 void XclExpSupbook::StoreCellRange_( sal_uInt16 nSBTab,
const ScRange& rRange )
1600 if( XclExpXct* pXct = maXctList.GetRecord( nSBTab ) )
1601 pXct->StoreCellRange_( rRange );
1604 sal_uInt16 XclExpSupbook::GetTabIndex(
const OUString& rTabName )
const
1607 size_t nSize = maXctList.GetSize();
1608 for (
size_t i = 0;
i < nSize; ++
i)
1610 XclExpXctRef aRec = maXctList.GetRecord(i);
1611 if (aXclName == aRec->GetTabName())
1612 return ulimit_cast<sal_uInt16>(i);
1617 sal_uInt16 XclExpSupbook::GetTabCount()
const
1619 return ulimit_cast<sal_uInt16>(maXctList.GetSize());
1625 sal_uInt16 nSBTab =
ulimit_cast< sal_uInt16 >( maXctList.GetSize() );
1626 XclExpXctRef xXct =
new XclExpXct( GetRoot(), rTabName, nSBTab, xCacheTable );
1627 AddRecSize( xXct->GetTabName().GetSize() );
1628 maXctList.AppendRecord( xXct );
1632 sal_uInt16 XclExpSupbook::InsertAddIn(
const OUString& rName )
1634 return GetExtNameBuffer().InsertAddIn( rName );
1637 sal_uInt16 XclExpSupbook::InsertEuroTool(
const OUString& rName )
1639 return GetExtNameBuffer().InsertEuroTool( rName );
1642 sal_uInt16 XclExpSupbook::InsertDde(
const OUString& rItem )
1644 return GetExtNameBuffer().InsertDde( maUrl, maDdeTopic, rItem );
1649 return GetExtNameBuffer().InsertExtName(*
this, rName, rArray);
1657 sal_uInt16 XclExpSupbook::GetFileId()
const
1662 const OUString& XclExpSupbook::GetUrl()
const
1672 maXctList.Save( rStrm );
1674 WriteExtNameBuffer( rStrm );
1682 sal_uInt16 nLevel = 0;
1688 while (nLevel-- > 0)
1689 sFile =
"../" + sFile;
1691 OUString
sId = rStrm.
addRelation( pExternalLink->getOutputStream(),
1694 pExternalLink->startElement( XML_externalLink,
1697 pExternalLink->startElement( XML_externalBook,
1699 FSNS(XML_r, XML_id), sId.toUtf8());
1701 if (!maXctList.IsEmpty())
1703 pExternalLink->startElement(XML_sheetNames);
1704 for (
size_t nPos = 0, nSize = maXctList.GetSize(); nPos < nSize; ++nPos)
1706 pExternalLink->singleElement(XML_sheetName,
1709 pExternalLink->endElement( XML_sheetNames);
1715 pExternalLink->startElement(XML_definedNames);
1717 WriteExtNameBufferXml( rStrm );
1718 pExternalLink->endElement(XML_definedNames);
1721 if (!maXctList.IsEmpty())
1723 pExternalLink->startElement(XML_sheetDataSet);
1726 maXctList.SaveXml( rStrm );
1728 pExternalLink->endElement( XML_sheetDataSet);
1731 pExternalLink->endElement( XML_externalBook);
1732 pExternalLink->endElement( XML_externalLink);
1735 const XclExpString* XclExpSupbook::GetTabName( sal_uInt16 nSBTab )
const
1737 XclExpXctRef xXct = maXctList.GetRecord( nSBTab );
1738 return xXct ? &xXct->GetTabName() :
nullptr;
1753 rStrm << nCount << maUrlEncoded;
1755 for(
size_t nPos = 0, nSize = maXctList.GetSize(); nPos < nSize; ++nPos )
1756 rStrm << maXctList.GetRecord( nPos )->GetTabName();
1763 SAL_WARN(
"sc.filter",
"Unhandled SUPBOOK type " << meType);
1769 XclExpSupbookBuffer::XclExpSupbookBuffer(
const XclExpRoot& rRoot ) :
1779 OSL_ENSURE( nCount > 0,
"XclExpSupbookBuffer::XclExpSupbookBuffer - no sheets to export" );
1782 maSBIndexVec.resize( nCount );
1785 XclExpSupbookRef xSupbook =
new XclExpSupbook(
GetRoot(), ::std::max( nXclCnt, nCodeCnt ) );
1786 mnOwnDocSB =
Append( xSupbook );
1787 for( sal_uInt16 nXclTab = 0; nXclTab < nXclCnt; ++nXclTab )
1788 maSBIndexVec[ nXclTab ].
Set( mnOwnDocSB, nXclTab );
1792 XclExpXti XclExpSupbookBuffer::GetXti( sal_uInt16 nFirstXclTab, sal_uInt16 nLastXclTab,
1796 size_t nSize = maSBIndexVec.size();
1797 if( (nFirstXclTab < nSize) && (nLastXclTab < nSize) )
1800 aXti.mnSupbook = maSBIndexVec[ nFirstXclTab ].mnSupbook;
1803 bool bSameSB =
true;
1804 for( sal_uInt16 nXclTab = nFirstXclTab + 1; bSameSB && (nXclTab <= nLastXclTab); ++nXclTab )
1806 bSameSB = maSBIndexVec[ nXclTab ].mnSupbook == aXti.mnSupbook;
1808 nLastXclTab = nXclTab - 1;
1810 aXti.mnFirstSBTab = maSBIndexVec[ nFirstXclTab ].mnSBTab;
1811 aXti.mnLastSBTab = maSBIndexVec[ nLastXclTab ].mnSBTab;
1818 XclExpSupbookRef xSupbook = maSupbookList.GetRecord( aXti.mnSupbook );
1820 xSupbook->FillRefLogEntry( *pRefLogEntry, aXti.mnFirstSBTab, aXti.mnLastSBTab );
1826 aXti.mnSupbook = mnOwnDocSB;
1827 aXti.mnFirstSBTab = nFirstXclTab;
1828 aXti.mnLastSBTab = nLastXclTab;
1834 void XclExpSupbookBuffer::StoreCellRange(
const ScRange& rRange )
1836 sal_uInt16 nXclTab = GetTabInfo().GetXclTab( rRange.
aStart.
Tab() );
1837 if( nXclTab < maSBIndexVec.size() )
1839 const XclExpSBIndex& rSBIndex = maSBIndexVec[ nXclTab ];
1840 XclExpSupbookRef xSupbook = maSupbookList.GetRecord( rSBIndex.mnSupbook );
1841 OSL_ENSURE( xSupbook ,
"XclExpSupbookBuffer::StoreCellRange - missing SUPBOOK record" );
1843 xSupbook->StoreCellRange( rRange, rSBIndex.mnSBTab );
1849 class FindSBIndexEntry
1852 explicit FindSBIndexEntry(sal_uInt16 nSupbookId, sal_uInt16 nTabId) :
1853 mnSupbookId(nSupbookId), mnTabId(nTabId) {}
1855 bool operator()(
const XclExpSupbookBuffer::XclExpSBIndex& r)
const
1857 return mnSupbookId == r.mnSupbook && mnTabId == r.mnSBTab;
1861 sal_uInt16 mnSupbookId;
1867 void XclExpSupbookBuffer::StoreCell( sal_uInt16 nFileId,
const OUString& rTabName,
const ScAddress& rCell )
1874 XclExpSupbookRef xSupbook;
1875 sal_uInt16 nSupbookId;
1876 if (!GetSupbookUrl(xSupbook, nSupbookId, *pUrl))
1878 xSupbook =
new XclExpSupbook(GetRoot(), *pUrl);
1879 nSupbookId =
Append(xSupbook);
1882 sal_uInt16 nSheetId = xSupbook->GetTabIndex(rTabName);
1887 FindSBIndexEntry
f(nSupbookId, nSheetId);
1888 if (::std::none_of(maSBIndexVec.begin(), maSBIndexVec.end(),
f))
1890 maSBIndexVec.emplace_back();
1891 XclExpSBIndex& r = maSBIndexVec.back();
1892 r.mnSupbook = nSupbookId;
1893 r.mnSBTab = nSheetId;
1896 xSupbook->StoreCell_(nSheetId, rCell);
1899 void XclExpSupbookBuffer::StoreCellRange( sal_uInt16 nFileId,
const OUString& rTabName,
const ScRange& rRange )
1906 XclExpSupbookRef xSupbook;
1907 sal_uInt16 nSupbookId;
1908 if (!GetSupbookUrl(xSupbook, nSupbookId, *pUrl))
1910 xSupbook =
new XclExpSupbook(GetRoot(), *pUrl);
1911 nSupbookId =
Append(xSupbook);
1918 SCTAB aMatrixListSize = 0;
1925 FormulaTokenArrayPlainIterator aIter(*pArray);
1926 for (FormulaToken* p = aIter.First(); p; p = aIter.Next())
1937 if (aMatrixListSize != nTabCount)
1943 sal_uInt16 nFirstSheetId = xSupbook->GetTabIndex(rTabName);
1946 aRange.aStart.SetTab(0);
1947 aRange.aEnd.SetTab(0);
1948 for (
SCTAB nTab = 0; nTab < nTabCount; ++nTab)
1950 sal_uInt16 nSheetId = nFirstSheetId +
static_cast<sal_uInt16
>(nTab);
1951 FindSBIndexEntry
f(nSupbookId, nSheetId);
1952 if (::std::none_of(maSBIndexVec.begin(), maSBIndexVec.end(),
f))
1954 maSBIndexVec.emplace_back();
1955 XclExpSBIndex& r = maSBIndexVec.back();
1956 r.mnSupbook = nSupbookId;
1957 r.mnSBTab = nSheetId;
1960 xSupbook->StoreCellRange_(nSheetId, aRange);
1964 bool XclExpSupbookBuffer::InsertAddIn(
1965 sal_uInt16& rnSupbook, sal_uInt16& rnExtName,
const OUString& rName )
1967 XclExpSupbookRef xSupbook;
1968 if( mnAddInSB == SAL_MAX_UINT16 )
1970 xSupbook =
new XclExpSupbook( GetRoot() );
1971 mnAddInSB =
Append( xSupbook );
1974 xSupbook = maSupbookList.GetRecord( mnAddInSB );
1975 OSL_ENSURE( xSupbook,
"XclExpSupbookBuffer::InsertAddin - missing add-in supbook" );
1976 rnSupbook = mnAddInSB;
1977 rnExtName = xSupbook->InsertAddIn( rName );
1978 return rnExtName > 0;
1981 bool XclExpSupbookBuffer::InsertEuroTool(
1982 sal_uInt16& rnSupbook, sal_uInt16& rnExtName,
const OUString& rName )
1984 XclExpSupbookRef xSupbook;
1985 OUString aUrl(
"\001\010EUROTOOL.XLA" );
1986 if( !GetSupbookUrl( xSupbook, rnSupbook, aUrl ) )
1989 rnSupbook =
Append( xSupbook );
1991 rnExtName = xSupbook->InsertEuroTool( rName );
1992 return rnExtName > 0;
1995 bool XclExpSupbookBuffer::InsertDde(
1996 sal_uInt16& rnSupbook, sal_uInt16& rnExtName,
1997 const OUString& rApplic,
const OUString& rTopic,
const OUString& rItem )
1999 XclExpSupbookRef xSupbook;
2000 if( !GetSupbookDde( xSupbook, rnSupbook, rApplic, rTopic ) )
2002 xSupbook =
new XclExpSupbook( GetRoot(), rApplic, rTopic );
2003 rnSupbook =
Append( xSupbook );
2005 rnExtName = xSupbook->InsertDde( rItem );
2006 return rnExtName > 0;
2009 bool XclExpSupbookBuffer::InsertExtName(
2010 sal_uInt16& rnSupbook, sal_uInt16& rnExtName,
const OUString& rUrl,
2013 XclExpSupbookRef xSupbook;
2014 if (!GetSupbookUrl(xSupbook, rnSupbook, rUrl))
2016 xSupbook =
new XclExpSupbook(GetRoot(), rUrl);
2017 rnSupbook =
Append(xSupbook);
2019 rnExtName = xSupbook->InsertExtName(rName, rArray);
2020 return rnExtName > 0;
2023 XclExpXti XclExpSupbookBuffer::GetXti( sal_uInt16 nFileId,
const OUString& rTabName, sal_uInt16 nXclTabSpan,
2032 XclExpSupbookRef xSupbook;
2033 sal_uInt16 nSupbookId;
2034 if (!GetSupbookUrl(xSupbook, nSupbookId, *pUrl))
2036 xSupbook =
new XclExpSupbook(GetRoot(), *pUrl);
2037 nSupbookId =
Append(xSupbook);
2039 aXti.mnSupbook = nSupbookId;
2041 sal_uInt16 nFirstSheetId = xSupbook->GetTabIndex(rTabName);
2047 sal_uInt16 nSheetCount = xSupbook->GetTabCount();
2048 for (sal_uInt16 i = 0;
i < nXclTabSpan; ++
i)
2050 sal_uInt16 nSheetId = nFirstSheetId +
i;
2051 if (nSheetId >= nSheetCount)
2054 FindSBIndexEntry
f(nSupbookId, nSheetId);
2055 if (::std::none_of(maSBIndexVec.begin(), maSBIndexVec.end(),
f))
2057 maSBIndexVec.emplace_back();
2058 XclExpSBIndex& r = maSBIndexVec.back();
2059 r.mnSupbook = nSupbookId;
2060 r.mnSBTab = nSheetId;
2063 aXti.mnFirstSBTab = nSheetId;
2064 if (i == nXclTabSpan - 1)
2065 aXti.mnLastSBTab = nSheetId;
2073 xSupbook->FillRefLogEntry(*pRefLogEntry, aXti.mnFirstSBTab, aXti.mnLastSBTab);
2081 maSupbookList.Save( rStrm );
2089 vector<sal_uInt16> aExternFileIds;
2090 for (
size_t nPos = 0, nSize = maSupbookList.GetSize(); nPos < nSize; ++nPos)
2092 XclExpSupbookRef xRef(maSupbookList.GetRecord(nPos));
2096 aExternFileIds.push_back(xRef->GetFileId() - 1);
2098 if (aExternFileIds.size() > 0)
2101 ::std::map< sal_uInt16, OUString >
aMap;
2102 for (
size_t nPos = 0, nSize = maSupbookList.GetSize(); nPos < nSize; ++nPos)
2104 XclExpSupbookRef xRef( maSupbookList.GetRecord( nPos));
2108 sal_uInt16
nId = xRef->GetFileId();
2110 const OUString& rUrl = xRef->GetUrl();
2111 ::std::pair< ::std::map< sal_uInt16, OUString >::iterator,
bool > aInsert(
2112 aMap.insert( ::std::make_pair( nId, rUrl)));
2113 if (!aInsert.second)
2115 SAL_WARN(
"sc.filter",
"XclExpSupbookBuffer::SaveXml: file ID already used: " << nId <<
2116 " wanted for " << rUrl <<
" and is " << (*aInsert.first).second <<
2117 (rUrl == (*aInsert.first).second ?
" multiple Supbook not supported" :
""));
2125 "application/vnd.openxmlformats-officedocument.spreadsheetml.externalLink+xml",
2131 FSNS(XML_r, XML_id), sId.toUtf8() );
2135 xRef->SaveXml( rStrm );
2140 bool XclExpSupbookBuffer::HasExternalReferences()
const
2142 for (
size_t nPos = 0, nSize = maSupbookList.GetSize(); nPos < nSize; ++nPos)
2150 bool XclExpSupbookBuffer::GetSupbookUrl(
2151 XclExpSupbookRef& rxSupbook, sal_uInt16& rnIndex, std::u16string_view rUrl )
const
2153 for(
size_t nPos = 0, nSize = maSupbookList.GetSize(); nPos < nSize; ++nPos )
2155 rxSupbook = maSupbookList.GetRecord( nPos );
2156 if( rxSupbook->IsUrlLink( rUrl ) )
2165 bool XclExpSupbookBuffer::GetSupbookDde( XclExpSupbookRef& rxSupbook,
2166 sal_uInt16& rnIndex, std::u16string_view rApplic, std::u16string_view rTopic )
const
2168 for(
size_t nPos = 0, nSize = maSupbookList.GetSize(); nPos < nSize; ++nPos )
2170 rxSupbook = maSupbookList.GetRecord( nPos );
2171 if( rxSupbook->IsDdeLink( rApplic, rTopic ) )
2180 sal_uInt16 XclExpSupbookBuffer::Append( XclExpSupbookRef
const & xSupbook )
2182 maSupbookList.AppendRecord( xSupbook );
2183 return ulimit_cast< sal_uInt16 >( maSupbookList.GetSize() - 1 );
2193 XclExpLinkManagerImpl5::XclExpLinkManagerImpl5(
const XclExpRoot& rRoot ) :
2198 void XclExpLinkManagerImpl5::FindExtSheet(
2199 sal_uInt16& rnExtSheet, sal_uInt16& rnFirstXclTab, sal_uInt16& rnLastXclTab,
2202 FindInternal( rnExtSheet, rnFirstXclTab, nFirstScTab );
2203 if( (rnFirstXclTab ==
EXC_TAB_DELETED) || (nFirstScTab == nLastScTab) )
2205 rnLastXclTab = rnFirstXclTab;
2209 sal_uInt16 nDummyExtSheet;
2210 FindInternal( nDummyExtSheet, rnLastXclTab, nLastScTab );
2213 OSL_ENSURE( !pRefLogEntry,
"XclExpLinkManagerImpl5::FindExtSheet - fill reflog entry not implemented" );
2216 sal_uInt16 XclExpLinkManagerImpl5::FindExtSheet(
sal_Unicode cCode )
2218 sal_uInt16 nExtSheet;
2219 FindInternal( nExtSheet, cCode );
2223 void XclExpLinkManagerImpl5::FindExtSheet(
2224 sal_uInt16 ,
const OUString& , sal_uInt16 ,
2225 sal_uInt16& , sal_uInt16& , sal_uInt16& ,
2236 void XclExpLinkManagerImpl5::StoreCell( sal_uInt16 ,
const OUString& ,
const ScAddress& )
2241 void XclExpLinkManagerImpl5::StoreCellRange( sal_uInt16 ,
const OUString& ,
const ScRange& )
2246 bool XclExpLinkManagerImpl5::InsertAddIn(
2247 sal_uInt16& rnExtSheet, sal_uInt16& rnExtName,
const OUString& rName )
2249 XclExpExtSheetRef xExtSheet = FindInternal( rnExtSheet,
EXC_EXTSH_ADDIN );
2252 rnExtName = xExtSheet->InsertAddIn( rName );
2253 return rnExtName > 0;
2258 bool XclExpLinkManagerImpl5::InsertEuroTool(
2259 sal_uInt16& , sal_uInt16& ,
const OUString& )
2264 bool XclExpLinkManagerImpl5::InsertDde(
2265 sal_uInt16& , sal_uInt16& ,
2266 const OUString& ,
const OUString& ,
const OUString& )
2272 bool XclExpLinkManagerImpl5::InsertExtName(
2273 sal_uInt16& , sal_uInt16& ,
const OUString& ,
2280 void XclExpLinkManagerImpl5::Save(
XclExpStream& rStrm )
2282 if( sal_uInt16 nExtSheetCount = GetExtSheetCount() )
2287 maExtSheetList.Save( rStrm );
2296 sal_uInt16 XclExpLinkManagerImpl5::GetExtSheetCount()
const
2298 return static_cast< sal_uInt16
>( maExtSheetList.GetSize() );
2301 sal_uInt16 XclExpLinkManagerImpl5::AppendInternal( XclExpExtSheetRef
const & xExtSheet )
2303 if( GetExtSheetCount() < 0x7FFF )
2305 maExtSheetList.AppendRecord( xExtSheet );
2307 return static_cast< sal_uInt16
>( -GetExtSheetCount() );
2312 void XclExpLinkManagerImpl5::CreateInternal()
2314 if( !maIntTabMap.empty() )
2319 for(
SCTAB nScTab = 0, nScCnt = rTabInfo.
GetScTabCount(); nScTab < nScCnt; ++nScTab )
2323 XclExpExtSheetRef xRec;
2324 if( nScTab == GetCurrScTab() )
2327 xRec =
new XclExpExternSheet( GetRoot(), rTabInfo.
GetScTabName( nScTab ) );
2328 maIntTabMap[ nScTab ] = AppendInternal( xRec );
2335 return maExtSheetList.GetRecord( static_cast< sal_uInt16 >( -nExtSheet - 1 ) );
2339 sal_uInt16& rnExtSheet, sal_uInt16& rnXclTab,
SCTAB nScTab )
2345 XclExpExtSheetRef xExtSheet;
2346 XclExpIntTabMap::const_iterator aIt = maIntTabMap.find( nScTab );
2347 if( aIt == maIntTabMap.end() )
2354 rnExtSheet = aIt->second;
2355 xExtSheet = GetInternal( rnExtSheet );
2356 rnXclTab = GetTabInfo().GetXclTab( nScTab );
2364 XclExpExtSheetRef xExtSheet;
2365 XclExpCodeMap::const_iterator aIt = maCodeMap.find( cCode );
2366 if( aIt == maCodeMap.end() )
2368 xExtSheet =
new XclExpExternSheet( GetRoot(), cCode );
2369 rnExtSheet = maCodeMap[ cCode ] = AppendInternal( xExtSheet );
2373 rnExtSheet = aIt->second;
2374 xExtSheet = GetInternal( rnExtSheet );
2379 XclExpLinkManagerImpl8::XclExpLinkManagerImpl8(
const XclExpRoot& rRoot ) :
2385 void XclExpLinkManagerImpl8::FindExtSheet(
2386 sal_uInt16& rnExtSheet, sal_uInt16& rnFirstXclTab, sal_uInt16& rnLastXclTab,
2390 rnFirstXclTab = rTabInfo.
GetXclTab( nFirstScTab );
2391 rnLastXclTab = rTabInfo.
GetXclTab( nLastScTab );
2392 rnExtSheet = InsertXti( maSBBuffer.GetXti( rnFirstXclTab, rnLastXclTab, pRefLogEntry ) );
2395 sal_uInt16 XclExpLinkManagerImpl8::FindExtSheet(
sal_Unicode cCode )
2398 "XclExpLinkManagerImpl8::FindExtSheet - unknown externsheet code" );
2402 void XclExpLinkManagerImpl8::FindExtSheet(
2403 sal_uInt16 nFileId,
const OUString& rTabName, sal_uInt16 nXclTabSpan,
2404 sal_uInt16& rnExtSheet, sal_uInt16& rnFirstSBTab, sal_uInt16& rnLastSBTab,
2407 XclExpXti aXti = maSBBuffer.GetXti(nFileId, rTabName, nXclTabSpan, pRefLogEntry);
2408 rnExtSheet = InsertXti(aXti);
2409 rnFirstSBTab = aXti.mnFirstSBTab;
2410 rnLastSBTab = aXti.mnLastSBTab;
2424 for (
SCTAB nScTab = nFirstScTab; nScTab <= nLastScTab; ++nScTab)
2429 aRange.aEnd.SetTab( nScTab );
2430 maSBBuffer.StoreCellRange( aRange );
2435 void XclExpLinkManagerImpl8::StoreCell( sal_uInt16 nFileId,
const OUString& rTabName,
const ScAddress& rPos )
2437 maSBBuffer.StoreCell(nFileId, rTabName, rPos);
2440 void XclExpLinkManagerImpl8::StoreCellRange( sal_uInt16 nFileId,
const OUString& rTabName,
const ScRange& rRange )
2442 maSBBuffer.StoreCellRange(nFileId, rTabName, rRange);
2445 bool XclExpLinkManagerImpl8::InsertAddIn(
2446 sal_uInt16& rnExtSheet, sal_uInt16& rnExtName,
const OUString& rName )
2448 sal_uInt16 nSupbook;
2449 if( maSBBuffer.InsertAddIn( nSupbook, rnExtName, rName ) )
2457 bool XclExpLinkManagerImpl8::InsertEuroTool(
2458 sal_uInt16& rnExtSheet, sal_uInt16& rnExtName,
const OUString& rName )
2460 sal_uInt16 nSupbook;
2461 if( maSBBuffer.InsertEuroTool( nSupbook, rnExtName, rName ) )
2469 bool XclExpLinkManagerImpl8::InsertDde(
2470 sal_uInt16& rnExtSheet, sal_uInt16& rnExtName,
2471 const OUString& rApplic,
const OUString& rTopic,
const OUString& rItem )
2473 sal_uInt16 nSupbook;
2474 if( maSBBuffer.InsertDde( nSupbook, rnExtName, rApplic, rTopic, rItem ) )
2482 bool XclExpLinkManagerImpl8::InsertExtName( sal_uInt16& rnExtSheet, sal_uInt16& rnExtName,
2485 sal_uInt16 nSupbook;
2486 if( maSBBuffer.InsertExtName( nSupbook, rnExtName, rUrl, rName, rArray ) )
2494 void XclExpLinkManagerImpl8::Save(
XclExpStream& rStrm )
2496 if( maXtiVec.empty() )
2500 maSBBuffer.Save( rStrm );
2503 sal_uInt16 nCount =
ulimit_cast< sal_uInt16 >( maXtiVec.size() );
2507 for(
const auto& rXti : maXtiVec )
2514 if (maSBBuffer.HasExternalReferences())
2517 pWorkbook->startElement(XML_externalReferences);
2520 maSBBuffer.SaveXml( rStrm );
2522 pWorkbook->endElement( XML_externalReferences);
2527 if( !maXtiVec.empty() )
2529 for(
const auto& rXti : maXtiVec )
2530 rXti.SaveXml( rStrm );
2535 sal_uInt16 XclExpLinkManagerImpl8::InsertXti(
const XclExpXti& rXti )
2537 auto aIt = std::find(maXtiVec.begin(), maXtiVec.end(), rXti);
2538 if (aIt != maXtiVec.end())
2539 return ulimit_cast< sal_uInt16 >( std::distance(maXtiVec.begin(), aIt) );
2540 maXtiVec.push_back( rXti );
2541 return ulimit_cast< sal_uInt16 >( maXtiVec.size() - 1 );
2550 mxImpl = std::make_shared<XclExpLinkManagerImpl5>( rRoot );
2553 mxImpl = std::make_shared<XclExpLinkManagerImpl8>( rRoot );
2565 sal_uInt16& rnExtSheet, sal_uInt16& rnXclTab,
2568 mxImpl->FindExtSheet( rnExtSheet, rnXclTab, rnXclTab, nScTab, nScTab, pRefLogEntry );
2572 sal_uInt16& rnExtSheet, sal_uInt16& rnFirstXclTab, sal_uInt16& rnLastXclTab,
2575 mxImpl->FindExtSheet( rnExtSheet, rnFirstXclTab, rnLastXclTab, nFirstScTab, nLastScTab, pRefLogEntry );
2580 return mxImpl->FindExtSheet( cCode );
2584 sal_uInt16& rnExtSheet, sal_uInt16& rnFirstSBTab, sal_uInt16& rnLastSBTab,
2587 mxImpl->FindExtSheet( nFileId, rTabName, nXclTabSpan, rnExtSheet, rnFirstSBTab, rnLastSBTab, pRefLogEntry );
2592 mxImpl->StoreCellRange(rRef, rRef, rPos);
2602 mxImpl->StoreCell(nFileId, rTabName, rPos);
2607 mxImpl->StoreCellRange(nFileId, rTabName, rRange);
2611 sal_uInt16& rnExtSheet, sal_uInt16& rnExtName,
const OUString& rName )
2613 return mxImpl->InsertAddIn( rnExtSheet, rnExtName, rName );
2617 sal_uInt16& rnExtSheet, sal_uInt16& rnExtName,
const OUString& rName )
2619 return mxImpl->InsertEuroTool( rnExtSheet, rnExtName, rName );
2623 sal_uInt16& rnExtSheet, sal_uInt16& rnExtName,
2624 const OUString& rApplic,
const OUString& rTopic,
const OUString& rItem )
2626 return mxImpl->InsertDde( rnExtSheet, rnExtName, rApplic, rTopic, rItem );
2630 sal_uInt16& rnExtSheet, sal_uInt16& rnExtName,
const OUString& rUrl,
const OUString& rName,
2633 return mxImpl->InsertExtName(rnExtSheet, rnExtName, rUrl, rName, rArray);
2643 mxImpl->SaveXml( rStrm );
bool operator==(const XclFontData &rLeft, const XclFontData &rRight)
Matrix data type that can store values of mixed types.
This class stores an unformatted or formatted string for Excel export.
static OString ToOString(const Color &rColor)
const sal_uInt16 EXC_ID_EXTERNCOUNT
Deleted sheet in a 3D reference.
OUString getString() const
void CalcXclIndexes()
Searches for sheets not to be exported.
A list of Excel record objects.
bool IsSelectedTab(SCTAB nScTab) const
Returns true, if the specified Calc sheet is selected and will be exported.
todo: It should be possible to have MarkArrays for each table, in order to enable "search all" across...
SC_DLLPUBLIC ScLinkMode GetLinkMode(SCTAB nTab) const
sal_Int32 compareString(const OUString &s1, const OUString &s2) const
bool IsExportTab(SCTAB nScTab) const
Returns true, if the specified Calc sheet will be exported.
XclExpTabInfo(const XclExpRoot &rRoot)
Initializes the complete buffer from the current exported document.
const XclExpRoot & GetRoot() const
Returns the filter root data.
bool InsertEuroTool(sal_uInt16 &rnExtSheet, sal_uInt16 &rnExtName, const OUString &rName)
InsertEuroTool.
This class is used to export Excel record streams.
bool IsExternalTab(SCTAB nScTab) const
Returns true, if the specified Calc sheet is used to store external cell contents.
static OUString BuildFileName(sal_uInt16 &rnLevel, bool &rbRel, const OUString &rUrl, const XclExpRoot &rRoot, bool bEncoded)
Builds file name from the passed file URL.
SCTAB GetCodeNameCount() const
Single reference (one address) into the sheet.
XclStrFlags
Flags used to specify import/export mode of strings.
const sal_uInt16 EXC_EXTN_EXPDDE_STDDOC
ScAddress toAbs(const ScSheetLimits &rLimits, const ScAddress &rPos) const
bool IsVisibleTab(SCTAB nScTab) const
Returns true, if the specified Calc sheet is visible and will be exported.
const sal_Unicode EXC_EXTSH_OWNTAB
#define CREATE_OFFICEDOC_RELATION_TYPE(ascii)
Sheet will be skipped, if any flag is set.
OUString GetScTabName(SCTAB nScTab) const
Returns the Calc name of the specified sheet.
sal_uInt16 mnDisplXclTab
Count of selected and exported sheets.
static SC_DLLPUBLIC CollatorWrapper * GetCollator()
const ScExtDocSettings & GetDocSettings() const
sal_uInt16 mnFirstXclTab
Name of the last sheet.
sal_uInt16 mnXclCnt
Count of Calc sheets.
Extended options held by an ScDocument containing additional settings for filters.
sal_uInt16 getExternalFileId(const OUString &rFile)
std::vector< XclExpTabInfoEntry > maTabInfoVec
SUPBOOK is used for DDE or OLE links.
void FindExtSheet(sal_uInt16 &rnExtSheet, sal_uInt16 &rnXclTab, SCTAB nScTab, XclExpRefLogEntry *pRefLogEntry=nullptr)
Searches for an EXTERNSHEET index for the given Calc sheet.
const sal_uInt8 EXC_CACHEDVAL_ERROR
ScDocument & GetDoc() const
Returns reference to the destination document (import) or source document (export).
bool IsEmpty() const
Returns true, if the string is empty.
const sal_Unicode EXC_EXTSH_TABNAME
Sheet will be ignored completely.
const OUString * getExternalFileName(sal_uInt16 nFileId, bool bForceOriginal=false)
It returns a pointer to the name of the URI associated with a given external file ID...
HashMap_OWString_Interface aMap
const sal_uInt16 EXC_SUPB_ADDIN
virtual void SaveXml(XclExpXmlStream &rStrm) override
Writes the entire Link table to OOXML.
Access to global data from other classes.
OUString getNamespaceURL(sal_Int32 nNSID) const
SC_DLLPUBLIC SCTAB GetTableCount() const
const sal_Unicode EXC_EXTSH_ADDIN
const SCTAB SCTAB_INVALID
An invalid Excel sheet index, for common use.
ScTabVec maToSortedVec
Sorted Calc sheet index -> real Calc sheet index.
sal_uInt16 mnLastXclTab
Calc index of the first sheet.
void PushStream(sax_fastparser::FSHelperPtr const &aStream)
SC_DLLPUBLIC ScExternalRefManager * GetExternalRefManager() const
sal_uInt16 mnFirstVisXclTab
Displayed (active) sheet.
Base class for all Excel records.
const sal_uInt8 SC_DDE_IGNOREMODE
FormulaError GetDoubleErrorValue(double fVal)
bool GetFlag(SCTAB nScTab, ExcTabBufFlags nFlags) const
Returns true, if any of the passed flags is set for the specified Calc sheet.
SUPBOOK contains add-in functions.
const sal_uInt16 EXC_ID_XCT
for export
sax_fastparser::FSHelperPtr & GetCurrentStream()
OUString getRelationship(Relationship eRelationship)
void StoreCell(const ScSingleRefData &rRef, const ScAddress &rPos)
Stores the cell with the given address in a CRN record list.
const sal_uInt16 EXC_ID_EXTERNSHEET
const sal_uInt8 EXC_ERR_REF
void SetSliceSize(sal_uInt16 nSize)
Sets data slice length.
bool IsMirroredTab(SCTAB nScTab) const
Returns true, if the specified Calc sheet is displayed in right-to-left mode.
SUPBOOK is used for external references.
const sal_uInt16 EXC_SUPB_SELF
sal_uInt16 GetXclExtTabCount() const
Returns the number of external linked sheets.
const sal_uInt16 EXC_ID_EXTERNNAME
bool InsertAddIn(sal_uInt16 &rnExtSheet, sal_uInt16 &rnExtName, const OUString &rName)
Finds or inserts an EXTERNNAME record for an add-in function name.
sal_uInt16 GetXclTab(SCTAB nScTab) const
Returns the Excel sheet index for a given Calc sheet.
virtual void Save(XclExpStream &rStrm) override
Writes the entire Link table.
MS Excel 5.0, MS Excel 7.0 (95)
bool InsertDde(sal_uInt16 &rnExtSheet, sal_uInt16 &rnExtName, const OUString &rApplic, const OUString &rTopic, const OUString &rItem)
Finds or inserts an EXTERNNAME record for DDE links.
XclExpLinkMgrImplPtr mxImpl
sal_uInt16 mnXclSelCnt
Count of external link sheets.
Reference< XAnimationNode > Clone(const Reference< XAnimationNode > &xSourceNode, const SdPage *pSource, const SdPage *pTarget)
ScExtDocOptions & GetExtDocOptions() const
Returns the extended document options.
SCTAB mnScCnt
Array of Calc sheet index information.
const XclExpString * mpLastTab
Name of the first sheet.
const sal_uInt16 EXC_TAB_EXTERNAL
const XclExpString * mpFirstTab
URL of the document containing the first sheet.
void EndRecord()
Checks and corrects real record length.
Stores the correct Excel sheet index for each Calc sheet.
const sal_uInt8 EXC_CACHEDVAL_BOOL
XclExpTabInfo & GetTabInfo() const
Returns the buffer for Calc->Excel sheet index conversion.
XclExpLinkManager(const XclExpRoot &rRoot)
Abstract base class for implementation classes of the link manager.
void setSkipUnusedFileIds(std::vector< sal_uInt16 > &pExternFileIds)
Sheet is linked externally.
const ScExtTabSettings * GetTabSettings(SCTAB nTab) const
std::shared_ptr< FastSerializerHelper > FSHelperPtr
This class contains static methods to encode a file URL.
const sal_uInt8 EXC_CACHEDVAL_EMPTY
Extended settings for a sheet, used in import/export filters.
const XclExpRoot & GetRoot() const
Returns this root instance - for code readability in derived classes.
XclExpValueRecord< sal_uInt16 > XclExpUInt16Record
A record containing an unsigned 16-bit value.
unknown SUPBOOK record type.
static OUString GetStreamName(const char *sStreamDir, const char *sStream, sal_Int32 nId)
SCTAB GetScTabCount() const
Returns the number of Calc sheets.
const sal_uInt8 EXC_CACHEDVAL_DOUBLE
::formula::FormulaTokenRef TokenRef
OUString addRelation(const OUString &rType, const OUString &rTarget)
const sal_Unicode EXC_EXTSH_OWNDOC
bool InsertExtName(sal_uInt16 &rnExtSheet, sal_uInt16 &rnExtName, const OUString &rUrl, const OUString &rName, const ScExternalRefCache::TokenArrayRef &rArray)
void StoreCellRange(const ScComplexRefData &rRef, const ScAddress &rPos)
Stores all cells in the given range in a CRN record list.
SC_DLLPUBLIC bool IsScenario(SCTAB nTab) const
#define SAL_WARN_IF(condition, area, stream)
const sal_uInt8 EXC_CACHEDVAL_STRING
ScExternalRefCache::TokenArrayRef getDoubleRefTokens(sal_uInt16 nFileId, const OUString &rTabName, const ScRange &rRange, const ScAddress *pCurPos)
Get an array of tokens that consist of the specified external cell range.
sal_uInt16 GetXclTabCount() const
Returns the number of Excel sheets to be exported.
void CalcSortedIndexes()
Sorts the names of all tables and stores the indexes of the sorted indexes.
std::shared_ptr< ScTokenArray > TokenArrayRef
std::shared_ptr< Table > TableTypeRef
Always use UCS-2 characters (default: try to compress). BIFF8 only.
sax_fastparser::FSHelperPtr CreateOutputStream(const OUString &sFullStream, const OUString &sRelativeStream, const css::uno::Reference< css::io::XOutputStream > &xParentRelation, const char *sContentType, std::u16string_view sRelationshipType, OUString *pRelationshipId=nullptr)
const XclExpString * mpUrl
const sal_uInt16 EXC_NOTAB
XclBiff GetBiff() const
Returns the current BIFF version of the importer/exporter.
Log entry for external references in a formula, used i.e.
const sal_uInt16 EXC_TAB_DELETED
Special sheet index for external links.
::std::pair< OUString, SCTAB > XclExpTabName
constexpr sal_Int32 FSNS(sal_Int32 namespc, sal_Int32 element)
SC_DLLPUBLIC bool IsLayoutRTL(SCTAB nTab) const
Complex reference (a range) into the sheet.
void SetFlag(SCTAB nScTab, ExcTabBufFlags nFlags, bool bSet=true)
Sets or clears (depending on bSet) all passed flags for the specified Calc sheet. ...
This class provides methods to create an XclExpString.
void StartRecord(sal_uInt16 nRecId, std::size_t nRecSize)
Starts a new record: writes header data, stores calculated record size.
sal_uInt16 convertFileIdToUsedFileId(sal_uInt16 nFileId)
Reindex external file references to skip unused files, if skipping is enabled.
SC_DLLPUBLIC bool IsVisible(SCTAB nTab) const
#define SAL_WARN(area, stream)
const sal_uInt16 EXC_EXTN_EXPDDE
for export
void(* f)(TrueTypeTable *)
virtual ~XclExpLinkManager() override
std::shared_ptr< XclExpString > XclExpStringRef
sal_uInt16 mnXclExtCnt
Count of Excel sheets to be exported.
SCTAB GetVisibleTab() const
SCTAB GetRealScTab(SCTAB nSortedScTab) const
Returns the Calc sheet index of the nSortedTab-th entry in the sorted sheet names list...
const sal_uInt16 EXC_ID_SUPBOOK
constexpr OUStringLiteral first
virtual void Save(XclExpStream &rStrm) override
Writes the record header and calls WriteBody().
ScTabVec maFromSortedVec
First visible sheet.
XclSupbookType
This enumeration specifies the type of a SUPBOOK record.
const sal_uInt16 EXC_ID_CRN
XclExpLinkManagerImpl(const XclExpRoot &rRoot)
SC_DLLPUBLIC bool GetName(SCTAB nTab, OUString &rName) const
bool IsDisplayedTab(SCTAB nScTab) const
Returns true, if the specified Calc sheet is the displayed (active) sheet.
Base class for single records with any content.
SUPBOOK is used for internal references.
SCTAB mnDisplTab
Index of displayed sheet.
void WriteZeroBytes(std::size_t nBytes)
Writes a sequence of nBytes zero bytes (respects slice setting).