25#include <oox/token/namespaces.hxx>
31#include <document.hxx>
34#include <tokenarray.hxx>
45using ::std::unique_ptr;
47using ::com::sun::star::uno::Any;
63 explicit XclExpExtNameBase(
const XclExpRoot& rRoot,
64 const OUString& rName, sal_uInt16 nFlags = 0 );
83class XclExpExtNameAddIn :
public XclExpExtNameBase
86 explicit XclExpExtNameAddIn(
const XclExpRoot& rRoot,
const OUString& rName );
90 virtual void WriteAddData(
XclExpStream& rStrm )
override;
94class XclExpExtNameDde :
public XclExpExtNameBase
97 explicit XclExpExtNameDde(
const XclExpRoot& rRoot,
const OUString& rName,
98 sal_uInt16 nFlags,
const ScMatrix* pResults =
nullptr );
102 virtual void WriteAddData(
XclExpStream& rStrm )
override;
105 typedef std::shared_ptr< XclExpCachedMatrix > XclExpCachedMatRef;
106 XclExpCachedMatRef mxMatrix;
111class XclExpExtName :
public XclExpExtNameBase
114 explicit XclExpExtName(
const XclExpRoot& rRoot,
const XclExpSupbook& rSupbook,
const OUString& rName,
121 virtual void WriteAddData(
XclExpStream& rStrm )
override;
124 const XclExpSupbook& mrSupbook;
125 unique_ptr<ScTokenArray>
mpArray;
134 explicit XclExpExtNameBuffer(
const XclExpRoot& rRoot );
138 sal_uInt16 InsertAddIn(
const OUString& rName );
140 sal_uInt16 InsertEuroTool(
const OUString& rName );
143 sal_uInt16 InsertDde( std::u16string_view rApplic, std::u16string_view rTopic,
const OUString& rItem );
154 sal_uInt16 GetIndex( std::u16string_view rName )
const;
157 sal_uInt16 AppendNew( XclExpExtNameBase* pExtName );
168 explicit XclExpCrn(
SCCOL nScCol,
SCROW nScRow,
const Any& rValue );
171 bool InsertValue(
SCCOL nScCol,
SCROW nScRow,
const Any& rValue );
179 static void WriteBool(
XclExpStream& rStrm,
bool bValue );
180 static void WriteDouble(
XclExpStream& rStrm,
double fValue );
181 static void WriteString(
XclExpStream& rStrm,
const OUString& rValue );
186 typedef ::std::vector< Any > CachedValues;
201 const OUString& rTabName, sal_uInt16 nSBTab,
205 const XclExpString& GetTabName()
const {
return maTabName; }
208 void StoreCellRange(
const ScRange& rRange );
210 void StoreCell_(
const ScAddress& rCell );
211 void StoreCellRange_(
const ScRange& rRange );
227 bool BuildCrnList( XclExpCrnList& rCrnRecs );
242 explicit XclExpExternSheetBase(
const XclExpRoot& rRoot,
243 sal_uInt16 nRecId, sal_uInt32 nRecSize = 0 );
247 XclExpExtNameBuffer& GetExtNameBuffer();
254 typedef std::shared_ptr< XclExpExtNameBuffer > XclExpExtNameBfrRef;
255 XclExpExtNameBfrRef mxExtNameBfr;
263class XclExpExternSheet :
public XclExpExternSheetBase
269 explicit XclExpExternSheet(
const XclExpRoot& rRoot, std::u16string_view rTabName );
273 sal_uInt16 InsertAddIn(
const OUString& rName );
280 void Init( std::u16string_view rEncUrl );
291class XclExpSupbook :
public XclExpExternSheetBase
295 explicit XclExpSupbook(
const XclExpRoot& rRoot, sal_uInt16 nXclTabCount );
297 explicit XclExpSupbook(
const XclExpRoot& rRoot );
301 explicit XclExpSupbook(
const XclExpRoot& rRoot,
const OUString& rUrl );
303 explicit XclExpSupbook(
const XclExpRoot& rRoot,
const OUString& rApplic,
const OUString& rTopic );
306 bool IsUrlLink( std::u16string_view rUrl )
const;
308 bool IsDdeLink( std::u16string_view rApplic, std::u16string_view rTopic )
const;
311 sal_uInt16 nFirstSBTab, sal_uInt16 nLastSBTab )
const;
314 void StoreCellRange(
const ScRange& rRange, sal_uInt16 nSBTab );
316 void StoreCell_( sal_uInt16 nSBTab,
const ScAddress& rCell );
317 void StoreCellRange_( sal_uInt16 nSBTab,
const ScRange& rRange );
319 sal_uInt16 GetTabIndex(
const OUString& rTabName )
const;
320 sal_uInt16 GetTabCount()
const;
326 sal_uInt16 InsertAddIn(
const OUString& rName );
328 sal_uInt16 InsertEuroTool(
const OUString& rName );
331 sal_uInt16 InsertDde(
const OUString& rItem );
339 sal_uInt16 GetFileId()
const;
342 const OUString& GetUrl()
const;
352 const XclExpString* GetTabName( sal_uInt16 nSBTab )
const;
361 XclExpXctList maXctList;
366 sal_uInt16 mnXclTabCount;
377 sal_uInt16 mnSupbook;
378 sal_uInt16 mnFirstSBTab;
379 sal_uInt16 mnLastSBTab;
381 explicit XclExpXti() : mnSupbook( 0 ), mnFirstSBTab( 0 ), mnLastSBTab( 0 ) {}
382 explicit XclExpXti( sal_uInt16 nSupbook, sal_uInt16 nFirstSBTab, sal_uInt16 nLastSBTab ) :
383 mnSupbook( nSupbook ), mnFirstSBTab( nFirstSBTab ), mnLastSBTab( nLastSBTab ) {}
387 {
rStrm << mnSupbook << mnFirstSBTab << mnLastSBTab; }
390bool operator==(
const XclExpXti& rLeft,
const XclExpXti& rRight )
393 (rLeft.mnSupbook == rRight.mnSupbook) &&
394 (rLeft.mnFirstSBTab == rRight.mnFirstSBTab) &&
395 (rLeft.mnLastSBTab == rRight.mnLastSBTab);
402 explicit XclExpSupbookBuffer(
const XclExpRoot& rRoot );
406 XclExpXti GetXti( sal_uInt16 nFirstXclTab, sal_uInt16 nLastXclTab,
410 void StoreCellRange(
const ScRange& rRange );
412 void StoreCell( sal_uInt16 nFileId,
const OUString& rTabName,
const ScAddress& rCell );
413 void StoreCellRange( sal_uInt16 nFileId,
const OUString& rTabName,
const ScRange& rRange );
419 sal_uInt16& rnSupbook, sal_uInt16& rnExtName,
420 const OUString& rName );
423 sal_uInt16& rnSupbook, sal_uInt16& rnExtName,
424 const OUString& rName );
429 sal_uInt16& rnSupbook, sal_uInt16& rnExtName,
430 const OUString& rApplic,
const OUString& rTopic,
const OUString& rItem );
433 sal_uInt16& rnSupbook, sal_uInt16& rnExtName,
const OUString& rUrl,
436 XclExpXti GetXti( sal_uInt16 nFileId,
const OUString& rTabName, sal_uInt16 nXclTabSpan,
446 bool HasExternalReferences()
const;
450 sal_uInt16 mnSupbook;
452 void Set( sal_uInt16 nSupbook, sal_uInt16 nSBTab )
453 { mnSupbook = nSupbook; mnSBTab = nSBTab; }
465 bool GetSupbookUrl( XclExpSupbookRef& rxSupbook, sal_uInt16& rnIndex,
466 std::u16string_view rUrl )
const;
471 bool GetSupbookDde( XclExpSupbookRef& rxSupbook, sal_uInt16& rnIndex,
472 std::u16string_view rApplic, std::u16string_view rTopic )
const;
476 sal_uInt16
Append( XclExpSupbookRef
const & xSupbook );
479 XclExpSupbookList maSupbookList;
480 std::vector< XclExpSBIndex >
482 sal_uInt16 mnOwnDocSB;
483 sal_uInt16 mnAddInSB;
496 sal_uInt16& rnFirstXclTab, sal_uInt16& rnLastXclTab,
502 virtual void FindExtSheet( sal_uInt16 nFileId,
const OUString& rTabName, sal_uInt16 nXclTabSpan,
503 sal_uInt16& rnExtSheet, sal_uInt16& rnFirstSBTab, sal_uInt16& rnLastSBTab,
514 sal_uInt16& rnExtSheet, sal_uInt16& rnExtName,
515 const OUString& rName ) = 0;
518 sal_uInt16& rnExtSheet, sal_uInt16& rnExtName,
519 const OUString& rName ) = 0;
523 sal_uInt16& rnExtSheet, sal_uInt16& rnExtName,
524 const OUString& rApplic,
const OUString& rTopic,
const OUString& rItem ) = 0;
527 sal_uInt16& rnExtSheet, sal_uInt16& rnExtName,
const OUString& rUrl,
546 explicit XclExpLinkManagerImpl5(
const XclExpRoot& rRoot );
549 sal_uInt16& rnFirstXclTab, sal_uInt16& rnLastXclTab,
554 virtual void FindExtSheet( sal_uInt16 nFileId,
const OUString& rTabName, sal_uInt16 nXclTabSpan,
555 sal_uInt16& rnExtSheet, sal_uInt16& rnFirstSBTab, sal_uInt16& rnLastSBTab,
560 virtual void StoreCell( sal_uInt16 nFileId,
const OUString& rTabName,
const ScAddress& rPos )
override;
561 virtual void StoreCellRange( sal_uInt16 nFileId,
const OUString& rTabName,
const ScRange& rRange )
override;
564 sal_uInt16& rnExtSheet, sal_uInt16& rnExtName,
565 const OUString& rName )
override;
569 sal_uInt16& rnExtSheet, sal_uInt16& rnExtName,
570 const OUString& rName )
override;
573 sal_uInt16& rnExtSheet, sal_uInt16& rnExtName,
574 const OUString& rApplic,
const OUString& rTopic,
const OUString& rItem )
override;
577 sal_uInt16& rnExtSheet, sal_uInt16& rnExtName,
const OUString& rUrl,
587 typedef ::std::map< SCTAB, sal_uInt16 > XclExpIntTabMap;
588 typedef ::std::map< sal_Unicode, sal_uInt16 > XclExpCodeMap;
592 sal_uInt16 GetExtSheetCount()
const;
595 sal_uInt16 AppendInternal( XclExpExtSheetRef
const & xExtSheet );
597 void CreateInternal();
600 XclExpExtSheetRef GetInternal( sal_uInt16 nExtSheet );
602 XclExpExtSheetRef FindInternal( sal_uInt16& rnExtSheet, sal_uInt16& rnXclTab,
SCTAB nScTab );
604 XclExpExtSheetRef FindInternal( sal_uInt16& rnExtSheet,
sal_Unicode cCode );
607 XclExpExtSheetList maExtSheetList;
608 XclExpIntTabMap maIntTabMap;
609 XclExpCodeMap maCodeMap;
616 explicit XclExpLinkManagerImpl8(
const XclExpRoot& rRoot );
619 sal_uInt16& rnFirstXclTab, sal_uInt16& rnLastXclTab,
624 virtual void FindExtSheet( sal_uInt16 nFileId,
const OUString& rTabName, sal_uInt16 nXclTabSpan,
625 sal_uInt16& rnExtSheet, sal_uInt16& rnFirstSBTab, sal_uInt16& rnLastSBTab,
630 virtual void StoreCell( sal_uInt16 nFileId,
const OUString& rTabName,
const ScAddress& rPos )
override;
631 virtual void StoreCellRange( sal_uInt16 nFileId,
const OUString& rTabName,
const ScRange& rRange )
override;
634 sal_uInt16& rnExtSheet, sal_uInt16& rnExtName,
635 const OUString& rName )
override;
638 sal_uInt16& rnExtSheet, sal_uInt16& rnExtName,
639 const OUString& rName )
override;
642 sal_uInt16& rnExtSheet, sal_uInt16& rnExtName,
643 const OUString& rApplic,
const OUString& rTopic,
const OUString& rItem )
override;
646 sal_uInt16& rnExtSheet, sal_uInt16& rnExtName,
const OUString& rUrl,
656 sal_uInt16 InsertXti(
const XclExpXti& rXti );
660 XclExpSupbookBuffer maSBBuffer;
661 std::vector< XclExpXti > maXtiVec;
678 mnFirstVisXclTab( 0 )
692 for( nScTab = 0; nScTab <
mnScCnt; ++nScTab )
714 nFirstExpScTab = nScTab;
717 nFirstVisScTab = nScTab;
736 if (nDisplScTab == -1 )
743 nFirstVisScTab = nFirstExpScTab;
747 nFirstVisScTab = nDisplScTab;
755 nDisplScTab = nFirstVisScTab;
759 for( nScTab = 0; nScTab <
mnScCnt; ++nScTab )
799 OSL_ENSURE( nScTab < mnScCnt && nScTab >= 0,
"XclExpTabInfo::IsActiveTab - sheet out of range" );
810 OSL_ENSURE( nScTab < mnScCnt && nScTab >= 0,
"XclExpTabInfo::IsActiveTab - sheet out of range" );
811 return (nScTab < mnScCnt && nScTab >= 0) ?
maTabInfoVec[ nScTab ].maScName : OUString();
821 OSL_ENSURE( nSortedScTab < mnScCnt && nSortedScTab >= 0,
"XclExpTabInfo::GetRealScTab - sheet out of range" );
827 OSL_ENSURE( nScTab < mnScCnt && nScTab >= 0,
"XclExpTabInfo::GetFlag - sheet out of range" );
828 return (nScTab < mnScCnt && nScTab >= 0) && (
maTabInfoVec[ nScTab ].mnFlags & nFlags);
833 OSL_ENSURE( nScTab < mnScCnt && nScTab >= 0,
"XclExpTabInfo::SetFlag - sheet out of range" );
834 if( nScTab < mnScCnt && nScTab >= 0 )
845 sal_uInt16 nXclTab = 0;
849 for( nScTab = 0; nScTab <
mnScCnt; ++nScTab )
862 for( nScTab = 0; nScTab <
mnScCnt; ++nScTab )
879struct XclExpTabNameSort {
892 ::std::vector< XclExpTabName > aVec(
mnScCnt );
896 for( nScTab = 0; nScTab <
mnScCnt; ++nScTab )
899 aVec[ nScTab ].second = nScTab;
901 ::std::sort( aVec.begin(), aVec.end(), XclExpTabNameSort() );
906 for( nScTab = 0; nScTab <
mnScCnt; ++nScTab )
915XclExpExtNameBase::XclExpExtNameBase(
916 const XclExpRoot& rRoot,
const OUString& rName, sal_uInt16 nFlags ) :
923 OSL_ENSURE(
maName.getLength() <= 255,
"XclExpExtNameBase::XclExpExtNameBase - string too long" );
924 SetRecSize( 6 + mxName->GetSize() );
932 WriteAddData( rStrm );
939XclExpExtNameAddIn::XclExpExtNameAddIn(
const XclExpRoot& rRoot,
const OUString& rName ) :
940 XclExpExtNameBase( rRoot, rName )
945void XclExpExtNameAddIn::WriteAddData(
XclExpStream& rStrm )
951XclExpExtNameDde::XclExpExtNameDde(
const XclExpRoot& rRoot,
952 const OUString& rName, sal_uInt16 nFlags,
const ScMatrix* pResults ) :
953 XclExpExtNameBase( rRoot, rName, nFlags )
957 mxMatrix = std::make_shared<XclExpCachedMatrix>( *pResults );
958 AddRecSize( mxMatrix->GetSize() );
962void XclExpExtNameDde::WriteAddData(
XclExpStream& rStrm )
965 mxMatrix->Save( rStrm );
968XclExpExtName::XclExpExtName(
const XclExpRoot& rRoot,
const XclExpSupbook& rSupbook,
970 XclExpExtNameBase( rRoot, rName ),
989 if (!
p->IsExternalRef())
992 switch (
p->GetType())
1002 sal_uInt16 nCol =
static_cast<sal_uInt16
>(rRef.
Col());
1003 sal_uInt16 nRow =
static_cast<sal_uInt16
>(rRef.
Row());
1004 if (bColRel) nCol |= 0x4000;
1005 if (bRowRel) nCol |= 0x8000;
1007 OUString aTabName =
p->GetString().getString();
1008 sal_uInt16 nSBTab = mrSupbook.GetTabIndex(aTabName);
1011 rStrm << static_cast<sal_uInt16>(9);
1013 rStrm << static_cast<sal_uInt8>(0x3A);
1015 rStrm << nSBTab << nSBTab << nRow << nCol;
1026 sal_uInt16 nTab1 = r1.
Tab();
1027 sal_uInt16 nTab2 = r2.
Tab();
1033 sal_uInt16 nCol1 =
static_cast<sal_uInt16
>(r1.
Col());
1034 sal_uInt16 nCol2 =
static_cast<sal_uInt16
>(r2.
Col());
1035 sal_uInt16 nRow1 =
static_cast<sal_uInt16
>(r1.
Row());
1036 sal_uInt16 nRow2 =
static_cast<sal_uInt16
>(r2.
Row());
1037 if (bCol1Rel) nCol1 |= 0x4000;
1038 if (bRow1Rel) nCol1 |= 0x8000;
1039 if (bCol2Rel) nCol2 |= 0x4000;
1040 if (bRow2Rel) nCol2 |= 0x8000;
1042 OUString aTabName =
p->GetString().getString();
1043 sal_uInt16 nSBTab = mrSupbook.GetTabIndex(aTabName);
1046 rStrm << static_cast<sal_uInt16>(13);
1048 rStrm << static_cast<sal_uInt8>(0x3B);
1050 sal_uInt16 nSBTab2 = nSBTab + nTab2 - nTab1;
1051 rStrm << nSBTab << nSBTab2 << nRow1 << nRow2 << nCol1 << nCol2;
1073 pExternalLink->startElement(XML_definedName,
1074 XML_name,
maName.toUtf8(),
1075 XML_refersTo, aFormula.toUtf8(),
1076 XML_sheetId,
nullptr);
1080 pExternalLink->startElement(XML_definedName,
1081 XML_name,
maName.toUtf8(),
1082 XML_refersTo,
nullptr,
1083 XML_sheetId,
nullptr);
1086 pExternalLink->endElement(XML_definedName);
1091XclExpExtNameBuffer::XclExpExtNameBuffer(
const XclExpRoot& rRoot ) :
1096sal_uInt16 XclExpExtNameBuffer::InsertAddIn(
const OUString& rName )
1098 sal_uInt16
nIndex = GetIndex( rName );
1099 return nIndex ?
nIndex : AppendNew(
new XclExpExtNameAddIn( GetRoot(), rName ) );
1102sal_uInt16 XclExpExtNameBuffer::InsertEuroTool(
const OUString& rName )
1104 sal_uInt16
nIndex = GetIndex( rName );
1105 return nIndex ?
nIndex : AppendNew(
new XclExpExtNameBase( GetRoot(), rName ) );
1108sal_uInt16 XclExpExtNameBuffer::InsertDde(
1109 std::u16string_view rApplic, std::u16string_view rTopic,
const OUString& rItem )
1111 sal_uInt16
nIndex = GetIndex( rItem );
1118 if( maNameList.IsEmpty() )
1119 AppendNew(
new XclExpExtNameDde(
1123 const ScMatrix* pScMatrix = GetDoc().GetDdeLinkResultMatrix( nPos );
1130sal_uInt16 XclExpExtNameBuffer::InsertExtName(
const XclExpSupbook& rSupbook,
1133 sal_uInt16
nIndex = GetIndex( rName );
1134 return nIndex ?
nIndex : AppendNew(
new XclExpExtName( GetRoot(), rSupbook, rName, rArray ) );
1139 maNameList.Save( rStrm );
1144 maNameList.SaveXml(rStrm);
1147sal_uInt16 XclExpExtNameBuffer::GetIndex( std::u16string_view rName )
const
1149 for(
size_t nPos = 0, nSize = maNameList.GetSize(); nPos < nSize; ++nPos )
1150 if( maNameList.GetRecord( nPos )->GetName() == rName )
1151 return static_cast< sal_uInt16
>(
nPos + 1 );
1155sal_uInt16 XclExpExtNameBuffer::AppendNew( XclExpExtNameBase* pExtName )
1157 size_t nSize = maNameList.GetSize();
1158 if( nSize < 0x7FFF )
1160 maNameList.AppendRecord( pExtName );
1161 return static_cast< sal_uInt16
>( nSize + 1 );
1168XclExpCrn::XclExpCrn(
SCCOL nScCol,
SCROW nScRow,
const Any& rValue ) :
1176bool XclExpCrn::InsertValue(
SCCOL nScCol,
SCROW nScRow,
const Any& rValue )
1178 if( (nScRow != mnScRow) || (nScCol !=
static_cast< SCCOL >( mnScCol +
maValues.size() )) )
1186 rStrm << static_cast< sal_uInt8 >( mnScCol +
maValues.size() - 1 )
1188 <<
static_cast< sal_uInt16
>( mnScRow );
1189 for(
const auto& rValue : maValues )
1191 if( rValue.has<
bool >() )
1192 WriteBool( rStrm, rValue.get<
bool >() );
1193 else if( rValue.has<
double >() )
1194 WriteDouble( rStrm, rValue.get<
double >() );
1195 else if( rValue.has< OUString >() )
1196 WriteString( rStrm, rValue.get< OUString >() );
1198 WriteEmpty( rStrm );
1202void XclExpCrn::WriteBool(
XclExpStream& rStrm,
bool bValue )
1205 rStrm.WriteZeroBytes( 7 );
1208void XclExpCrn::WriteDouble(
XclExpStream& rStrm,
double fValue )
1210 if( !std::isfinite( fValue ) )
1221void XclExpCrn::WriteString(
XclExpStream& rStrm,
const OUString& rValue )
1229 rStrm.WriteZeroBytes( 7 );
1235 rStrm.WriteZeroBytes( 8 );
1242 pFS->startElement(XML_row, XML_r, OString::number(mnScRow + 1));
1245 for(
const auto& rValue : maValues )
1247 bool bCloseCell =
true;
1248 if( rValue.has<
double >() )
1250 double fVal = rValue.get<
double >();
1251 if (std::isfinite( fVal))
1255 pFS->startElement(XML_v);
1261 pFS->startElement(XML_v);
1262 pFS->write(
"#VALUE!" );
1265 else if( rValue.has< OUString >() )
1268 pFS->startElement(XML_v);
1269 pFS->write( rValue.get< OUString >() );
1271 else if( rValue.has<
bool >() )
1274 pFS->startElement(XML_v);
1275 pFS->write( rValue.get<
bool >() ?
"1" :
"0" );
1285 pFS->endElement(XML_v);
1286 pFS->endElement(XML_cell);
1291 pFS->endElement( XML_row);
1296XclExpXct::XclExpXct(
const XclExpRoot& rRoot,
const OUString& rTabName,
1299 mxCacheTable(
std::move( xCacheTable )),
1300 maUsedCells( rRoot.GetDoc().GetSheetLimits() ),
1301 maBoundRange(
ScAddress::INITIALIZE_INVALID ),
1302 maTabName( rTabName ),
1307void XclExpXct::StoreCellRange(
const ScRange& rRange )
1313 maUsedCells.SetMultiMarkArea( rRange );
1314 maBoundRange.ExtendTo( rRange );
1317void XclExpXct::StoreCell_(
const ScAddress& rCell )
1319 maUsedCells.SetMultiMarkArea(
ScRange( rCell ) );
1320 maBoundRange.ExtendTo(
ScRange( rCell ) );
1323void XclExpXct::StoreCellRange_(
const ScRange& rRange )
1325 maUsedCells.SetMultiMarkArea( rRange );
1326 maBoundRange.ExtendTo( rRange );
1336 bool InsertValue(
SCCOL nScCol,
SCROW nScRow,
const Any& rValue );
1339bool XclExpCrnList::InsertValue(
SCCOL nScCol,
SCROW nScRow,
const Any& rValue )
1341 RecordRefType xLastRec = GetLastRecord();
1342 if( xLastRec && xLastRec->InsertValue( nScCol, nScRow, rValue ) )
1344 if( GetSize() == SAL_MAX_UINT16 )
1346 AppendNewRecord(
new XclExpCrn( nScCol, nScRow, rValue ) );
1352bool XclExpXct::BuildCrnList( XclExpCrnList& rCrnRecs )
1361 ::std::pair< SCROW, SCROW > aRowRange = mxCacheTable->getRowRange();
1362 if( aRowRange.first >= aRowRange.second )
1367 if( !GetAddressConverter().ValidateRange( maBoundRange,
false ) )
1371 SCROW nScRow1 = ::std::max( aRowRange.first, maBoundRange.aStart.Row() );
1372 SCROW nScRow2 = ::std::min( aRowRange.second - 1, maBoundRange.aEnd.Row() );
1373 if( nScRow1 > nScRow2 )
1382 for(
SCROW nScRow = nScRow1; bValid && (nScRow <= nScRow2); ++nScRow )
1384 ::std::pair< SCCOL, SCCOL > aColRange = mxCacheTable->getColRange( nScRow );
1385 const SCCOL nScEnd = ::std::min( aColRange.second, GetDoc().GetSheetLimits().GetMaxColCount() );
1386 for(
SCCOL nScCol = aColRange.first; bValid && (nScCol < nScEnd); ++nScCol )
1388 if( maUsedCells.IsCellMarked( nScCol, nScRow,
true ) )
1390 sal_uInt32 nScNumFmt = 0;
1394 switch( xToken->GetType() )
1397 bValid = (rFormatter.
GetType( nScNumFmt ) == SvNumFormatType::LOGICAL) ?
1398 rCrnRecs.InsertValue( nScCol, nScRow,
Any( xToken->GetDouble() != 0 ) ) :
1399 rCrnRecs.InsertValue( nScCol, nScRow,
Any( xToken->GetDouble() ) );
1403 if( !xToken->GetString().isEmpty() )
1404 bValid = rCrnRecs.InsertValue( nScCol, nScRow,
Any( xToken->GetString().getString() ) );
1417 XclExpCrnList aCrnRecs;
1418 if (!BuildCrnList( aCrnRecs))
1423 rStrm << static_cast< sal_uInt16 >( aCrnRecs.GetSize() ) << mnSBTab;
1425 aCrnRecs.Save( rStrm );
1430 XclExpCrnList aCrnRecs;
1434 bool bValid = BuildCrnList( aCrnRecs);
1435 pFS->startElement(XML_sheetData, XML_sheetId, OString::number(mnSBTab));
1439 aCrnRecs.SaveXml( rStrm );
1441 pFS->endElement( XML_sheetData);
1446XclExpExternSheetBase::XclExpExternSheetBase(
const XclExpRoot& rRoot, sal_uInt16 nRecId, sal_uInt32 nRecSize ) :
1452XclExpExtNameBuffer& XclExpExternSheetBase::GetExtNameBuffer()
1455 mxExtNameBfr = std::make_shared<XclExpExtNameBuffer>( GetRoot() );
1456 return *mxExtNameBfr;
1459void XclExpExternSheetBase::WriteExtNameBuffer(
XclExpStream& rStrm )
1462 mxExtNameBfr->Save( rStrm );
1465void XclExpExternSheetBase::WriteExtNameBufferXml(
XclExpXmlStream& rStrm )
1468 mxExtNameBfr->SaveXml( rStrm );
1476 Init( OUStringChar(cCode) );
1479XclExpExternSheet::XclExpExternSheet(
const XclExpRoot& rRoot, std::u16string_view rTabName ) :
1491 WriteExtNameBuffer( rStrm );
1494void XclExpExternSheet::Init( std::u16string_view rEncUrl )
1498 SetRecSize( maTabName.GetSize() );
1501sal_uInt16 XclExpExternSheet::InsertAddIn(
const OUString& rName )
1503 return GetExtNameBuffer().InsertAddIn( rName );
1506void XclExpExternSheet::WriteBody(
XclExpStream& rStrm )
1513 maTabName.WriteBuffer( rStrm );
1518XclExpSupbook::XclExpSupbook(
const XclExpRoot& rRoot, sal_uInt16 nXclTabCount ) :
1521 mnXclTabCount( nXclTabCount ),
1526XclExpSupbook::XclExpSupbook(
const XclExpRoot& rRoot ) :
1537 maUrlEncoded( rUrl ),
1542 SetRecSize( 2 + maUrlEncoded.GetSize() );
1545XclExpSupbook::XclExpSupbook(
const XclExpRoot& rRoot,
const OUString& rUrl ) :
1553 SetRecSize( 2 + maUrlEncoded.GetSize() );
1558 mnFileId = nFileId + 1;
1561 size_t nTabIndex = 0;
1562 for(
const auto& rTabName : aTabNames )
1564 InsertTabName( rTabName, pRefMgr->
getCacheTable( nFileId, nTabIndex ) );
1569XclExpSupbook::XclExpSupbook(
const XclExpRoot& rRoot,
const OUString& rApplic,
const OUString& rTopic ) :
1572 maDdeTopic( rTopic ),
1578 SetRecSize( 2 + maUrlEncoded.GetSize() );
1581bool XclExpSupbook::IsUrlLink( std::u16string_view rUrl )
const
1586bool XclExpSupbook::IsDdeLink( std::u16string_view rApplic, std::u16string_view rTopic )
const
1592 sal_uInt16 nFirstSBTab, sal_uInt16 nLastSBTab )
const
1594 rRefLogEntry.
mpUrl = maUrlEncoded.
IsEmpty() ? nullptr : &maUrlEncoded;
1595 rRefLogEntry.
mpFirstTab = GetTabName( nFirstSBTab );
1596 rRefLogEntry.
mpLastTab = GetTabName( nLastSBTab );
1599void XclExpSupbook::StoreCellRange(
const ScRange& rRange, sal_uInt16 nSBTab )
1601 if( XclExpXct* pXct = maXctList.GetRecord( nSBTab ) )
1602 pXct->StoreCellRange( rRange );
1605void XclExpSupbook::StoreCell_( sal_uInt16 nSBTab,
const ScAddress& rCell )
1607 if( XclExpXct* pXct = maXctList.GetRecord( nSBTab ) )
1608 pXct->StoreCell_( rCell );
1611void XclExpSupbook::StoreCellRange_( sal_uInt16 nSBTab,
const ScRange& rRange )
1615 if( XclExpXct* pXct = maXctList.GetRecord( nSBTab ) )
1616 pXct->StoreCellRange_( rRange );
1619sal_uInt16 XclExpSupbook::GetTabIndex(
const OUString& rTabName )
const
1622 size_t nSize = maXctList.GetSize();
1623 for (
size_t i = 0;
i < nSize; ++
i)
1625 XclExpXctRef aRec = maXctList.GetRecord(i);
1626 if (aXclName == aRec->GetTabName())
1627 return ulimit_cast<sal_uInt16>(i);
1632sal_uInt16 XclExpSupbook::GetTabCount()
const
1634 return ulimit_cast<sal_uInt16>(maXctList.GetSize());
1640 sal_uInt16 nSBTab = ulimit_cast< sal_uInt16 >( maXctList.GetSize() );
1641 XclExpXctRef xXct =
new XclExpXct( GetRoot(), rTabName, nSBTab, xCacheTable );
1642 AddRecSize( xXct->GetTabName().GetSize() );
1643 maXctList.AppendRecord( xXct );
1647sal_uInt16 XclExpSupbook::InsertAddIn(
const OUString& rName )
1649 return GetExtNameBuffer().InsertAddIn( rName );
1652sal_uInt16 XclExpSupbook::InsertEuroTool(
const OUString& rName )
1654 return GetExtNameBuffer().InsertEuroTool( rName );
1657sal_uInt16 XclExpSupbook::InsertDde(
const OUString& rItem )
1659 return GetExtNameBuffer().InsertDde( maUrl, maDdeTopic, rItem );
1664 return GetExtNameBuffer().InsertExtName(*
this, rName, rArray);
1672sal_uInt16 XclExpSupbook::GetFileId()
const
1677const OUString& XclExpSupbook::GetUrl()
const
1687 maXctList.Save( rStrm );
1689 WriteExtNameBuffer( rStrm );
1697 sal_uInt16 nLevel = 0;
1703 while (nLevel-- > 0)
1704 sFile =
"../" + sFile;
1706 OUString
sId =
rStrm.addRelation( pExternalLink->getOutputStream(),
1709 pExternalLink->startElement( XML_externalLink,
1710 XML_xmlns,
rStrm.getNamespaceURL(OOX_NS(xls)).toUtf8());
1712 pExternalLink->startElement( XML_externalBook,
1713 FSNS(XML_xmlns, XML_r),
rStrm.getNamespaceURL(OOX_NS(officeRel)).toUtf8(),
1714 FSNS(XML_r, XML_id),
sId.toUtf8());
1716 if (!maXctList.IsEmpty())
1718 pExternalLink->startElement(XML_sheetNames);
1719 for (
size_t nPos = 0, nSize = maXctList.GetSize(); nPos < nSize; ++nPos)
1721 pExternalLink->singleElement(XML_sheetName,
1724 pExternalLink->endElement( XML_sheetNames);
1730 pExternalLink->startElement(XML_definedNames);
1732 WriteExtNameBufferXml( rStrm );
1733 pExternalLink->endElement(XML_definedNames);
1736 if (!maXctList.IsEmpty())
1738 pExternalLink->startElement(XML_sheetDataSet);
1741 maXctList.SaveXml( rStrm );
1743 pExternalLink->endElement( XML_sheetDataSet);
1746 pExternalLink->endElement( XML_externalBook);
1747 pExternalLink->endElement( XML_externalLink);
1750const XclExpString* XclExpSupbook::GetTabName( sal_uInt16 nSBTab )
const
1752 XclExpXctRef xXct = maXctList.GetRecord( nSBTab );
1753 return xXct ? &xXct->GetTabName() :
nullptr;
1767 sal_uInt16
nCount = ulimit_cast< sal_uInt16 >( maXctList.GetSize() );
1770 for(
size_t nPos = 0, nSize = maXctList.GetSize(); nPos < nSize; ++nPos )
1771 rStrm << maXctList.GetRecord( nPos )->GetTabName();
1778 SAL_WARN(
"sc.filter",
"Unhandled SUPBOOK type " << meType);
1784XclExpSupbookBuffer::XclExpSupbookBuffer(
const XclExpRoot& rRoot ) :
1794 OSL_ENSURE( nCount > 0,
"XclExpSupbookBuffer::XclExpSupbookBuffer - no sheets to export" );
1797 maSBIndexVec.resize( nCount );
1800 XclExpSupbookRef xSupbook =
new XclExpSupbook(
GetRoot(), ::std::max( nXclCnt, nCodeCnt ) );
1801 mnOwnDocSB =
Append( xSupbook );
1802 for( sal_uInt16 nXclTab = 0; nXclTab < nXclCnt; ++nXclTab )
1803 maSBIndexVec[ nXclTab ].
Set( mnOwnDocSB, nXclTab );
1807XclExpXti XclExpSupbookBuffer::GetXti( sal_uInt16 nFirstXclTab, sal_uInt16 nLastXclTab,
1811 size_t nSize = maSBIndexVec.size();
1812 if( (nFirstXclTab < nSize) && (nLastXclTab < nSize) )
1815 aXti.mnSupbook = maSBIndexVec[ nFirstXclTab ].mnSupbook;
1818 bool bSameSB =
true;
1819 for( sal_uInt16 nXclTab = nFirstXclTab + 1; bSameSB && (nXclTab <= nLastXclTab); ++nXclTab )
1821 bSameSB = maSBIndexVec[ nXclTab ].mnSupbook == aXti.mnSupbook;
1823 nLastXclTab = nXclTab - 1;
1825 aXti.mnFirstSBTab = maSBIndexVec[ nFirstXclTab ].mnSBTab;
1826 aXti.mnLastSBTab = maSBIndexVec[ nLastXclTab ].mnSBTab;
1833 XclExpSupbookRef xSupbook = maSupbookList.GetRecord( aXti.mnSupbook );
1835 xSupbook->FillRefLogEntry( *pRefLogEntry, aXti.mnFirstSBTab, aXti.mnLastSBTab );
1841 aXti.mnSupbook = mnOwnDocSB;
1842 aXti.mnFirstSBTab = nFirstXclTab;
1843 aXti.mnLastSBTab = nLastXclTab;
1849void XclExpSupbookBuffer::StoreCellRange(
const ScRange& rRange )
1851 sal_uInt16 nXclTab = GetTabInfo().GetXclTab( rRange.
aStart.
Tab() );
1852 if( nXclTab < maSBIndexVec.size() )
1854 const XclExpSBIndex& rSBIndex = maSBIndexVec[ nXclTab ];
1855 XclExpSupbookRef xSupbook = maSupbookList.GetRecord( rSBIndex.mnSupbook );
1856 OSL_ENSURE( xSupbook ,
"XclExpSupbookBuffer::StoreCellRange - missing SUPBOOK record" );
1858 xSupbook->StoreCellRange( rRange, rSBIndex.mnSBTab );
1864class FindSBIndexEntry
1867 explicit FindSBIndexEntry(sal_uInt16 nSupbookId, sal_uInt16 nTabId) :
1868 mnSupbookId(nSupbookId), mnTabId(nTabId) {}
1870 bool operator()(
const XclExpSupbookBuffer::XclExpSBIndex& r)
const
1872 return mnSupbookId == r.mnSupbook && mnTabId == r.mnSBTab;
1876 sal_uInt16 mnSupbookId;
1882void XclExpSupbookBuffer::StoreCell( sal_uInt16 nFileId,
const OUString& rTabName,
const ScAddress& rCell )
1889 XclExpSupbookRef xSupbook;
1890 sal_uInt16 nSupbookId;
1891 if (!GetSupbookUrl(xSupbook, nSupbookId, *pUrl))
1893 xSupbook =
new XclExpSupbook(GetRoot(), *pUrl);
1894 nSupbookId =
Append(xSupbook);
1897 sal_uInt16 nSheetId = xSupbook->GetTabIndex(rTabName);
1902 FindSBIndexEntry f(nSupbookId, nSheetId);
1903 if (::std::none_of(maSBIndexVec.begin(), maSBIndexVec.end(), f))
1905 maSBIndexVec.emplace_back();
1906 XclExpSBIndex& r = maSBIndexVec.back();
1907 r.mnSupbook = nSupbookId;
1908 r.mnSBTab = nSheetId;
1911 xSupbook->StoreCell_(nSheetId, rCell);
1914void XclExpSupbookBuffer::StoreCellRange( sal_uInt16 nFileId,
const OUString& rTabName,
const ScRange& rRange )
1921 XclExpSupbookRef xSupbook;
1922 sal_uInt16 nSupbookId;
1923 if (!GetSupbookUrl(xSupbook, nSupbookId, *pUrl))
1925 xSupbook =
new XclExpSupbook(GetRoot(), *pUrl);
1926 nSupbookId =
Append(xSupbook);
1933 SCTAB aMatrixListSize = 0;
1940 FormulaTokenArrayPlainIterator aIter(*pArray);
1941 for (FormulaToken* p = aIter.First(); p; p = aIter.Next())
1943 if (
p->GetType() == svMatrix)
1945 else if (
p->GetOpCode() != ocSep)
1952 if (aMatrixListSize != nTabCount)
1958 sal_uInt16 nFirstSheetId = xSupbook->GetTabIndex(rTabName);
1961 aRange.aStart.SetTab(0);
1962 aRange.aEnd.SetTab(0);
1963 for (
SCTAB nTab = 0; nTab < nTabCount; ++nTab)
1965 sal_uInt16 nSheetId = nFirstSheetId +
static_cast<sal_uInt16
>(nTab);
1966 FindSBIndexEntry f(nSupbookId, nSheetId);
1967 if (::std::none_of(maSBIndexVec.begin(), maSBIndexVec.end(), f))
1969 maSBIndexVec.emplace_back();
1970 XclExpSBIndex& r = maSBIndexVec.back();
1971 r.mnSupbook = nSupbookId;
1972 r.mnSBTab = nSheetId;
1975 xSupbook->StoreCellRange_(nSheetId, aRange);
1979bool XclExpSupbookBuffer::InsertAddIn(
1980 sal_uInt16& rnSupbook, sal_uInt16& rnExtName,
const OUString& rName )
1982 XclExpSupbookRef xSupbook;
1983 if( mnAddInSB == SAL_MAX_UINT16 )
1985 xSupbook =
new XclExpSupbook( GetRoot() );
1986 mnAddInSB =
Append( xSupbook );
1989 xSupbook = maSupbookList.GetRecord( mnAddInSB );
1990 OSL_ENSURE( xSupbook,
"XclExpSupbookBuffer::InsertAddin - missing add-in supbook" );
1991 rnSupbook = mnAddInSB;
1992 rnExtName = xSupbook->InsertAddIn( rName );
1993 return rnExtName > 0;
1996bool XclExpSupbookBuffer::InsertEuroTool(
1997 sal_uInt16& rnSupbook, sal_uInt16& rnExtName,
const OUString& rName )
1999 XclExpSupbookRef xSupbook;
2000 OUString aUrl(
"\001\010EUROTOOL.XLA" );
2001 if( !GetSupbookUrl( xSupbook, rnSupbook, aUrl ) )
2004 rnSupbook =
Append( xSupbook );
2006 rnExtName = xSupbook->InsertEuroTool( rName );
2007 return rnExtName > 0;
2010bool XclExpSupbookBuffer::InsertDde(
2011 sal_uInt16& rnSupbook, sal_uInt16& rnExtName,
2012 const OUString& rApplic,
const OUString& rTopic,
const OUString& rItem )
2014 XclExpSupbookRef xSupbook;
2015 if( !GetSupbookDde( xSupbook, rnSupbook, rApplic, rTopic ) )
2017 xSupbook =
new XclExpSupbook( GetRoot(), rApplic, rTopic );
2018 rnSupbook =
Append( xSupbook );
2020 rnExtName = xSupbook->InsertDde( rItem );
2021 return rnExtName > 0;
2024bool XclExpSupbookBuffer::InsertExtName(
2025 sal_uInt16& rnSupbook, sal_uInt16& rnExtName,
const OUString& rUrl,
2028 XclExpSupbookRef xSupbook;
2029 if (!GetSupbookUrl(xSupbook, rnSupbook, rUrl))
2031 xSupbook =
new XclExpSupbook(GetRoot(), rUrl);
2032 rnSupbook =
Append(xSupbook);
2034 rnExtName = xSupbook->InsertExtName(rName, rArray);
2035 return rnExtName > 0;
2038XclExpXti XclExpSupbookBuffer::GetXti( sal_uInt16 nFileId,
const OUString& rTabName, sal_uInt16 nXclTabSpan,
2047 XclExpSupbookRef xSupbook;
2048 sal_uInt16 nSupbookId;
2049 if (!GetSupbookUrl(xSupbook, nSupbookId, *pUrl))
2051 xSupbook =
new XclExpSupbook(GetRoot(), *pUrl);
2052 nSupbookId =
Append(xSupbook);
2054 aXti.mnSupbook = nSupbookId;
2056 sal_uInt16 nFirstSheetId = xSupbook->GetTabIndex(rTabName);
2062 sal_uInt16 nSheetCount = xSupbook->GetTabCount();
2063 for (sal_uInt16 i = 0;
i < nXclTabSpan; ++
i)
2065 sal_uInt16 nSheetId = nFirstSheetId +
i;
2066 if (nSheetId >= nSheetCount)
2069 FindSBIndexEntry f(nSupbookId, nSheetId);
2070 if (::std::none_of(maSBIndexVec.begin(), maSBIndexVec.end(), f))
2072 maSBIndexVec.emplace_back();
2073 XclExpSBIndex& r = maSBIndexVec.back();
2074 r.mnSupbook = nSupbookId;
2075 r.mnSBTab = nSheetId;
2078 aXti.mnFirstSBTab = nSheetId;
2079 if (i == nXclTabSpan - 1)
2080 aXti.mnLastSBTab = nSheetId;
2088 xSupbook->FillRefLogEntry(*pRefLogEntry, aXti.mnFirstSBTab, aXti.mnLastSBTab);
2096 maSupbookList.Save( rStrm );
2104 vector<sal_uInt16> aExternFileIds;
2105 for (
size_t nPos = 0, nSize = maSupbookList.GetSize(); nPos < nSize; ++nPos)
2107 XclExpSupbookRef xRef(maSupbookList.GetRecord(nPos));
2111 aExternFileIds.push_back(xRef->GetFileId() - 1);
2113 if (aExternFileIds.size() > 0)
2116 ::std::map< sal_uInt16, OUString >
aMap;
2117 for (
size_t nPos = 0, nSize = maSupbookList.GetSize(); nPos < nSize; ++nPos)
2119 XclExpSupbookRef xRef( maSupbookList.GetRecord( nPos));
2123 sal_uInt16
nId = xRef->GetFileId();
2125 const OUString& rUrl = xRef->GetUrl();
2126 ::std::pair< ::std::map< sal_uInt16, OUString >::iterator,
bool > aInsert(
2127 aMap.insert( ::std::make_pair( nId, rUrl)));
2128 if (!aInsert.second)
2130 SAL_WARN(
"sc.filter",
"XclExpSupbookBuffer::SaveXml: file ID already used: " << nId <<
2131 " wanted for " << rUrl <<
" and is " << (*aInsert.first).second <<
2132 (rUrl == (*aInsert.first).second ?
" multiple Supbook not supported" :
""));
2139 rStrm.GetCurrentStream()->getOutputStream(),
2140 "application/vnd.openxmlformats-officedocument.spreadsheetml.externalLink+xml",
2145 rStrm.GetCurrentStream()->singleElement( XML_externalReference,
2146 FSNS(XML_r, XML_id),
sId.toUtf8() );
2149 rStrm.PushStream( pExternalLink );
2150 xRef->SaveXml( rStrm );
2155bool XclExpSupbookBuffer::HasExternalReferences()
const
2157 for (
size_t nPos = 0, nSize = maSupbookList.GetSize(); nPos < nSize; ++nPos)
2165bool XclExpSupbookBuffer::GetSupbookUrl(
2166 XclExpSupbookRef& rxSupbook, sal_uInt16& rnIndex, std::u16string_view rUrl )
const
2168 for(
size_t nPos = 0, nSize = maSupbookList.GetSize(); nPos < nSize; ++nPos )
2170 rxSupbook = maSupbookList.GetRecord( nPos );
2171 if( rxSupbook->IsUrlLink( rUrl ) )
2173 rnIndex = ulimit_cast< sal_uInt16 >( nPos );
2180bool XclExpSupbookBuffer::GetSupbookDde( XclExpSupbookRef& rxSupbook,
2181 sal_uInt16& rnIndex, std::u16string_view rApplic, std::u16string_view rTopic )
const
2183 for(
size_t nPos = 0, nSize = maSupbookList.GetSize(); nPos < nSize; ++nPos )
2185 rxSupbook = maSupbookList.GetRecord( nPos );
2186 if( rxSupbook->IsDdeLink( rApplic, rTopic ) )
2188 rnIndex = ulimit_cast< sal_uInt16 >( nPos );
2195sal_uInt16 XclExpSupbookBuffer::Append( XclExpSupbookRef
const & xSupbook )
2197 maSupbookList.AppendRecord( xSupbook );
2198 return ulimit_cast< sal_uInt16 >( maSupbookList.GetSize() - 1 );
2208XclExpLinkManagerImpl5::XclExpLinkManagerImpl5(
const XclExpRoot& rRoot ) :
2213void XclExpLinkManagerImpl5::FindExtSheet(
2214 sal_uInt16& rnExtSheet, sal_uInt16& rnFirstXclTab, sal_uInt16& rnLastXclTab,
2217 FindInternal( rnExtSheet, rnFirstXclTab, nFirstScTab );
2218 if( (rnFirstXclTab ==
EXC_TAB_DELETED) || (nFirstScTab == nLastScTab) )
2220 rnLastXclTab = rnFirstXclTab;
2224 sal_uInt16 nDummyExtSheet;
2225 FindInternal( nDummyExtSheet, rnLastXclTab, nLastScTab );
2228 OSL_ENSURE( !pRefLogEntry,
"XclExpLinkManagerImpl5::FindExtSheet - fill reflog entry not implemented" );
2231sal_uInt16 XclExpLinkManagerImpl5::FindExtSheet(
sal_Unicode cCode )
2233 sal_uInt16 nExtSheet;
2234 FindInternal( nExtSheet, cCode );
2238void XclExpLinkManagerImpl5::FindExtSheet(
2239 sal_uInt16 ,
const OUString& , sal_uInt16 ,
2240 sal_uInt16& , sal_uInt16& , sal_uInt16& ,
2251void XclExpLinkManagerImpl5::StoreCell( sal_uInt16 ,
const OUString& ,
const ScAddress& )
2256void XclExpLinkManagerImpl5::StoreCellRange( sal_uInt16 ,
const OUString& ,
const ScRange& )
2261bool XclExpLinkManagerImpl5::InsertAddIn(
2262 sal_uInt16& rnExtSheet, sal_uInt16& rnExtName,
const OUString& rName )
2264 XclExpExtSheetRef xExtSheet = FindInternal( rnExtSheet,
EXC_EXTSH_ADDIN );
2267 rnExtName = xExtSheet->InsertAddIn( rName );
2268 return rnExtName > 0;
2273bool XclExpLinkManagerImpl5::InsertEuroTool(
2274 sal_uInt16& , sal_uInt16& ,
const OUString& )
2279bool XclExpLinkManagerImpl5::InsertDde(
2280 sal_uInt16& , sal_uInt16& ,
2281 const OUString& ,
const OUString& ,
const OUString& )
2287bool XclExpLinkManagerImpl5::InsertExtName(
2288 sal_uInt16& , sal_uInt16& ,
const OUString& ,
2295void XclExpLinkManagerImpl5::Save(
XclExpStream& rStrm )
2297 if( sal_uInt16 nExtSheetCount = GetExtSheetCount() )
2302 maExtSheetList.Save( rStrm );
2311sal_uInt16 XclExpLinkManagerImpl5::GetExtSheetCount()
const
2313 return static_cast< sal_uInt16
>( maExtSheetList.GetSize() );
2316sal_uInt16 XclExpLinkManagerImpl5::AppendInternal( XclExpExtSheetRef
const & xExtSheet )
2318 if( GetExtSheetCount() < 0x7FFF )
2320 maExtSheetList.AppendRecord( xExtSheet );
2322 return static_cast< sal_uInt16
>( -GetExtSheetCount() );
2327void XclExpLinkManagerImpl5::CreateInternal()
2329 if( !maIntTabMap.empty() )
2334 for(
SCTAB nScTab = 0, nScCnt = rTabInfo.
GetScTabCount(); nScTab < nScCnt; ++nScTab )
2338 XclExpExtSheetRef xRec;
2339 if( nScTab == GetCurrScTab() )
2342 xRec =
new XclExpExternSheet( GetRoot(), rTabInfo.
GetScTabName( nScTab ) );
2343 maIntTabMap[ nScTab ] = AppendInternal( xRec );
2350 return maExtSheetList.GetRecord(
static_cast< sal_uInt16
>( -nExtSheet - 1 ) );
2354 sal_uInt16& rnExtSheet, sal_uInt16& rnXclTab,
SCTAB nScTab )
2360 XclExpExtSheetRef xExtSheet;
2361 XclExpIntTabMap::const_iterator aIt = maIntTabMap.find( nScTab );
2362 if( aIt == maIntTabMap.end() )
2369 rnExtSheet = aIt->second;
2370 xExtSheet = GetInternal( rnExtSheet );
2371 rnXclTab = GetTabInfo().GetXclTab( nScTab );
2379 XclExpExtSheetRef xExtSheet;
2380 XclExpCodeMap::const_iterator aIt = maCodeMap.find( cCode );
2381 if( aIt == maCodeMap.end() )
2383 xExtSheet =
new XclExpExternSheet( GetRoot(), cCode );
2384 rnExtSheet = maCodeMap[ cCode ] = AppendInternal( xExtSheet );
2388 rnExtSheet = aIt->second;
2389 xExtSheet = GetInternal( rnExtSheet );
2394XclExpLinkManagerImpl8::XclExpLinkManagerImpl8(
const XclExpRoot& rRoot ) :
2400void XclExpLinkManagerImpl8::FindExtSheet(
2401 sal_uInt16& rnExtSheet, sal_uInt16& rnFirstXclTab, sal_uInt16& rnLastXclTab,
2405 rnFirstXclTab = rTabInfo.
GetXclTab( nFirstScTab );
2406 rnLastXclTab = rTabInfo.
GetXclTab( nLastScTab );
2407 rnExtSheet = InsertXti( maSBBuffer.GetXti( rnFirstXclTab, rnLastXclTab, pRefLogEntry ) );
2410sal_uInt16 XclExpLinkManagerImpl8::FindExtSheet(
sal_Unicode cCode )
2413 "XclExpLinkManagerImpl8::FindExtSheet - unknown externsheet code" );
2417void XclExpLinkManagerImpl8::FindExtSheet(
2418 sal_uInt16 nFileId,
const OUString& rTabName, sal_uInt16 nXclTabSpan,
2419 sal_uInt16& rnExtSheet, sal_uInt16& rnFirstSBTab, sal_uInt16& rnLastSBTab,
2422 XclExpXti aXti = maSBBuffer.GetXti(nFileId, rTabName, nXclTabSpan, pRefLogEntry);
2423 rnExtSheet = InsertXti(aXti);
2424 rnFirstSBTab = aXti.mnFirstSBTab;
2425 rnLastSBTab = aXti.mnLastSBTab;
2439 for (
SCTAB nScTab = nFirstScTab; nScTab <= nLastScTab; ++nScTab)
2443 aRange.aStart.SetTab( nScTab );
2444 aRange.aEnd.SetTab( nScTab );
2445 maSBBuffer.StoreCellRange( aRange );
2450void XclExpLinkManagerImpl8::StoreCell( sal_uInt16 nFileId,
const OUString& rTabName,
const ScAddress& rPos )
2452 maSBBuffer.StoreCell(nFileId, rTabName, rPos);
2455void XclExpLinkManagerImpl8::StoreCellRange( sal_uInt16 nFileId,
const OUString& rTabName,
const ScRange& rRange )
2457 maSBBuffer.StoreCellRange(nFileId, rTabName, rRange);
2460bool XclExpLinkManagerImpl8::InsertAddIn(
2461 sal_uInt16& rnExtSheet, sal_uInt16& rnExtName,
const OUString& rName )
2463 sal_uInt16 nSupbook;
2464 if( maSBBuffer.InsertAddIn( nSupbook, rnExtName, rName ) )
2472bool XclExpLinkManagerImpl8::InsertEuroTool(
2473 sal_uInt16& rnExtSheet, sal_uInt16& rnExtName,
const OUString& rName )
2475 sal_uInt16 nSupbook;
2476 if( maSBBuffer.InsertEuroTool( nSupbook, rnExtName, rName ) )
2484bool XclExpLinkManagerImpl8::InsertDde(
2485 sal_uInt16& rnExtSheet, sal_uInt16& rnExtName,
2486 const OUString& rApplic,
const OUString& rTopic,
const OUString& rItem )
2488 sal_uInt16 nSupbook;
2489 if( maSBBuffer.InsertDde( nSupbook, rnExtName, rApplic, rTopic, rItem ) )
2497bool XclExpLinkManagerImpl8::InsertExtName( sal_uInt16& rnExtSheet, sal_uInt16& rnExtName,
2500 sal_uInt16 nSupbook;
2501 if( maSBBuffer.InsertExtName( nSupbook, rnExtName, rUrl, rName, rArray ) )
2509void XclExpLinkManagerImpl8::Save(
XclExpStream& rStrm )
2511 if( maXtiVec.empty() )
2515 maSBBuffer.Save( rStrm );
2518 sal_uInt16
nCount = ulimit_cast< sal_uInt16 >( maXtiVec.size() );
2521 rStrm.SetSliceSize( 6 );
2522 for(
const auto& rXti : maXtiVec )
2529 if (maSBBuffer.HasExternalReferences())
2532 pWorkbook->startElement(XML_externalReferences);
2535 maSBBuffer.SaveXml( rStrm );
2537 pWorkbook->endElement( XML_externalReferences);
2542 if( !maXtiVec.empty() )
2544 for(
const auto& rXti : maXtiVec )
2545 rXti.SaveXml( rStrm );
2550sal_uInt16 XclExpLinkManagerImpl8::InsertXti(
const XclExpXti& rXti )
2552 auto aIt = std::find(maXtiVec.begin(), maXtiVec.end(), rXti);
2553 if (aIt != maXtiVec.end())
2554 return ulimit_cast< sal_uInt16 >( std::distance(maXtiVec.begin(), aIt) );
2555 maXtiVec.push_back( rXti );
2556 return ulimit_cast< sal_uInt16 >( maXtiVec.size() - 1 );
2565 mxImpl = std::make_shared<XclExpLinkManagerImpl5>( rRoot );
2568 mxImpl = std::make_shared<XclExpLinkManagerImpl8>( rRoot );
2580 sal_uInt16& rnExtSheet, sal_uInt16& rnXclTab,
2583 mxImpl->FindExtSheet( rnExtSheet, rnXclTab, rnXclTab, nScTab, nScTab, pRefLogEntry );
2587 sal_uInt16& rnExtSheet, sal_uInt16& rnFirstXclTab, sal_uInt16& rnLastXclTab,
2590 mxImpl->FindExtSheet( rnExtSheet, rnFirstXclTab, rnLastXclTab, nFirstScTab, nLastScTab, pRefLogEntry );
2595 return mxImpl->FindExtSheet( cCode );
2599 sal_uInt16& rnExtSheet, sal_uInt16& rnFirstSBTab, sal_uInt16& rnLastSBTab,
2602 mxImpl->FindExtSheet( nFileId, rTabName, nXclTabSpan, rnExtSheet, rnFirstSBTab, rnLastSBTab, pRefLogEntry );
2607 mxImpl->StoreCellRange(rRef, rRef, rPos);
2617 mxImpl->StoreCell(nFileId, rTabName, rPos);
2622 mxImpl->StoreCellRange(nFileId, rTabName, rRange);
2626 sal_uInt16& rnExtSheet, sal_uInt16& rnExtName,
const OUString& rName )
2628 return mxImpl->InsertAddIn( rnExtSheet, rnExtName, rName );
2632 sal_uInt16& rnExtSheet, sal_uInt16& rnExtName,
const OUString& rName )
2634 return mxImpl->InsertEuroTool( rnExtSheet, rnExtName, rName );
2638 sal_uInt16& rnExtSheet, sal_uInt16& rnExtName,
2639 const OUString& rApplic,
const OUString& rTopic,
const OUString& rItem )
2641 return mxImpl->InsertDde( rnExtSheet, rnExtName, rApplic, rTopic, rItem );
2645 sal_uInt16& rnExtSheet, sal_uInt16& rnExtName,
const OUString& rUrl,
const OUString& rName,
2648 return mxImpl->InsertExtName(rnExtSheet, rnExtName, rUrl, rName, rArray);
sal_Int32 compareString(const OUString &s1, const OUString &s2) const
SC_DLLPUBLIC bool IsScenario(SCTAB nTab) const
SCTAB GetVisibleTab() const
SC_DLLPUBLIC ScExternalRefManager * GetExternalRefManager() const
SC_DLLPUBLIC ScLinkMode GetLinkMode(SCTAB nTab) const
SC_DLLPUBLIC bool IsVisible(SCTAB nTab) const
SC_DLLPUBLIC bool IsLayoutRTL(SCTAB nTab) const
SC_DLLPUBLIC bool GetName(SCTAB nTab, OUString &rName) const
SC_DLLPUBLIC SCTAB GetTableCount() const
Extended options held by an ScDocument containing additional settings for filters.
const ScExtDocSettings & GetDocSettings() const
SCTAB GetCodeNameCount() const
const ScExtTabSettings * GetTabSettings(SCTAB nTab) const
std::shared_ptr< Table > TableTypeRef
::formula::FormulaTokenRef TokenRef
std::shared_ptr< ScTokenArray > TokenArrayRef
sal_uInt16 getExternalFileId(const OUString &rFile)
void setSkipUnusedFileIds(std::vector< sal_uInt16 > &pExternFileIds)
sal_uInt16 convertFileIdToUsedFileId(sal_uInt16 nFileId)
Reindex external file references to skip unused files, if skipping is enabled.
ScExternalRefCache::TableTypeRef getCacheTable(sal_uInt16 nFileId, size_t nTabIndex) const
Get a cache table instance for specified table and table index.
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.
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.
void getAllCachedTableNames(sal_uInt16 nFileId, ::std::vector< OUString > &rTabNames) const
Returns a vector containing all (real) table names and cache tables of the specified file.
static SC_DLLPUBLIC CollatorWrapper & GetCollator()
case-insensitive collator
todo: It should be possible to have MarkArrays for each table, in order to enable "search all" across...
Matrix data type that can store values of mixed types.
static OUString BuildFileName(sal_uInt16 &rnLevel, bool &rbRel, const OUString &rUrl, const XclExpRoot &rRoot, bool bEncoded)
Builds file name from the passed file URL.
Abstract base class for implementation classes of the link manager.
virtual void FindExtSheet(sal_uInt16 nFileId, const OUString &rTabName, sal_uInt16 nXclTabSpan, sal_uInt16 &rnExtSheet, sal_uInt16 &rnFirstSBTab, sal_uInt16 &rnLastSBTab, XclExpRefLogEntry *pRefLogEntry)=0
virtual void StoreCell(sal_uInt16 nFileId, const OUString &rTabName, const ScAddress &rPos)=0
virtual void StoreCellRange(const ScSingleRefData &rRef1, const ScSingleRefData &rRef2, const ScAddress &rPos)=0
Derived classes store all cells in the given range in a CRN record list.
XclExpLinkManagerImpl(const XclExpRoot &rRoot)
virtual bool InsertEuroTool(sal_uInt16 &rnExtSheet, sal_uInt16 &rnExtName, const OUString &rName)=0
InsertEuroTool.
virtual void SaveXml(XclExpXmlStream &rStrm)=0
Derived classes write the entire link table to the passed OOXML stream.
virtual void StoreCellRange(sal_uInt16 nFileId, const OUString &rTabName, const ScRange &rRange)=0
virtual void Save(XclExpStream &rStrm)=0
Derived classes write the entire link table to the passed stream.
virtual void FindExtSheet(sal_uInt16 &rnExtSheet, sal_uInt16 &rnFirstXclTab, sal_uInt16 &rnLastXclTab, SCTAB nFirstScTab, SCTAB nLastScTab, XclExpRefLogEntry *pRefLogEntry)=0
Derived classes search for an EXTSHEET structure for the given Calc sheet range.
virtual bool InsertAddIn(sal_uInt16 &rnExtSheet, sal_uInt16 &rnExtName, const OUString &rName)=0
Derived classes find or insert an EXTERNNAME record for an add-in function name.
virtual sal_uInt16 FindExtSheet(sal_Unicode cCode)=0
Derived classes search for a special EXTERNSHEET index for the own document.
virtual bool InsertDde(sal_uInt16 &rnExtSheet, sal_uInt16 &rnExtName, const OUString &rApplic, const OUString &rTopic, const OUString &rItem)=0
Derived classes find or insert an EXTERNNAME record for DDE links.
virtual bool InsertExtName(sal_uInt16 &rnExtSheet, sal_uInt16 &rnExtName, const OUString &rUrl, const OUString &rName, const ScExternalRefCache::TokenArrayRef &rArray)=0
bool InsertExtName(sal_uInt16 &rnExtSheet, sal_uInt16 &rnExtName, const OUString &rUrl, const OUString &rName, const ScExternalRefCache::TokenArrayRef &rArray)
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.
void FindExtSheet(sal_uInt16 &rnExtSheet, sal_uInt16 &rnXclTab, SCTAB nScTab, XclExpRefLogEntry *pRefLogEntry=nullptr)
Searches for an EXTERNSHEET index for the given Calc sheet.
void StoreCell(const ScSingleRefData &rRef, const ScAddress &rPos)
Stores the cell with the given address in a CRN record list.
XclExpLinkManager(const XclExpRoot &rRoot)
virtual void Save(XclExpStream &rStrm) override
Writes the entire Link table.
void StoreCellRange(const ScComplexRefData &rRef, const ScAddress &rPos)
Stores all cells in the given range in a CRN record list.
virtual void SaveXml(XclExpXmlStream &rStrm) override
Writes the entire Link table to OOXML.
virtual ~XclExpLinkManager() override
bool InsertAddIn(sal_uInt16 &rnExtSheet, sal_uInt16 &rnExtName, const OUString &rName)
Finds or inserts an EXTERNNAME record for an add-in function name.
XclExpLinkMgrImplPtr mxImpl
bool InsertEuroTool(sal_uInt16 &rnExtSheet, sal_uInt16 &rnExtName, const OUString &rName)
InsertEuroTool.
Base class for all Excel records.
virtual void SaveXml(XclExpXmlStream &rStrm)
virtual void Save(XclExpStream &rStrm)
Overwrite this method to do any operation while saving the record.
A list of Excel record objects.
rtl::Reference< RecType > RecordRefType
Base class for single records with any content.
virtual void Save(XclExpStream &rStrm) override
Writes the record header and calls WriteBody().
virtual void WriteBody(XclExpStream &rStrm)
Writes the body of the record (without record header).
Access to global data from other classes.
XclExpTabInfo & GetTabInfo() const
Returns the buffer for Calc->Excel sheet index conversion.
const XclExpRoot & GetRoot() const
Returns this root instance - for code readability in derived classes.
This class is used to export Excel record streams.
This class provides methods to create an XclExpString.
This class stores an unformatted or formatted string for Excel export.
bool IsEmpty() const
Returns true, if the string is empty.
Stores the correct Excel sheet index for each Calc sheet.
bool IsMirroredTab(SCTAB nScTab) const
Returns true, if the specified Calc sheet is displayed in right-to-left mode.
SCTAB GetScTabCount() const
Returns the number of Calc sheets.
bool GetFlag(SCTAB nScTab, ExcTabBufFlags nFlags) const
Returns true, if any of the passed flags is set for the specified Calc sheet.
void SetFlag(SCTAB nScTab, ExcTabBufFlags nFlags, bool bSet=true)
Sets or clears (depending on bSet) all passed flags for the specified Calc sheet.
SCTAB GetRealScTab(SCTAB nSortedScTab) const
Returns the Calc sheet index of the nSortedTab-th entry in the sorted sheet names list.
bool IsDisplayedTab(SCTAB nScTab) const
Returns true, if the specified Calc sheet is the displayed (active) sheet.
bool IsVisibleTab(SCTAB nScTab) const
Returns true, if the specified Calc sheet is visible and will be exported.
sal_uInt16 mnFirstVisXclTab
Displayed (active) sheet.
SCTAB mnScCnt
Array of Calc sheet index information.
sal_uInt16 mnXclSelCnt
Count of external link sheets.
sal_uInt16 GetXclTab(SCTAB nScTab) const
Returns the Excel sheet index for a given Calc sheet.
XclExpTabInfo(const XclExpRoot &rRoot)
Initializes the complete buffer from the current exported document.
std::vector< XclExpTabInfoEntry > maTabInfoVec
OUString GetScTabName(SCTAB nScTab) const
Returns the Calc name of the specified sheet.
void CalcXclIndexes()
Searches for sheets not to be exported.
sal_uInt16 mnDisplXclTab
Count of selected and exported sheets.
sal_uInt16 mnXclCnt
Count of Calc sheets.
ScTabVec maFromSortedVec
First visible sheet.
bool IsSelectedTab(SCTAB nScTab) const
Returns true, if the specified Calc sheet is selected and will be exported.
bool IsExternalTab(SCTAB nScTab) const
Returns true, if the specified Calc sheet is used to store external cell contents.
sal_uInt16 GetXclTabCount() const
Returns the number of Excel sheets to be exported.
bool IsExportTab(SCTAB nScTab) const
Returns true, if the specified Calc sheet will be exported.
sal_uInt16 GetXclExtTabCount() const
Returns the number of external linked sheets.
ScTabVec maToSortedVec
Sorted Calc sheet index -> real Calc sheet index.
sal_uInt16 mnXclExtCnt
Count of Excel sheets to be exported.
void CalcSortedIndexes()
Sorts the names of all tables and stores the indexes of the sorted indexes.
This class contains static methods to encode a file URL.
ScExtDocOptions & GetExtDocOptions() const
Returns the extended document options.
XclBiff GetBiff() const
Returns the current BIFF version of the importer/exporter.
ScDocument & GetDoc() const
Returns reference to the destination document (import) or source document (export).
static OString ToOString(const Color &rColor)
static OUString ToOUString(const char *s)
static OUString GetStreamName(const char *sStreamDir, const char *sStream, sal_Int32 nId)
virtual OUString GetName() const override
const sal_uInt8 SC_DDE_IGNOREMODE
FormulaError GetDoubleErrorValue(double fVal)
constexpr sal_Int32 FSNS(sal_Int32 namespc, sal_Int32 element)
#define SAL_WARN_IF(condition, area, stream)
#define SAL_WARN(area, stream)
constexpr OUStringLiteral first
OUString getRelationship(Relationship eRelationship)
std::shared_ptr< FastSerializerHelper > FSHelperPtr
css::uno::Reference< css::animations::XAnimationNode > Clone(const css::uno::Reference< css::animations::XAnimationNode > &xSourceNode, const SdPage *pSource=nullptr, const SdPage *pTarget=nullptr)
HashMap_OWString_Interface aMap
#define CREATE_OFFICEDOC_RELATION_TYPE(ascii)
Complex reference (a range) into the sheet.
SCTAB mnDisplTab
Index of displayed sheet.
Extended settings for a sheet, used in import/export filters.
Single reference (one address) into the sheet.
ScAddress toAbs(const ScSheetLimits &rLimits, const ScAddress &rPos) const
Log entry for external references in a formula, used i.e.
const XclExpString * mpUrl
const XclExpString * mpLastTab
Name of the first sheet.
sal_uInt16 mnLastXclTab
Calc index of the first sheet.
const XclExpString * mpFirstTab
URL of the document containing the first sheet.
sal_uInt16 mnFirstXclTab
Name of the last sheet.
::std::pair< OUString, SCTAB > XclExpTabName
@ Mirrored
Sheet is selected.
@ Extern
Sheet will be ignored completely.
@ SkipMask
Sheet is linked externally.
@ Selected
Sheet is visible.
@ Visible
Sheet will be skipped, if any flag is set.
XclExpValueRecord< sal_uInt16 > XclExpUInt16Record
A record containing an unsigned 16-bit value.
std::shared_ptr< XclExpString > XclExpStringRef
const SCTAB SCTAB_INVALID
An invalid Excel sheet index, for common use.
const sal_uInt8 EXC_ERR_REF
const sal_uInt16 EXC_NOTAB
const sal_uInt8 EXC_CACHEDVAL_ERROR
const sal_uInt8 EXC_CACHEDVAL_STRING
@ EXC_BIFF8
MS Excel 5.0, MS Excel 7.0 (95)
const sal_uInt8 EXC_CACHEDVAL_EMPTY
const sal_uInt8 EXC_CACHEDVAL_BOOL
const sal_uInt8 EXC_CACHEDVAL_DOUBLE
const sal_Unicode EXC_EXTSH_OWNDOC
const sal_Unicode EXC_EXTSH_TABNAME
XclSupbookType
This enumeration specifies the type of a SUPBOOK record.
@ Extern
SUPBOOK is used for internal references.
@ Addin
SUPBOOK is used for external references.
@ Eurotool
SUPBOOK is used for DDE or OLE links.
@ Self
unknown SUPBOOK record type.
@ Special
SUPBOOK contains add-in functions.
const sal_Unicode EXC_EXTSH_ADDIN
const sal_uInt16 EXC_ID_EXTERNCOUNT
Deleted sheet in a 3D reference.
const sal_Unicode EXC_EXTSH_OWNTAB
const sal_uInt16 EXC_SUPB_ADDIN
const sal_uInt16 EXC_SUPB_SELF
const sal_uInt16 EXC_ID_EXTERNNAME
const sal_uInt16 EXC_ID_EXTERNSHEET
const sal_uInt16 EXC_EXTN_EXPDDE_STDDOC
const sal_uInt16 EXC_TAB_EXTERNAL
const sal_uInt16 EXC_ID_XCT
for export
const sal_uInt16 EXC_EXTN_EXPDDE
for export
const sal_uInt16 EXC_ID_SUPBOOK
const sal_uInt16 EXC_TAB_DELETED
Special sheet index for external links.
const sal_uInt16 EXC_ID_CRN
XclStrFlags
Flags used to specify import/export mode of strings.
@ EightBitLength
Always use UCS-2 characters (default: try to compress). BIFF8 only.
bool operator==(const XclFontData &rLeft, const XclFontData &rRight)