24 #include <oox/token/namespaces.hxx>
30 #include <document.hxx>
33 #include <tokenarray.hxx>
42 #include <string_view>
44 using ::std::unique_ptr;
46 using ::com::sun::star::uno::Any;
62 explicit XclExpExtNameBase(
const XclExpRoot& rRoot,
63 const OUString& rName, sal_uInt16 nFlags = 0 );
82 class XclExpExtNameAddIn :
public XclExpExtNameBase
85 explicit XclExpExtNameAddIn(
const XclExpRoot& rRoot,
const OUString& rName );
89 virtual void WriteAddData(
XclExpStream& rStrm )
override;
93 class XclExpExtNameDde :
public XclExpExtNameBase
96 explicit XclExpExtNameDde(
const XclExpRoot& rRoot,
const OUString& rName,
97 sal_uInt16 nFlags,
const ScMatrix* pResults =
nullptr );
101 virtual void WriteAddData(
XclExpStream& rStrm )
override;
104 typedef std::shared_ptr< XclExpCachedMatrix > XclExpCachedMatRef;
105 XclExpCachedMatRef mxMatrix;
110 class XclExpExtName :
public XclExpExtNameBase
113 explicit XclExpExtName(
const XclExpRoot& rRoot,
const XclExpSupbook& rSupbook,
const OUString& rName,
120 virtual void WriteAddData(
XclExpStream& rStrm )
override;
123 const XclExpSupbook& mrSupbook;
124 unique_ptr<ScTokenArray>
mpArray;
133 explicit XclExpExtNameBuffer(
const XclExpRoot& rRoot );
137 sal_uInt16 InsertAddIn(
const OUString& rName );
139 sal_uInt16 InsertEuroTool(
const OUString& rName );
142 sal_uInt16 InsertDde( std::u16string_view rApplic, std::u16string_view rTopic,
const OUString& rItem );
153 sal_uInt16 GetIndex( std::u16string_view rName )
const;
156 sal_uInt16 AppendNew( XclExpExtNameBase* pExtName );
167 explicit XclExpCrn(
SCCOL nScCol,
SCROW nScRow,
const Any& rValue );
170 bool InsertValue(
SCCOL nScCol,
SCROW nScRow,
const Any& rValue );
178 static void WriteBool(
XclExpStream& rStrm,
bool bValue );
179 static void WriteDouble(
XclExpStream& rStrm,
double fValue );
180 static void WriteString(
XclExpStream& rStrm,
const OUString& rValue );
185 typedef ::std::vector< Any > CachedValues;
200 const OUString& rTabName, sal_uInt16 nSBTab,
204 const XclExpString& GetTabName()
const {
return maTabName; }
207 void StoreCellRange(
const ScRange& rRange );
209 void StoreCell_(
const ScAddress& rCell );
210 void StoreCellRange_(
const ScRange& rRange );
226 bool BuildCrnList( XclExpCrnList& rCrnRecs );
241 explicit XclExpExternSheetBase(
const XclExpRoot& rRoot,
242 sal_uInt16 nRecId, sal_uInt32 nRecSize = 0 );
246 XclExpExtNameBuffer& GetExtNameBuffer();
253 typedef std::shared_ptr< XclExpExtNameBuffer > XclExpExtNameBfrRef;
254 XclExpExtNameBfrRef mxExtNameBfr;
262 class XclExpExternSheet :
public XclExpExternSheetBase
268 explicit XclExpExternSheet(
const XclExpRoot& rRoot, std::u16string_view rTabName );
272 sal_uInt16 InsertAddIn(
const OUString& rName );
279 void Init( std::u16string_view rEncUrl );
290 class XclExpSupbook :
public XclExpExternSheetBase
294 explicit XclExpSupbook(
const XclExpRoot& rRoot, sal_uInt16 nXclTabCount );
296 explicit XclExpSupbook(
const XclExpRoot& rRoot );
300 explicit XclExpSupbook(
const XclExpRoot& rRoot,
const OUString& rUrl );
302 explicit XclExpSupbook(
const XclExpRoot& rRoot,
const OUString& rApplic,
const OUString& rTopic );
305 bool IsUrlLink( std::u16string_view rUrl )
const;
307 bool IsDdeLink( std::u16string_view rApplic, std::u16string_view rTopic )
const;
310 sal_uInt16 nFirstSBTab, sal_uInt16 nLastSBTab )
const;
313 void StoreCellRange(
const ScRange& rRange, sal_uInt16 nSBTab );
315 void StoreCell_( sal_uInt16 nSBTab,
const ScAddress& rCell );
316 void StoreCellRange_( sal_uInt16 nSBTab,
const ScRange& rRange );
318 sal_uInt16 GetTabIndex(
const OUString& rTabName )
const;
319 sal_uInt16 GetTabCount()
const;
325 sal_uInt16 InsertAddIn(
const OUString& rName );
327 sal_uInt16 InsertEuroTool(
const OUString& rName );
330 sal_uInt16 InsertDde(
const OUString& rItem );
338 sal_uInt16 GetFileId()
const;
341 const OUString& GetUrl()
const;
351 const XclExpString* GetTabName( sal_uInt16 nSBTab )
const;
358 typedef XclExpXctList::RecordRefType XclExpXctRef;
360 XclExpXctList maXctList;
365 sal_uInt16 mnXclTabCount;
376 sal_uInt16 mnSupbook;
377 sal_uInt16 mnFirstSBTab;
378 sal_uInt16 mnLastSBTab;
380 explicit XclExpXti() : mnSupbook( 0 ), mnFirstSBTab( 0 ), mnLastSBTab( 0 ) {}
381 explicit XclExpXti( sal_uInt16 nSupbook, sal_uInt16 nFirstSBTab, sal_uInt16 nLastSBTab ) :
382 mnSupbook( nSupbook ), mnFirstSBTab( nFirstSBTab ), mnLastSBTab( nLastSBTab ) {}
386 { rStrm << mnSupbook << mnFirstSBTab << mnLastSBTab; }
389 bool operator==(
const XclExpXti& rLeft,
const XclExpXti& rRight )
392 (rLeft.mnSupbook == rRight.mnSupbook) &&
393 (rLeft.mnFirstSBTab == rRight.mnFirstSBTab) &&
394 (rLeft.mnLastSBTab == rRight.mnLastSBTab);
401 explicit XclExpSupbookBuffer(
const XclExpRoot& rRoot );
405 XclExpXti GetXti( sal_uInt16 nFirstXclTab, sal_uInt16 nLastXclTab,
409 void StoreCellRange(
const ScRange& rRange );
411 void StoreCell( sal_uInt16 nFileId,
const OUString& rTabName,
const ScAddress& rCell );
412 void StoreCellRange( sal_uInt16 nFileId,
const OUString& rTabName,
const ScRange& rRange );
418 sal_uInt16& rnSupbook, sal_uInt16& rnExtName,
419 const OUString& rName );
422 sal_uInt16& rnSupbook, sal_uInt16& rnExtName,
423 const OUString& rName );
428 sal_uInt16& rnSupbook, sal_uInt16& rnExtName,
429 const OUString& rApplic,
const OUString& rTopic,
const OUString& rItem );
432 sal_uInt16& rnSupbook, sal_uInt16& rnExtName,
const OUString& rUrl,
435 XclExpXti GetXti( sal_uInt16 nFileId,
const OUString& rTabName, sal_uInt16 nXclTabSpan,
445 bool HasExternalReferences()
const;
449 sal_uInt16 mnSupbook;
451 void Set( sal_uInt16 nSupbook, sal_uInt16 nSBTab )
452 { mnSupbook = nSupbook; mnSBTab = nSBTab; }
457 typedef XclExpSupbookList::RecordRefType XclExpSupbookRef;
464 bool GetSupbookUrl( XclExpSupbookRef& rxSupbook, sal_uInt16& rnIndex,
465 std::u16string_view rUrl )
const;
470 bool GetSupbookDde( XclExpSupbookRef& rxSupbook, sal_uInt16& rnIndex,
471 std::u16string_view rApplic, std::u16string_view rTopic )
const;
475 sal_uInt16
Append( XclExpSupbookRef
const & xSupbook );
478 XclExpSupbookList maSupbookList;
479 std::vector< XclExpSBIndex >
481 sal_uInt16 mnOwnDocSB;
482 sal_uInt16 mnAddInSB;
494 virtual void FindExtSheet( sal_uInt16& rnExtSheet,
495 sal_uInt16& rnFirstXclTab, sal_uInt16& rnLastXclTab,
499 virtual sal_uInt16 FindExtSheet(
sal_Unicode cCode ) = 0;
501 virtual void FindExtSheet( sal_uInt16 nFileId,
const OUString& rTabName, sal_uInt16 nXclTabSpan,
502 sal_uInt16& rnExtSheet, sal_uInt16& rnFirstSBTab, sal_uInt16& rnLastSBTab,
508 virtual void StoreCell( sal_uInt16 nFileId,
const OUString& rTabName,
const ScAddress& rPos ) = 0;
509 virtual void StoreCellRange( sal_uInt16 nFileId,
const OUString& rTabName,
const ScRange& rRange ) = 0;
512 virtual bool InsertAddIn(
513 sal_uInt16& rnExtSheet, sal_uInt16& rnExtName,
514 const OUString& rName ) = 0;
516 virtual bool InsertEuroTool(
517 sal_uInt16& rnExtSheet, sal_uInt16& rnExtName,
518 const OUString& rName ) = 0;
521 virtual bool InsertDde(
522 sal_uInt16& rnExtSheet, sal_uInt16& rnExtName,
523 const OUString& rApplic,
const OUString& rTopic,
const OUString& rItem ) = 0;
525 virtual bool InsertExtName(
526 sal_uInt16& rnExtSheet, sal_uInt16& rnExtName,
const OUString& rUrl,
545 explicit XclExpLinkManagerImpl5(
const XclExpRoot& rRoot );
547 virtual void FindExtSheet( sal_uInt16& rnExtSheet,
548 sal_uInt16& rnFirstXclTab, sal_uInt16& rnLastXclTab,
551 virtual sal_uInt16 FindExtSheet(
sal_Unicode cCode )
override;
553 virtual void FindExtSheet( sal_uInt16 nFileId,
const OUString& rTabName, sal_uInt16 nXclTabSpan,
554 sal_uInt16& rnExtSheet, sal_uInt16& rnFirstSBTab, sal_uInt16& rnLastSBTab,
559 virtual void StoreCell( sal_uInt16 nFileId,
const OUString& rTabName,
const ScAddress& rPos )
override;
560 virtual void StoreCellRange( sal_uInt16 nFileId,
const OUString& rTabName,
const ScRange& rRange )
override;
562 virtual bool InsertAddIn(
563 sal_uInt16& rnExtSheet, sal_uInt16& rnExtName,
564 const OUString& rName )
override;
567 virtual bool InsertEuroTool(
568 sal_uInt16& rnExtSheet, sal_uInt16& rnExtName,
569 const OUString& rName )
override;
571 virtual bool InsertDde(
572 sal_uInt16& rnExtSheet, sal_uInt16& rnExtName,
573 const OUString& rApplic,
const OUString& rTopic,
const OUString& rItem )
override;
575 virtual bool InsertExtName(
576 sal_uInt16& rnExtSheet, sal_uInt16& rnExtName,
const OUString& rUrl,
585 typedef XclExpExtSheetList::RecordRefType XclExpExtSheetRef;
586 typedef ::std::map< SCTAB, sal_uInt16 > XclExpIntTabMap;
587 typedef ::std::map< sal_Unicode, sal_uInt16 > XclExpCodeMap;
591 sal_uInt16 GetExtSheetCount()
const;
594 sal_uInt16 AppendInternal( XclExpExtSheetRef
const & xExtSheet );
596 void CreateInternal();
599 XclExpExtSheetRef GetInternal( sal_uInt16 nExtSheet );
601 XclExpExtSheetRef FindInternal( sal_uInt16& rnExtSheet, sal_uInt16& rnXclTab,
SCTAB nScTab );
603 XclExpExtSheetRef FindInternal( sal_uInt16& rnExtSheet,
sal_Unicode cCode );
606 XclExpExtSheetList maExtSheetList;
607 XclExpIntTabMap maIntTabMap;
608 XclExpCodeMap maCodeMap;
615 explicit XclExpLinkManagerImpl8(
const XclExpRoot& rRoot );
617 virtual void FindExtSheet( sal_uInt16& rnExtSheet,
618 sal_uInt16& rnFirstXclTab, sal_uInt16& rnLastXclTab,
621 virtual sal_uInt16 FindExtSheet(
sal_Unicode cCode )
override;
623 virtual void FindExtSheet( sal_uInt16 nFileId,
const OUString& rTabName, sal_uInt16 nXclTabSpan,
624 sal_uInt16& rnExtSheet, sal_uInt16& rnFirstSBTab, sal_uInt16& rnLastSBTab,
629 virtual void StoreCell( sal_uInt16 nFileId,
const OUString& rTabName,
const ScAddress& rPos )
override;
630 virtual void StoreCellRange( sal_uInt16 nFileId,
const OUString& rTabName,
const ScRange& rRange )
override;
632 virtual bool InsertAddIn(
633 sal_uInt16& rnExtSheet, sal_uInt16& rnExtName,
634 const OUString& rName )
override;
636 virtual bool InsertEuroTool(
637 sal_uInt16& rnExtSheet, sal_uInt16& rnExtName,
638 const OUString& rName )
override;
640 virtual bool InsertDde(
641 sal_uInt16& rnExtSheet, sal_uInt16& rnExtName,
642 const OUString& rApplic,
const OUString& rTopic,
const OUString& rItem )
override;
644 virtual bool InsertExtName(
645 sal_uInt16& rnExtSheet, sal_uInt16& rnExtName,
const OUString& rUrl,
655 sal_uInt16 InsertXti(
const XclExpXti& rXti );
659 XclExpSupbookBuffer maSBBuffer;
660 std::vector< XclExpXti > maXtiVec;
677 mnFirstVisXclTab( 0 )
691 for( nScTab = 0; nScTab <
mnScCnt; ++nScTab )
713 nFirstExpScTab = nScTab;
716 nFirstVisScTab = nScTab;
735 if (nDisplScTab == -1 )
742 nFirstVisScTab = nFirstExpScTab;
746 nFirstVisScTab = nDisplScTab;
754 nDisplScTab = nFirstVisScTab;
758 for( nScTab = 0; nScTab <
mnScCnt; ++nScTab )
798 OSL_ENSURE( nScTab < mnScCnt && nScTab >= 0,
"XclExpTabInfo::IsActiveTab - sheet out of range" );
809 OSL_ENSURE( nScTab < mnScCnt && nScTab >= 0,
"XclExpTabInfo::IsActiveTab - sheet out of range" );
810 return (nScTab < mnScCnt && nScTab >= 0) ?
maTabInfoVec[ nScTab ].maScName : OUString();
820 OSL_ENSURE( nSortedScTab < mnScCnt && nSortedScTab >= 0,
"XclExpTabInfo::GetRealScTab - sheet out of range" );
826 OSL_ENSURE( nScTab < mnScCnt && nScTab >= 0,
"XclExpTabInfo::GetFlag - sheet out of range" );
827 return (nScTab < mnScCnt && nScTab >= 0) && (
maTabInfoVec[ nScTab ].mnFlags & nFlags);
832 OSL_ENSURE( nScTab < mnScCnt && nScTab >= 0,
"XclExpTabInfo::SetFlag - sheet out of range" );
833 if( nScTab < mnScCnt && nScTab >= 0 )
844 sal_uInt16 nXclTab = 0;
848 for( nScTab = 0; nScTab <
mnScCnt; ++nScTab )
861 for( nScTab = 0; nScTab <
mnScCnt; ++nScTab )
878 struct XclExpTabNameSort {
879 bool operator ()(
const XclExpTabName& rArg1,
const XclExpTabName& rArg2 )
891 ::std::vector< XclExpTabName > aVec(
mnScCnt );
895 for( nScTab = 0; nScTab <
mnScCnt; ++nScTab )
898 aVec[ nScTab ].second = nScTab;
900 ::std::sort( aVec.begin(), aVec.end(), XclExpTabNameSort() );
905 for( nScTab = 0; nScTab <
mnScCnt; ++nScTab )
914 XclExpExtNameBase::XclExpExtNameBase(
915 const XclExpRoot& rRoot,
const OUString& rName, sal_uInt16 nFlags ) :
922 OSL_ENSURE(
maName.getLength() <= 255,
"XclExpExtNameBase::XclExpExtNameBase - string too long" );
923 SetRecSize( 6 + mxName->GetSize() );
926 void XclExpExtNameBase::WriteBody(
XclExpStream& rStrm )
931 WriteAddData( rStrm );
938 XclExpExtNameAddIn::XclExpExtNameAddIn(
const XclExpRoot& rRoot,
const OUString& rName ) :
939 XclExpExtNameBase( rRoot, rName )
944 void XclExpExtNameAddIn::WriteAddData(
XclExpStream& rStrm )
950 XclExpExtNameDde::XclExpExtNameDde(
const XclExpRoot& rRoot,
951 const OUString& rName, sal_uInt16 nFlags,
const ScMatrix* pResults ) :
952 XclExpExtNameBase( rRoot, rName, nFlags )
956 mxMatrix = std::make_shared<XclExpCachedMatrix>( *pResults );
957 AddRecSize( mxMatrix->GetSize() );
961 void XclExpExtNameDde::WriteAddData(
XclExpStream& rStrm )
964 mxMatrix->Save( rStrm );
967 XclExpExtName::XclExpExtName(
const XclExpRoot& rRoot,
const XclExpSupbook& rSupbook,
969 XclExpExtNameBase( rRoot, rName ),
1001 sal_uInt16 nCol =
static_cast<sal_uInt16
>(rRef.
Col());
1002 sal_uInt16 nRow =
static_cast<sal_uInt16
>(rRef.
Row());
1003 if (bColRel) nCol |= 0x4000;
1004 if (bRowRel) nCol |= 0x8000;
1007 sal_uInt16 nSBTab = mrSupbook.GetTabIndex(aTabName);
1010 rStrm << static_cast<sal_uInt16>(9);
1012 rStrm << static_cast<sal_uInt8>(0x3A);
1014 rStrm << nSBTab << nSBTab << nRow << nCol;
1025 sal_uInt16 nTab1 = r1.
Tab();
1026 sal_uInt16 nTab2 = r2.
Tab();
1032 sal_uInt16 nCol1 =
static_cast<sal_uInt16
>(r1.
Col());
1033 sal_uInt16 nCol2 =
static_cast<sal_uInt16
>(r2.
Col());
1034 sal_uInt16 nRow1 =
static_cast<sal_uInt16
>(r1.
Row());
1035 sal_uInt16 nRow2 =
static_cast<sal_uInt16
>(r2.
Row());
1036 if (bCol1Rel) nCol1 |= 0x4000;
1037 if (bRow1Rel) nCol1 |= 0x8000;
1038 if (bCol2Rel) nCol2 |= 0x4000;
1039 if (bRow2Rel) nCol2 |= 0x8000;
1042 sal_uInt16 nSBTab = mrSupbook.GetTabIndex(aTabName);
1045 rStrm << static_cast<sal_uInt16>(13);
1047 rStrm << static_cast<sal_uInt8>(0x3B);
1049 sal_uInt16 nSBTab2 = nSBTab + nTab2 - nTab1;
1050 rStrm << nSBTab << nSBTab2 << nRow1 << nRow2 << nCol1 << nCol2;
1072 pExternalLink->startElement(XML_definedName,
1073 XML_name,
maName.toUtf8(),
1074 XML_refersTo, aFormula.toUtf8(),
1075 XML_sheetId,
nullptr);
1079 pExternalLink->startElement(XML_definedName,
1080 XML_name,
maName.toUtf8(),
1081 XML_refersTo,
nullptr,
1082 XML_sheetId,
nullptr);
1085 pExternalLink->endElement(XML_definedName);
1090 XclExpExtNameBuffer::XclExpExtNameBuffer(
const XclExpRoot& rRoot ) :
1095 sal_uInt16 XclExpExtNameBuffer::InsertAddIn(
const OUString& rName )
1097 sal_uInt16
nIndex = GetIndex( rName );
1098 return nIndex ? nIndex : AppendNew(
new XclExpExtNameAddIn( GetRoot(), rName ) );
1101 sal_uInt16 XclExpExtNameBuffer::InsertEuroTool(
const OUString& rName )
1103 sal_uInt16 nIndex = GetIndex( rName );
1104 return nIndex ? nIndex : AppendNew(
new XclExpExtNameBase( GetRoot(), rName ) );
1107 sal_uInt16 XclExpExtNameBuffer::InsertDde(
1108 std::u16string_view rApplic, std::u16string_view rTopic,
const OUString& rItem )
1110 sal_uInt16 nIndex = GetIndex( rItem );
1117 if( maNameList.IsEmpty() )
1118 AppendNew(
new XclExpExtNameDde(
1122 const ScMatrix* pScMatrix = GetDoc().GetDdeLinkResultMatrix( nPos );
1123 nIndex = AppendNew(
new XclExpExtNameDde( GetRoot(), rItem,
EXC_EXTN_EXPDDE, pScMatrix ) );
1129 sal_uInt16 XclExpExtNameBuffer::InsertExtName(
const XclExpSupbook& rSupbook,
1132 sal_uInt16 nIndex = GetIndex( rName );
1133 return nIndex ? nIndex : AppendNew(
new XclExpExtName( GetRoot(), rSupbook, rName, rArray ) );
1138 maNameList.Save( rStrm );
1143 maNameList.SaveXml(rStrm);
1146 sal_uInt16 XclExpExtNameBuffer::GetIndex( std::u16string_view rName )
const
1148 for(
size_t nPos = 0, nSize = maNameList.GetSize(); nPos < nSize; ++nPos )
1149 if( maNameList.GetRecord( nPos )->GetName() == rName )
1150 return static_cast< sal_uInt16 >( nPos + 1 );
1154 sal_uInt16 XclExpExtNameBuffer::AppendNew( XclExpExtNameBase* pExtName )
1156 size_t nSize = maNameList.GetSize();
1157 if( nSize < 0x7FFF )
1159 maNameList.AppendRecord( pExtName );
1160 return static_cast< sal_uInt16
>( nSize + 1 );
1167 XclExpCrn::XclExpCrn(
SCCOL nScCol,
SCROW nScRow,
const Any& rValue ) :
1175 bool XclExpCrn::InsertValue(
SCCOL nScCol,
SCROW nScRow,
const Any& rValue )
1177 if( (nScRow != mnScRow) || (nScCol != static_cast< SCCOL >( mnScCol +
maValues.size() )) )
1185 rStrm << static_cast< sal_uInt8 >( mnScCol +
maValues.size() - 1 )
1186 << static_cast< sal_uInt8 >( mnScCol )
1187 <<
static_cast< sal_uInt16
>( mnScRow );
1188 for(
const auto& rValue : maValues )
1190 if( rValue.has<
bool >() )
1191 WriteBool( rStrm, rValue.get<
bool >() );
1192 else if( rValue.has<
double >() )
1193 WriteDouble( rStrm, rValue.get<
double >() );
1194 else if( rValue.has< OUString >() )
1195 WriteString( rStrm, rValue.get< OUString >() );
1197 WriteEmpty( rStrm );
1201 void XclExpCrn::WriteBool(
XclExpStream& rStrm,
bool bValue )
1207 void XclExpCrn::WriteDouble(
XclExpStream& rStrm,
double fValue )
1209 if( !std::isfinite( fValue ) )
1220 void XclExpCrn::WriteString(
XclExpStream& rStrm,
const OUString& rValue )
1241 pFS->startElement(XML_row, XML_r, OString::number(mnScRow + 1));
1244 for(
const auto& rValue : maValues )
1246 bool bCloseCell =
true;
1247 if( rValue.has<
double >() )
1249 double fVal = rValue.get<
double >();
1250 if (std::isfinite( fVal))
1254 pFS->startElement(XML_v);
1260 pFS->startElement(XML_v);
1261 pFS->write(
"#VALUE!" );
1264 else if( rValue.has< OUString >() )
1267 pFS->startElement(XML_v);
1268 pFS->write( rValue.get< OUString >() );
1270 else if( rValue.has<
bool >() )
1273 pFS->startElement(XML_v);
1274 pFS->write( rValue.get<
bool >() ?
"1" :
"0" );
1284 pFS->endElement(XML_v);
1285 pFS->endElement(XML_cell);
1290 pFS->endElement( XML_row);
1295 XclExpXct::XclExpXct(
const XclExpRoot& rRoot,
const OUString& rTabName,
1298 mxCacheTable( xCacheTable ),
1299 maUsedCells( rRoot.GetDoc().GetSheetLimits() ),
1300 maBoundRange(
ScAddress::INITIALIZE_INVALID ),
1301 maTabName( rTabName ),
1306 void XclExpXct::StoreCellRange(
const ScRange& rRange )
1312 maUsedCells.SetMultiMarkArea( rRange );
1313 maBoundRange.ExtendTo( rRange );
1316 void XclExpXct::StoreCell_(
const ScAddress& rCell )
1318 maUsedCells.SetMultiMarkArea(
ScRange( rCell ) );
1319 maBoundRange.ExtendTo(
ScRange( rCell ) );
1322 void XclExpXct::StoreCellRange_(
const ScRange& rRange )
1324 maUsedCells.SetMultiMarkArea( rRange );
1325 maBoundRange.ExtendTo( rRange );
1335 bool InsertValue(
SCCOL nScCol,
SCROW nScRow,
const Any& rValue );
1338 bool XclExpCrnList::InsertValue(
SCCOL nScCol,
SCROW nScRow,
const Any& rValue )
1340 RecordRefType xLastRec = GetLastRecord();
1341 if( xLastRec && xLastRec->InsertValue( nScCol, nScRow, rValue ) )
1345 AppendNewRecord(
new XclExpCrn( nScCol, nScRow, rValue ) );
1351 bool XclExpXct::BuildCrnList( XclExpCrnList& rCrnRecs )
1360 ::std::pair< SCROW, SCROW > aRowRange = mxCacheTable->getRowRange();
1361 if( aRowRange.first >= aRowRange.second )
1366 if( !GetAddressConverter().ValidateRange( maBoundRange,
false ) )
1370 SCROW nScRow1 = ::std::max( aRowRange.first, maBoundRange.aStart.Row() );
1371 SCROW nScRow2 = ::std::min( aRowRange.second - 1, maBoundRange.aEnd.Row() );
1372 if( nScRow1 > nScRow2 )
1381 for(
SCROW nScRow = nScRow1; bValid && (nScRow <= nScRow2); ++nScRow )
1383 ::std::pair< SCCOL, SCCOL > aColRange = mxCacheTable->getColRange( nScRow );
1384 const SCCOL nScEnd = ::std::min( aColRange.second, GetDoc().GetSheetLimits().GetMaxColCount() );
1385 for(
SCCOL nScCol = aColRange.first; bValid && (nScCol < nScEnd); ++nScCol )
1387 if( maUsedCells.IsCellMarked( nScCol, nScRow,
true ) )
1389 sal_uInt32 nScNumFmt = 0;
1393 switch( xToken->GetType() )
1396 bValid = (rFormatter.
GetType( nScNumFmt ) == SvNumFormatType::LOGICAL) ?
1397 rCrnRecs.InsertValue( nScCol, nScRow,
Any( xToken->GetDouble() != 0 ) ) :
1398 rCrnRecs.InsertValue( nScCol, nScRow,
Any( xToken->GetDouble() ) );
1402 if( !xToken->GetString().isEmpty() )
1403 bValid = rCrnRecs.InsertValue( nScCol, nScRow,
Any( xToken->GetString().getString() ) );
1416 XclExpCrnList aCrnRecs;
1417 if (!BuildCrnList( aCrnRecs))
1422 rStrm << static_cast< sal_uInt16 >( aCrnRecs.GetSize() ) << mnSBTab;
1424 aCrnRecs.Save( rStrm );
1429 XclExpCrnList aCrnRecs;
1433 bool bValid = BuildCrnList( aCrnRecs);
1434 pFS->startElement(XML_sheetData, XML_sheetId, OString::number(mnSBTab));
1438 aCrnRecs.SaveXml( rStrm );
1440 pFS->endElement( XML_sheetData);
1445 XclExpExternSheetBase::XclExpExternSheetBase(
const XclExpRoot& rRoot, sal_uInt16 nRecId, sal_uInt32 nRecSize ) :
1451 XclExpExtNameBuffer& XclExpExternSheetBase::GetExtNameBuffer()
1454 mxExtNameBfr = std::make_shared<XclExpExtNameBuffer>( GetRoot() );
1455 return *mxExtNameBfr;
1458 void XclExpExternSheetBase::WriteExtNameBuffer(
XclExpStream& rStrm )
1461 mxExtNameBfr->Save( rStrm );
1464 void XclExpExternSheetBase::WriteExtNameBufferXml(
XclExpXmlStream& rStrm )
1467 mxExtNameBfr->SaveXml( rStrm );
1475 Init( OUStringChar(cCode) );
1478 XclExpExternSheet::XclExpExternSheet(
const XclExpRoot& rRoot, std::u16string_view rTabName ) :
1490 WriteExtNameBuffer( rStrm );
1493 void XclExpExternSheet::Init( std::u16string_view rEncUrl )
1497 SetRecSize( maTabName.GetSize() );
1500 sal_uInt16 XclExpExternSheet::InsertAddIn(
const OUString& rName )
1502 return GetExtNameBuffer().InsertAddIn( rName );
1505 void XclExpExternSheet::WriteBody(
XclExpStream& rStrm )
1512 maTabName.WriteBuffer( rStrm );
1517 XclExpSupbook::XclExpSupbook(
const XclExpRoot& rRoot, sal_uInt16 nXclTabCount ) :
1520 mnXclTabCount( nXclTabCount ),
1525 XclExpSupbook::XclExpSupbook(
const XclExpRoot& rRoot ) :
1536 maUrlEncoded( rUrl ),
1541 SetRecSize( 2 + maUrlEncoded.GetSize() );
1544 XclExpSupbook::XclExpSupbook(
const XclExpRoot& rRoot,
const OUString& rUrl ) :
1552 SetRecSize( 2 + maUrlEncoded.GetSize() );
1557 mnFileId = nFileId + 1;
1559 pRefMgr->getAllCachedTableNames( nFileId, aTabNames );
1560 size_t nTabIndex = 0;
1561 for(
const auto& rTabName : aTabNames )
1563 InsertTabName( rTabName, pRefMgr->getCacheTable( nFileId, nTabIndex ) );
1568 XclExpSupbook::XclExpSupbook(
const XclExpRoot& rRoot,
const OUString& rApplic,
const OUString& rTopic ) :
1571 maDdeTopic( rTopic ),
1577 SetRecSize( 2 + maUrlEncoded.GetSize() );
1580 bool XclExpSupbook::IsUrlLink( std::u16string_view rUrl )
const
1585 bool XclExpSupbook::IsDdeLink( std::u16string_view rApplic, std::u16string_view rTopic )
const
1591 sal_uInt16 nFirstSBTab, sal_uInt16 nLastSBTab )
const
1593 rRefLogEntry.
mpUrl = maUrlEncoded.
IsEmpty() ?
nullptr : &maUrlEncoded;
1594 rRefLogEntry.
mpFirstTab = GetTabName( nFirstSBTab );
1595 rRefLogEntry.
mpLastTab = GetTabName( nLastSBTab );
1598 void XclExpSupbook::StoreCellRange(
const ScRange& rRange, sal_uInt16 nSBTab )
1600 if( XclExpXct* pXct = maXctList.GetRecord( nSBTab ) )
1601 pXct->StoreCellRange( rRange );
1604 void XclExpSupbook::StoreCell_( sal_uInt16 nSBTab,
const ScAddress& rCell )
1606 if( XclExpXct* pXct = maXctList.GetRecord( nSBTab ) )
1607 pXct->StoreCell_( rCell );
1610 void XclExpSupbook::StoreCellRange_( sal_uInt16 nSBTab,
const ScRange& rRange )
1614 if( XclExpXct* pXct = maXctList.GetRecord( nSBTab ) )
1615 pXct->StoreCellRange_( rRange );
1618 sal_uInt16 XclExpSupbook::GetTabIndex(
const OUString& rTabName )
const
1621 size_t nSize = maXctList.GetSize();
1622 for (
size_t i = 0;
i < nSize; ++
i)
1624 XclExpXctRef aRec = maXctList.GetRecord(i);
1625 if (aXclName == aRec->GetTabName())
1626 return ulimit_cast<sal_uInt16>(i);
1631 sal_uInt16 XclExpSupbook::GetTabCount()
const
1633 return ulimit_cast<sal_uInt16>(maXctList.GetSize());
1639 sal_uInt16 nSBTab =
ulimit_cast< sal_uInt16 >( maXctList.GetSize() );
1640 XclExpXctRef xXct =
new XclExpXct( GetRoot(), rTabName, nSBTab, xCacheTable );
1641 AddRecSize( xXct->GetTabName().GetSize() );
1642 maXctList.AppendRecord( xXct );
1646 sal_uInt16 XclExpSupbook::InsertAddIn(
const OUString& rName )
1648 return GetExtNameBuffer().InsertAddIn( rName );
1651 sal_uInt16 XclExpSupbook::InsertEuroTool(
const OUString& rName )
1653 return GetExtNameBuffer().InsertEuroTool( rName );
1656 sal_uInt16 XclExpSupbook::InsertDde(
const OUString& rItem )
1658 return GetExtNameBuffer().InsertDde( maUrl, maDdeTopic, rItem );
1663 return GetExtNameBuffer().InsertExtName(*
this, rName, rArray);
1671 sal_uInt16 XclExpSupbook::GetFileId()
const
1676 const OUString& XclExpSupbook::GetUrl()
const
1686 maXctList.Save( rStrm );
1688 WriteExtNameBuffer( rStrm );
1696 sal_uInt16 nLevel = 0;
1702 while (nLevel-- > 0)
1703 sFile =
"../" + sFile;
1705 OUString
sId = rStrm.
addRelation( pExternalLink->getOutputStream(),
1708 pExternalLink->startElement( XML_externalLink,
1711 pExternalLink->startElement( XML_externalBook,
1713 FSNS(XML_r, XML_id), sId.toUtf8());
1715 if (!maXctList.IsEmpty())
1717 pExternalLink->startElement(XML_sheetNames);
1718 for (
size_t nPos = 0, nSize = maXctList.GetSize(); nPos < nSize; ++nPos)
1720 pExternalLink->singleElement(XML_sheetName,
1723 pExternalLink->endElement( XML_sheetNames);
1729 pExternalLink->startElement(XML_definedNames);
1731 WriteExtNameBufferXml( rStrm );
1732 pExternalLink->endElement(XML_definedNames);
1735 if (!maXctList.IsEmpty())
1737 pExternalLink->startElement(XML_sheetDataSet);
1740 maXctList.SaveXml( rStrm );
1742 pExternalLink->endElement( XML_sheetDataSet);
1745 pExternalLink->endElement( XML_externalBook);
1746 pExternalLink->endElement( XML_externalLink);
1749 const XclExpString* XclExpSupbook::GetTabName( sal_uInt16 nSBTab )
const
1751 XclExpXctRef xXct = maXctList.GetRecord( nSBTab );
1752 return xXct ? &xXct->GetTabName() :
nullptr;
1767 rStrm << nCount << maUrlEncoded;
1769 for(
size_t nPos = 0, nSize = maXctList.GetSize(); nPos < nSize; ++nPos )
1770 rStrm << maXctList.GetRecord( nPos )->GetTabName();
1777 SAL_WARN(
"sc.filter",
"Unhandled SUPBOOK type " << meType);
1783 XclExpSupbookBuffer::XclExpSupbookBuffer(
const XclExpRoot& rRoot ) :
1793 OSL_ENSURE( nCount > 0,
"XclExpSupbookBuffer::XclExpSupbookBuffer - no sheets to export" );
1796 maSBIndexVec.resize( nCount );
1799 XclExpSupbookRef xSupbook =
new XclExpSupbook(
GetRoot(), ::std::max( nXclCnt, nCodeCnt ) );
1800 mnOwnDocSB =
Append( xSupbook );
1801 for( sal_uInt16 nXclTab = 0; nXclTab < nXclCnt; ++nXclTab )
1802 maSBIndexVec[ nXclTab ].
Set( mnOwnDocSB, nXclTab );
1806 XclExpXti XclExpSupbookBuffer::GetXti( sal_uInt16 nFirstXclTab, sal_uInt16 nLastXclTab,
1810 size_t nSize = maSBIndexVec.size();
1811 if( (nFirstXclTab < nSize) && (nLastXclTab < nSize) )
1814 aXti.mnSupbook = maSBIndexVec[ nFirstXclTab ].mnSupbook;
1817 bool bSameSB =
true;
1818 for( sal_uInt16 nXclTab = nFirstXclTab + 1; bSameSB && (nXclTab <= nLastXclTab); ++nXclTab )
1820 bSameSB = maSBIndexVec[ nXclTab ].mnSupbook == aXti.mnSupbook;
1822 nLastXclTab = nXclTab - 1;
1824 aXti.mnFirstSBTab = maSBIndexVec[ nFirstXclTab ].mnSBTab;
1825 aXti.mnLastSBTab = maSBIndexVec[ nLastXclTab ].mnSBTab;
1832 XclExpSupbookRef xSupbook = maSupbookList.GetRecord( aXti.mnSupbook );
1834 xSupbook->FillRefLogEntry( *pRefLogEntry, aXti.mnFirstSBTab, aXti.mnLastSBTab );
1840 aXti.mnSupbook = mnOwnDocSB;
1841 aXti.mnFirstSBTab = nFirstXclTab;
1842 aXti.mnLastSBTab = nLastXclTab;
1848 void XclExpSupbookBuffer::StoreCellRange(
const ScRange& rRange )
1850 sal_uInt16 nXclTab = GetTabInfo().GetXclTab( rRange.
aStart.
Tab() );
1851 if( nXclTab < maSBIndexVec.size() )
1853 const XclExpSBIndex& rSBIndex = maSBIndexVec[ nXclTab ];
1854 XclExpSupbookRef xSupbook = maSupbookList.GetRecord( rSBIndex.mnSupbook );
1855 OSL_ENSURE( xSupbook ,
"XclExpSupbookBuffer::StoreCellRange - missing SUPBOOK record" );
1857 xSupbook->StoreCellRange( rRange, rSBIndex.mnSBTab );
1863 class FindSBIndexEntry
1866 explicit FindSBIndexEntry(sal_uInt16 nSupbookId, sal_uInt16 nTabId) :
1867 mnSupbookId(nSupbookId), mnTabId(nTabId) {}
1869 bool operator()(
const XclExpSupbookBuffer::XclExpSBIndex& r)
const
1871 return mnSupbookId == r.mnSupbook && mnTabId == r.mnSBTab;
1875 sal_uInt16 mnSupbookId;
1881 void XclExpSupbookBuffer::StoreCell( sal_uInt16 nFileId,
const OUString& rTabName,
const ScAddress& rCell )
1888 XclExpSupbookRef xSupbook;
1889 sal_uInt16 nSupbookId;
1890 if (!GetSupbookUrl(xSupbook, nSupbookId, *pUrl))
1892 xSupbook =
new XclExpSupbook(GetRoot(), *pUrl);
1893 nSupbookId =
Append(xSupbook);
1896 sal_uInt16 nSheetId = xSupbook->GetTabIndex(rTabName);
1901 FindSBIndexEntry
f(nSupbookId, nSheetId);
1902 if (::std::none_of(maSBIndexVec.begin(), maSBIndexVec.end(),
f))
1904 maSBIndexVec.emplace_back();
1905 XclExpSBIndex& r = maSBIndexVec.back();
1906 r.mnSupbook = nSupbookId;
1907 r.mnSBTab = nSheetId;
1910 xSupbook->StoreCell_(nSheetId, rCell);
1913 void XclExpSupbookBuffer::StoreCellRange( sal_uInt16 nFileId,
const OUString& rTabName,
const ScRange& rRange )
1920 XclExpSupbookRef xSupbook;
1921 sal_uInt16 nSupbookId;
1922 if (!GetSupbookUrl(xSupbook, nSupbookId, *pUrl))
1924 xSupbook =
new XclExpSupbook(GetRoot(), *pUrl);
1925 nSupbookId =
Append(xSupbook);
1932 SCTAB aMatrixListSize = 0;
1939 FormulaTokenArrayPlainIterator aIter(*pArray);
1940 for (FormulaToken* p = aIter.First(); p; p = aIter.Next())
1951 if (aMatrixListSize != nTabCount)
1957 sal_uInt16 nFirstSheetId = xSupbook->GetTabIndex(rTabName);
1960 aRange.aStart.SetTab(0);
1961 aRange.aEnd.SetTab(0);
1962 for (
SCTAB nTab = 0; nTab < nTabCount; ++nTab)
1964 sal_uInt16 nSheetId = nFirstSheetId +
static_cast<sal_uInt16
>(nTab);
1965 FindSBIndexEntry
f(nSupbookId, nSheetId);
1966 if (::std::none_of(maSBIndexVec.begin(), maSBIndexVec.end(),
f))
1968 maSBIndexVec.emplace_back();
1969 XclExpSBIndex& r = maSBIndexVec.back();
1970 r.mnSupbook = nSupbookId;
1971 r.mnSBTab = nSheetId;
1974 xSupbook->StoreCellRange_(nSheetId, aRange);
1978 bool XclExpSupbookBuffer::InsertAddIn(
1979 sal_uInt16& rnSupbook, sal_uInt16& rnExtName,
const OUString& rName )
1981 XclExpSupbookRef xSupbook;
1982 if( mnAddInSB == SAL_MAX_UINT16 )
1984 xSupbook =
new XclExpSupbook( GetRoot() );
1985 mnAddInSB =
Append( xSupbook );
1988 xSupbook = maSupbookList.GetRecord( mnAddInSB );
1989 OSL_ENSURE( xSupbook,
"XclExpSupbookBuffer::InsertAddin - missing add-in supbook" );
1990 rnSupbook = mnAddInSB;
1991 rnExtName = xSupbook->InsertAddIn( rName );
1992 return rnExtName > 0;
1995 bool XclExpSupbookBuffer::InsertEuroTool(
1996 sal_uInt16& rnSupbook, sal_uInt16& rnExtName,
const OUString& rName )
1998 XclExpSupbookRef xSupbook;
1999 OUString aUrl(
"\001\010EUROTOOL.XLA" );
2000 if( !GetSupbookUrl( xSupbook, rnSupbook, aUrl ) )
2003 rnSupbook =
Append( xSupbook );
2005 rnExtName = xSupbook->InsertEuroTool( rName );
2006 return rnExtName > 0;
2009 bool XclExpSupbookBuffer::InsertDde(
2010 sal_uInt16& rnSupbook, sal_uInt16& rnExtName,
2011 const OUString& rApplic,
const OUString& rTopic,
const OUString& rItem )
2013 XclExpSupbookRef xSupbook;
2014 if( !GetSupbookDde( xSupbook, rnSupbook, rApplic, rTopic ) )
2016 xSupbook =
new XclExpSupbook( GetRoot(), rApplic, rTopic );
2017 rnSupbook =
Append( xSupbook );
2019 rnExtName = xSupbook->InsertDde( rItem );
2020 return rnExtName > 0;
2023 bool XclExpSupbookBuffer::InsertExtName(
2024 sal_uInt16& rnSupbook, sal_uInt16& rnExtName,
const OUString& rUrl,
2027 XclExpSupbookRef xSupbook;
2028 if (!GetSupbookUrl(xSupbook, rnSupbook, rUrl))
2030 xSupbook =
new XclExpSupbook(GetRoot(), rUrl);
2031 rnSupbook =
Append(xSupbook);
2033 rnExtName = xSupbook->InsertExtName(rName, rArray);
2034 return rnExtName > 0;
2037 XclExpXti XclExpSupbookBuffer::GetXti( sal_uInt16 nFileId,
const OUString& rTabName, sal_uInt16 nXclTabSpan,
2046 XclExpSupbookRef xSupbook;
2047 sal_uInt16 nSupbookId;
2048 if (!GetSupbookUrl(xSupbook, nSupbookId, *pUrl))
2050 xSupbook =
new XclExpSupbook(GetRoot(), *pUrl);
2051 nSupbookId =
Append(xSupbook);
2053 aXti.mnSupbook = nSupbookId;
2055 sal_uInt16 nFirstSheetId = xSupbook->GetTabIndex(rTabName);
2061 sal_uInt16 nSheetCount = xSupbook->GetTabCount();
2062 for (sal_uInt16 i = 0;
i < nXclTabSpan; ++
i)
2064 sal_uInt16 nSheetId = nFirstSheetId +
i;
2065 if (nSheetId >= nSheetCount)
2068 FindSBIndexEntry
f(nSupbookId, nSheetId);
2069 if (::std::none_of(maSBIndexVec.begin(), maSBIndexVec.end(),
f))
2071 maSBIndexVec.emplace_back();
2072 XclExpSBIndex& r = maSBIndexVec.back();
2073 r.mnSupbook = nSupbookId;
2074 r.mnSBTab = nSheetId;
2077 aXti.mnFirstSBTab = nSheetId;
2078 if (i == nXclTabSpan - 1)
2079 aXti.mnLastSBTab = nSheetId;
2087 xSupbook->FillRefLogEntry(*pRefLogEntry, aXti.mnFirstSBTab, aXti.mnLastSBTab);
2095 maSupbookList.Save( rStrm );
2103 vector<sal_uInt16> aExternFileIds;
2104 for (
size_t nPos = 0, nSize = maSupbookList.GetSize(); nPos < nSize; ++nPos)
2106 XclExpSupbookRef xRef(maSupbookList.GetRecord(nPos));
2110 aExternFileIds.push_back(xRef->GetFileId() - 1);
2112 if (aExternFileIds.size() > 0)
2115 ::std::map< sal_uInt16, OUString >
aMap;
2116 for (
size_t nPos = 0, nSize = maSupbookList.GetSize(); nPos < nSize; ++nPos)
2118 XclExpSupbookRef xRef( maSupbookList.GetRecord( nPos));
2122 sal_uInt16
nId = xRef->GetFileId();
2124 const OUString& rUrl = xRef->GetUrl();
2125 ::std::pair< ::std::map< sal_uInt16, OUString >::iterator,
bool > aInsert(
2126 aMap.insert( ::std::make_pair( nId, rUrl)));
2127 if (!aInsert.second)
2129 SAL_WARN(
"sc.filter",
"XclExpSupbookBuffer::SaveXml: file ID already used: " << nId <<
2130 " wanted for " << rUrl <<
" and is " << (*aInsert.first).second <<
2131 (rUrl == (*aInsert.first).second ?
" multiple Supbook not supported" :
""));
2139 "application/vnd.openxmlformats-officedocument.spreadsheetml.externalLink+xml",
2145 FSNS(XML_r, XML_id), sId.toUtf8() );
2149 xRef->SaveXml( rStrm );
2154 bool XclExpSupbookBuffer::HasExternalReferences()
const
2156 for (
size_t nPos = 0, nSize = maSupbookList.GetSize(); nPos < nSize; ++nPos)
2164 bool XclExpSupbookBuffer::GetSupbookUrl(
2165 XclExpSupbookRef& rxSupbook, sal_uInt16& rnIndex, std::u16string_view rUrl )
const
2167 for(
size_t nPos = 0, nSize = maSupbookList.GetSize(); nPos < nSize; ++nPos )
2169 rxSupbook = maSupbookList.GetRecord( nPos );
2170 if( rxSupbook->IsUrlLink( rUrl ) )
2179 bool XclExpSupbookBuffer::GetSupbookDde( XclExpSupbookRef& rxSupbook,
2180 sal_uInt16& rnIndex, std::u16string_view rApplic, std::u16string_view rTopic )
const
2182 for(
size_t nPos = 0, nSize = maSupbookList.GetSize(); nPos < nSize; ++nPos )
2184 rxSupbook = maSupbookList.GetRecord( nPos );
2185 if( rxSupbook->IsDdeLink( rApplic, rTopic ) )
2194 sal_uInt16 XclExpSupbookBuffer::Append( XclExpSupbookRef
const & xSupbook )
2196 maSupbookList.AppendRecord( xSupbook );
2197 return ulimit_cast< sal_uInt16 >( maSupbookList.GetSize() - 1 );
2207 XclExpLinkManagerImpl5::XclExpLinkManagerImpl5(
const XclExpRoot& rRoot ) :
2212 void XclExpLinkManagerImpl5::FindExtSheet(
2213 sal_uInt16& rnExtSheet, sal_uInt16& rnFirstXclTab, sal_uInt16& rnLastXclTab,
2216 FindInternal( rnExtSheet, rnFirstXclTab, nFirstScTab );
2217 if( (rnFirstXclTab ==
EXC_TAB_DELETED) || (nFirstScTab == nLastScTab) )
2219 rnLastXclTab = rnFirstXclTab;
2223 sal_uInt16 nDummyExtSheet;
2224 FindInternal( nDummyExtSheet, rnLastXclTab, nLastScTab );
2227 OSL_ENSURE( !pRefLogEntry,
"XclExpLinkManagerImpl5::FindExtSheet - fill reflog entry not implemented" );
2230 sal_uInt16 XclExpLinkManagerImpl5::FindExtSheet(
sal_Unicode cCode )
2232 sal_uInt16 nExtSheet;
2233 FindInternal( nExtSheet, cCode );
2237 void XclExpLinkManagerImpl5::FindExtSheet(
2238 sal_uInt16 ,
const OUString& , sal_uInt16 ,
2239 sal_uInt16& , sal_uInt16& , sal_uInt16& ,
2250 void XclExpLinkManagerImpl5::StoreCell( sal_uInt16 ,
const OUString& ,
const ScAddress& )
2255 void XclExpLinkManagerImpl5::StoreCellRange( sal_uInt16 ,
const OUString& ,
const ScRange& )
2260 bool XclExpLinkManagerImpl5::InsertAddIn(
2261 sal_uInt16& rnExtSheet, sal_uInt16& rnExtName,
const OUString& rName )
2263 XclExpExtSheetRef xExtSheet = FindInternal( rnExtSheet,
EXC_EXTSH_ADDIN );
2266 rnExtName = xExtSheet->InsertAddIn( rName );
2267 return rnExtName > 0;
2272 bool XclExpLinkManagerImpl5::InsertEuroTool(
2273 sal_uInt16& , sal_uInt16& ,
const OUString& )
2278 bool XclExpLinkManagerImpl5::InsertDde(
2279 sal_uInt16& , sal_uInt16& ,
2280 const OUString& ,
const OUString& ,
const OUString& )
2286 bool XclExpLinkManagerImpl5::InsertExtName(
2287 sal_uInt16& , sal_uInt16& ,
const OUString& ,
2294 void XclExpLinkManagerImpl5::Save(
XclExpStream& rStrm )
2296 if( sal_uInt16 nExtSheetCount = GetExtSheetCount() )
2301 maExtSheetList.Save( rStrm );
2310 sal_uInt16 XclExpLinkManagerImpl5::GetExtSheetCount()
const
2312 return static_cast< sal_uInt16
>( maExtSheetList.GetSize() );
2315 sal_uInt16 XclExpLinkManagerImpl5::AppendInternal( XclExpExtSheetRef
const & xExtSheet )
2317 if( GetExtSheetCount() < 0x7FFF )
2319 maExtSheetList.AppendRecord( xExtSheet );
2321 return static_cast< sal_uInt16
>( -GetExtSheetCount() );
2326 void XclExpLinkManagerImpl5::CreateInternal()
2328 if( !maIntTabMap.empty() )
2333 for(
SCTAB nScTab = 0, nScCnt = rTabInfo.
GetScTabCount(); nScTab < nScCnt; ++nScTab )
2337 XclExpExtSheetRef xRec;
2338 if( nScTab == GetCurrScTab() )
2341 xRec =
new XclExpExternSheet( GetRoot(), rTabInfo.
GetScTabName( nScTab ) );
2342 maIntTabMap[ nScTab ] = AppendInternal( xRec );
2349 return maExtSheetList.GetRecord( static_cast< sal_uInt16 >( -nExtSheet - 1 ) );
2353 sal_uInt16& rnExtSheet, sal_uInt16& rnXclTab,
SCTAB nScTab )
2359 XclExpExtSheetRef xExtSheet;
2360 XclExpIntTabMap::const_iterator aIt = maIntTabMap.find( nScTab );
2361 if( aIt == maIntTabMap.end() )
2368 rnExtSheet = aIt->second;
2369 xExtSheet = GetInternal( rnExtSheet );
2370 rnXclTab = GetTabInfo().GetXclTab( nScTab );
2378 XclExpExtSheetRef xExtSheet;
2379 XclExpCodeMap::const_iterator aIt = maCodeMap.find( cCode );
2380 if( aIt == maCodeMap.end() )
2382 xExtSheet =
new XclExpExternSheet( GetRoot(), cCode );
2383 rnExtSheet = maCodeMap[ cCode ] = AppendInternal( xExtSheet );
2387 rnExtSheet = aIt->second;
2388 xExtSheet = GetInternal( rnExtSheet );
2393 XclExpLinkManagerImpl8::XclExpLinkManagerImpl8(
const XclExpRoot& rRoot ) :
2399 void XclExpLinkManagerImpl8::FindExtSheet(
2400 sal_uInt16& rnExtSheet, sal_uInt16& rnFirstXclTab, sal_uInt16& rnLastXclTab,
2404 rnFirstXclTab = rTabInfo.
GetXclTab( nFirstScTab );
2405 rnLastXclTab = rTabInfo.
GetXclTab( nLastScTab );
2406 rnExtSheet = InsertXti( maSBBuffer.GetXti( rnFirstXclTab, rnLastXclTab, pRefLogEntry ) );
2409 sal_uInt16 XclExpLinkManagerImpl8::FindExtSheet(
sal_Unicode cCode )
2412 "XclExpLinkManagerImpl8::FindExtSheet - unknown externsheet code" );
2416 void XclExpLinkManagerImpl8::FindExtSheet(
2417 sal_uInt16 nFileId,
const OUString& rTabName, sal_uInt16 nXclTabSpan,
2418 sal_uInt16& rnExtSheet, sal_uInt16& rnFirstSBTab, sal_uInt16& rnLastSBTab,
2421 XclExpXti aXti = maSBBuffer.GetXti(nFileId, rTabName, nXclTabSpan, pRefLogEntry);
2422 rnExtSheet = InsertXti(aXti);
2423 rnFirstSBTab = aXti.mnFirstSBTab;
2424 rnLastSBTab = aXti.mnLastSBTab;
2438 for (
SCTAB nScTab = nFirstScTab; nScTab <= nLastScTab; ++nScTab)
2443 aRange.aEnd.SetTab( nScTab );
2444 maSBBuffer.StoreCellRange( aRange );
2449 void XclExpLinkManagerImpl8::StoreCell( sal_uInt16 nFileId,
const OUString& rTabName,
const ScAddress& rPos )
2451 maSBBuffer.StoreCell(nFileId, rTabName, rPos);
2454 void XclExpLinkManagerImpl8::StoreCellRange( sal_uInt16 nFileId,
const OUString& rTabName,
const ScRange& rRange )
2456 maSBBuffer.StoreCellRange(nFileId, rTabName, rRange);
2459 bool XclExpLinkManagerImpl8::InsertAddIn(
2460 sal_uInt16& rnExtSheet, sal_uInt16& rnExtName,
const OUString& rName )
2462 sal_uInt16 nSupbook;
2463 if( maSBBuffer.InsertAddIn( nSupbook, rnExtName, rName ) )
2471 bool XclExpLinkManagerImpl8::InsertEuroTool(
2472 sal_uInt16& rnExtSheet, sal_uInt16& rnExtName,
const OUString& rName )
2474 sal_uInt16 nSupbook;
2475 if( maSBBuffer.InsertEuroTool( nSupbook, rnExtName, rName ) )
2483 bool XclExpLinkManagerImpl8::InsertDde(
2484 sal_uInt16& rnExtSheet, sal_uInt16& rnExtName,
2485 const OUString& rApplic,
const OUString& rTopic,
const OUString& rItem )
2487 sal_uInt16 nSupbook;
2488 if( maSBBuffer.InsertDde( nSupbook, rnExtName, rApplic, rTopic, rItem ) )
2496 bool XclExpLinkManagerImpl8::InsertExtName( sal_uInt16& rnExtSheet, sal_uInt16& rnExtName,
2499 sal_uInt16 nSupbook;
2500 if( maSBBuffer.InsertExtName( nSupbook, rnExtName, rUrl, rName, rArray ) )
2508 void XclExpLinkManagerImpl8::Save(
XclExpStream& rStrm )
2510 if( maXtiVec.empty() )
2514 maSBBuffer.Save( rStrm );
2517 sal_uInt16 nCount =
ulimit_cast< sal_uInt16 >( maXtiVec.size() );
2521 for(
const auto& rXti : maXtiVec )
2528 if (maSBBuffer.HasExternalReferences())
2531 pWorkbook->startElement(XML_externalReferences);
2534 maSBBuffer.SaveXml( rStrm );
2536 pWorkbook->endElement( XML_externalReferences);
2541 if( !maXtiVec.empty() )
2543 for(
const auto& rXti : maXtiVec )
2544 rXti.SaveXml( rStrm );
2549 sal_uInt16 XclExpLinkManagerImpl8::InsertXti(
const XclExpXti& rXti )
2551 auto aIt = std::find(maXtiVec.begin(), maXtiVec.end(), rXti);
2552 if (aIt != maXtiVec.end())
2553 return ulimit_cast< sal_uInt16 >( std::distance(maXtiVec.begin(), aIt) );
2554 maXtiVec.push_back( rXti );
2555 return ulimit_cast< sal_uInt16 >( maXtiVec.size() - 1 );
2564 mxImpl = std::make_shared<XclExpLinkManagerImpl5>( rRoot );
2567 mxImpl = std::make_shared<XclExpLinkManagerImpl8>( rRoot );
2579 sal_uInt16& rnExtSheet, sal_uInt16& rnXclTab,
2582 mxImpl->FindExtSheet( rnExtSheet, rnXclTab, rnXclTab, nScTab, nScTab, pRefLogEntry );
2586 sal_uInt16& rnExtSheet, sal_uInt16& rnFirstXclTab, sal_uInt16& rnLastXclTab,
2589 mxImpl->FindExtSheet( rnExtSheet, rnFirstXclTab, rnLastXclTab, nFirstScTab, nLastScTab, pRefLogEntry );
2594 return mxImpl->FindExtSheet( cCode );
2598 sal_uInt16& rnExtSheet, sal_uInt16& rnFirstSBTab, sal_uInt16& rnLastSBTab,
2601 mxImpl->FindExtSheet( nFileId, rTabName, nXclTabSpan, rnExtSheet, rnFirstSBTab, rnLastSBTab, pRefLogEntry );
2606 mxImpl->StoreCellRange(rRef, rRef, rPos);
2616 mxImpl->StoreCell(nFileId, rTabName, rPos);
2621 mxImpl->StoreCellRange(nFileId, rTabName, rRange);
2625 sal_uInt16& rnExtSheet, sal_uInt16& rnExtName,
const OUString& rName )
2627 return mxImpl->InsertAddIn( rnExtSheet, rnExtName, rName );
2631 sal_uInt16& rnExtSheet, sal_uInt16& rnExtName,
const OUString& rName )
2633 return mxImpl->InsertEuroTool( rnExtSheet, rnExtName, rName );
2637 sal_uInt16& rnExtSheet, sal_uInt16& rnExtName,
2638 const OUString& rApplic,
const OUString& rTopic,
const OUString& rItem )
2640 return mxImpl->InsertDde( rnExtSheet, rnExtName, rApplic, rTopic, rItem );
2644 sal_uInt16& rnExtSheet, sal_uInt16& rnExtName,
const OUString& rUrl,
const OUString& rName,
2647 return mxImpl->InsertExtName(rnExtSheet, rnExtName, rUrl, rName, rArray);
2657 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
static OUString ToOUString(const char *s)
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.
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.
virtual OUString GetName() const override
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.
sax_fastparser::FSHelperPtr CreateOutputStream(const OUString &sFullStream, std::u16string_view sRelativeStream, const css::uno::Reference< css::io::XOutputStream > &xParentRelation, const char *sContentType, std::u16string_view sRelationshipType, OUString *pRelationshipId=nullptr)
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
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)
static SC_DLLPUBLIC CollatorWrapper & GetCollator()
case-insensitive collator
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.
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
OUString addRelation(const OUString &rType, std::u16string_view rTarget)
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).