22#include <compiler.hxx>
23#include <tokenarray.hxx>
25#include <com/sun/star/beans/XPropertySet.hpp>
26#include <com/sun/star/sheet/DDELinkInfo.hpp>
27#include <com/sun/star/sheet/ExternalLinkType.hpp>
28#include <com/sun/star/sheet/XDDELinks.hpp>
29#include <com/sun/star/sheet/XDDELinkResults.hpp>
30#include <com/sun/star/sheet/XExternalDocLinks.hpp>
31#include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
35#include <osl/diagnose.h>
40#include <oox/token/namespaces.hxx>
41#include <oox/token/properties.hxx>
43#include <oox/token/tokens.hxx>
52using ::oox::core::Relation;
53using ::oox::core::Relations;
57const sal_uInt16 BIFF12_EXTERNALBOOK_BOOK = 0;
58const sal_uInt16 BIFF12_EXTERNALBOOK_DDE = 1;
59const sal_uInt16 BIFF12_EXTERNALBOOK_OLE = 2;
61const sal_uInt16 BIFF12_EXTNAME_AUTOMATIC = 0x0002;
62const sal_uInt16 BIFF12_EXTNAME_PREFERPIC = 0x0004;
63const sal_uInt16 BIFF12_EXTNAME_STDDOCNAME = 0x0008;
64const sal_uInt16 BIFF12_EXTNAME_OLEOBJECT = 0x0010;
65const sal_uInt16 BIFF12_EXTNAME_ICONIFIED = 0x0020;
72 mbStdDocName( false ),
80 mrParentLink( rParentLink ),
81 mbDdeLinkCreated( false )
88 OSL_ENSURE( !
maModel.
maName.isEmpty(),
"ExternalName::importDefinedName - empty name" );
90 OSL_ENSURE( !
maModel.
maFormula.isEmpty(),
"ExternalName::importDefinedName - empty formula" );
101 pArray->SetCodeError(nErr);
103 if (pArray->HasReferences())
114 OSL_ENSURE( !
maModel.
maName.isEmpty(),
"ExternalName::importDdeItem - empty name" );
129 OSL_ENSURE( !
maModel.
maName.isEmpty(),
"ExternalName::importOleItem - empty name" );
139 OSL_ENSURE( !
maModel.
maName.isEmpty(),
"ExternalName::importExternalName - empty name" );
146 nFlags =
rStrm.readuInt16();
147 nSheetId =
rStrm.readInt32();
157 "ExternalName::importExternalNameFlags - wrong OLE flag in external name" );
162 sal_Int32 nRows, nCols;
163 nRows =
rStrm.readInt32();
164 nCols =
rStrm.readInt32();
170 appendResultValue< double >( (
rStrm.readuInt8() == 0) ? 0.0 : 1.0 );
207 Reference< XDDELinks > xDdeLinks( aDocProps.
getAnyProperty( PROP_DDELinks ), UNO_QUERY_THROW );
212 Reference< XDDELinkResults > xResults(
mxDdeLink, UNO_QUERY_THROW );
218 OSL_FAIL(
"ExternalName::getDdeLinkData - cannot create DDE link" );
223 orDdeServer =
mxDdeLink->getApplication();
237 "ExternalName::setResultSize - wrong link type" );
238 OSL_ENSURE( (nRows > 0) && (nColumns > 0),
"ExternalName::setResultSize - invalid matrix size" );
240 if( (0 < nRows) && (nRows <= rMaxPos.
Row() + 1) && (0 < nColumns) && (nColumns <= rMaxPos.
Col() + 1) )
264 mnFirst = ::std::min( nFirst, nLast );
265 mnLast = ::std::max( nFirst, nLast );
278 mnFirst = ::std::min( nFirst, nLast );
279 mnLast = ::std::max( nFirst, nLast );
312 OUString aDdeService = rAttribs.
getXString( XML_ddeService, OUString() );
313 OUString aDdeTopic = rAttribs.
getXString( XML_ddeTopic, OUString() );
320 xExtName->importDdeItem( rAttribs );
326 OUString aProgId = rAttribs.
getXString( XML_progId, OUString() );
327 OUString aTargetUrl = rRelations.getExternalTargetFromRelId( rAttribs.
getString( R_TOKEN(
id ), OUString() ) );
334 xExtName->importOleItem( rAttribs );
360 switch(
rStrm.readuInt16() )
362 case BIFF12_EXTERNALBOOK_BOOK:
365 case BIFF12_EXTERNALBOOK_DDE:
367 OUString aDdeService, aDdeTopic;
368 rStrm >> aDdeService >> aDdeTopic;
372 case BIFF12_EXTERNALBOOK_OLE:
380 OSL_FAIL(
"ExternalLink::importExternalBook - unknown link type" );
398 xExtName->importExternalName(
rStrm );
404 ExternalLinkInfo aLinkInfo;
409 aLinkInfo.Type = css::sheet::ExternalLinkType::SELF;
412 aLinkInfo.Type = css::sheet::ExternalLinkType::DOCUMENT;
417 aLinkInfo.Type = css::sheet::ExternalLinkType::SPECIAL;
421 aLinkInfo.Type = css::sheet::ExternalLinkType::DDE;
422 DDELinkInfo aDdeLinkInfo;
426 DDEItemInfo aItemInfo;
428 if( rxExtName->getDdeItemInfo( aItemInfo ) )
431 aLinkInfo.Data <<= aDdeLinkInfo;
435 aLinkInfo.Type = css::sheet::ExternalLinkType::UNKNOWN;
460 if(
mxDocLink.is() && (nCacheIdx >= 0) )
try
463 Reference< XExternalSheetCache > xSheetCache(
mxDocLink->getByIndex( nCacheIdx ), UNO_QUERY_THROW );
481 orSheetRange.
setRange( nTabId1, nTabId2 );
530 Reference< XExternalDocLinks > xDocLinks( aDocProps.
getAnyProperty( PROP_ExternalDocLinks ), UNO_QUERY_THROW );
543 OSL_ENSURE(
meLinkType == eLinkType,
"ExternalLink::setDdeOleTargetUrl - missing classname or target" );
548 if(
const Relation* pRelation = rRelations.getRelationFromRelId( rRelId ) )
554 OSL_ENSURE( !rSheetName.isEmpty(),
"ExternalLink::insertExternalSheet - empty sheet name" );
557 Reference< XExternalSheetCache > xSheetCache =
mxDocLink->addSheetCache( rSheetName,
false );
558 sal_Int32 nCacheIdx = xSheetCache.is() ? xSheetCache->getTokenIndex() : -1;
587 mbUseRefSheets( false )
595 xExtLink->importExternalReference( rAttribs );
604 xExtLink->importExternalRef(
rStrm );
629 OSL_ENSURE(
mbUseRefSheets,
"ExternalLinkBuffer::importExternalSheets - missing EXTERNALREFS records" );
631 OSL_ENSURE(
maRefSheets.empty(),
"ExternalLinkBuffer::importExternalSheets - multiple EXTERNALSHEETS records" );
635 size_t nMaxCount = getLimitedValue< size_t, sal_Int64 >(
nRefCount, 0,
rStrm.getRemaining() / 12 );
637 for(
size_t nRefId = 0; !
rStrm.isEof() && (nRefId < nMaxCount); ++nRefId )
647 ::std::vector< ExternalLinkInfo > aLinkInfos;
649 aLinkInfos.push_back(
mxSelfRef->getLinkInfo() );
651 aLinkInfos.push_back( rxExtLink->getLinkInfo() );
663 xExtLink =
maLinks.
get( pRefSheets->mnExtRefId );
669 OSL_ENSURE(
mbUseRefSheets,
"ExternalLinkBuffer::getSheetRange - wrong BIFF version" );
673 pExtLink->getSheetRange( aSheetRange, pRefSheets->mnTabId1, pRefSheets->mnTabId2 );
689 &
maRefSheets[
static_cast< size_t >( nRefId ) ] :
nullptr;
void SetExternalLinks(const css::uno::Sequence< css::sheet::ExternalLinkInfo > &rLinks)
Set external link info for ScAddress::CONV_XL_OOX.
std::unique_ptr< ScTokenArray > CompileString(const OUString &rFormula)
Tokenize formula expression string into an array of tokens.
SC_DLLPUBLIC void CheckLinkFormulaNeedingCheck(const ScTokenArray &rCode)
Check token array and set link check if ocDde/ocWebservice is contained.
SC_DLLPUBLIC ScExternalRefManager * GetExternalRefManager() const
sal_uInt16 getExternalFileId(const OUString &rFile)
void storeRangeNameTokens(sal_uInt16 nFileId, const OUString &rName, const ScTokenArray &rArray)
std::optional< OUString > getXString(sal_Int32 nAttrToken) const
std::optional< sal_Int32 > getInteger(sal_Int32 nAttrToken) const
std::optional< OUString > getString(sal_Int32 nAttrToken) const
std::optional< bool > getBool(sal_Int32 nAttrToken) const
static css::uno::Sequence< css::uno::Sequence< typename MatrixType::value_type > > matrixToSequenceSequence(const MatrixType &rMatrix)
static const VectorType::value_type * getVectorElement(const VectorType &rVector, sal_Int32 nIndex)
void resize(size_type nWidth, size_type nHeight)
css::uno::Any getAnyProperty(sal_Int32 nPropId) const
value_type get(sal_Int32 nIndex) const
OUString getAbsoluteUrl(const OUString &rUrl) const
const ScAddress & getMaxApiAddress() const
Returns the biggest valid cell address in the own Calc document.
static double calcDoubleFromError(sal_uInt8 nErrorCode)
Converts the passed BIFF error to a double containing the respective Calc error code.
static OUString readString(SequenceInputStream &rStrm, bool b32BitLen=true)
Reads a BIFF12 string with leading 16-bit or 32-bit length field.
Base class for defined names and external names.
const RefSheetsModel * getRefSheets(sal_Int32 nRefId) const
Returns the specified sheet indexes for a reference identifier.
ExternalLinkRef createExternalLink()
Creates a new external link and inserts it into the list of links.
void importExternalAddin(SequenceInputStream &rStrm)
Imports the EXTERNALADDIN record from the passed stream.
void importExternalSelf(SequenceInputStream &rStrm)
Imports the EXTERNALSELF record from the passed stream.
ExternalLinkRef getExternalLink(sal_Int32 nRefId, bool bUseRefSheets=true) const
Returns the external link for the passed reference identifier.
css::uno::Sequence< css::sheet::ExternalLinkInfo > getLinkInfos() const
Returns the sequence of link infos needed by the XML formula parser.
void importExternalSheets(SequenceInputStream &rStrm)
Imports the EXTERNALSHEETS record from the passed stream.
bool mbUseRefSheets
Sheet indexes for reference ids.
void importExternalSame(SequenceInputStream &rStrm)
Imports the EXTERNALSAME record from the passed stream.
RefSheetsModelVec maRefSheets
Real external links needed for formula parser.
ExternalLinkRef importExternalReference(const AttributeList &rAttribs)
Imports the externalReference element containing .
ExternalLinkVec maLinks
Implicit self reference at index 0.
ExternalLinkBuffer(const WorkbookHelper &rHelper)
ExternalLinkRef importExternalRef(SequenceInputStream &rStrm)
Imports the EXTERNALREF record from the passed stream.
ExternalLinkVec maExtLinks
List of link structures for all kinds of links.
LinkSheetRange getSheetRange(sal_Int32 nRefId) const
Returns the sheet range for the specified reference (BIFF8 only).
ExternalLinkRef mxSelfRef
const OUString & getClassName() const
Returns the class name of this external link.
ExternalLinkType getLinkType() const
Returns the type of this external link.
void importExtSheetNames(SequenceInputStream &rStrm)
Imports the EXTSHEETNAMES record containing the sheet names in an externally linked document.
OUString maRelId
Type of the function library, if link type is ExternalLinkType::Library.
ExternalNameRef createExternalName()
sal_Int32 getSheetCacheIndex(sal_Int32 nTabId) const
Returns the external sheet cache index or for the passed sheet.
void importDefinedName(const AttributeList &rAttribs)
Imports the definedName element describing an external name.
void importDdeLink(const AttributeList &rAttribs)
Imports the ddeLink element describing a DDE link.
RefVector< ExternalName > maExtNames
External sheet cache indexes.
void importExternalSelf(SequenceInputStream &rStrm)
Imports the EXTERNALSELF record from the passed stream.
void importExternalReference(const AttributeList &rAttribs)
Imports the externalReference element containing the relation identifier.
std::vector< sal_Int32 > maSheetCaches
Interface for an external document.
FunctionLibraryType getFuncLibraryType() const
Returns the type of the external library if this is a library link.
css::sheet::ExternalLinkInfo getLinkInfo() const
Returns the link info needed by the XML formula parser.
void importSheetName(const AttributeList &rAttribs)
Imports the sheetName element containing the sheet name in an externally linked document.
void getSheetRange(LinkSheetRange &orSheetRange, sal_Int32 nTabId1, sal_Int32 nTabId2) const
Returns the internal sheet range or range of external sheet caches for the passed sheet range (BIFF o...
ExternalNameRef getNameByIndex(sal_Int32 nIndex) const
Returns the external name with the passed zero-based index.
void importExternalAddin(SequenceInputStream &rStrm)
Imports the EXTERNALADDIN record from the passed stream.
void setDdeOleTargetUrl(const OUString &rClassName, const OUString &rTargetUrl, ExternalLinkType eLinkType)
OUString maClassName
Relation identifier for the external link fragment.
void parseExternalReference(const ::oox::core::Relations &rRelations, const OUString &rRelId)
void setExternalTargetUrl(const OUString &rTargetUrl, const OUString &rTargetType)
OUString maTargetUrl
DDE service, OLE class name.
ExternalNameRef importExternalName(SequenceInputStream &rStrm)
Imports the EXTERNALNAME record describing an external name.
FunctionLibraryType meFuncLibType
Type of this link object.
void importOleLink(const ::oox::core::Relations &rRelations, const AttributeList &rAttribs)
Imports the oleLink element describing an OLE link.
void importExternalBook(const ::oox::core::Relations &rRelations, const AttributeList &rAttribs)
Imports the externalBook element describing an externally linked document.
ExternalNameRef importOleItem(const AttributeList &rAttribs)
Imports the oleItem element describing an object of an OLE link.
void insertExternalSheet(const OUString &rSheetName)
Creates an external document link and the sheet cache for the passed sheet name.
css::uno::Reference< css::sheet::XExternalDocLink > mxDocLink
Target link, DDE topic, OLE target.
ExternalLinkType meLinkType
sal_Int32 getDocumentLinkIndex() const
Returns the token index of the external document.
ExternalLink(const WorkbookHelper &rHelper)
ExternalNameRef importDdeItem(const AttributeList &rAttribs)
Imports the ddeItem element describing an item of a DDE link.
void importExternalRef(SequenceInputStream &rStrm)
Imports the EXTERNALREF record from the passed stream.
css::uno::Reference< css::sheet::XExternalSheetCache > getSheetCache(sal_Int32 nTabId) const
Returns the sheet cache of the external sheet with the passed index.
const OUString & getTargetUrl() const
Returns the target URL of this external link.
void importExternalSame(SequenceInputStream &rStrm)
Imports the EXTERNALSAME record from the passed stream.
void importExternalName(SequenceInputStream &rStrm)
Imports the EXTERNALNAME record containing the name (only).
void importDdeItemError(SequenceInputStream &rStrm)
Imports the DDEITEM_ERROR record containing an error code in a link result.
void importDefinedName(const AttributeList &rAttribs)
Imports the definedName element.
void importDdeItemBool(SequenceInputStream &rStrm)
Imports the DDEITEM_BOOL record containing a boolean value in a link result.
void importDdeItemValues(SequenceInputStream &rStrm)
Imports the DDEITEMVALUES record containing the size of the DDE result matrix.
void importDdeItemString(SequenceInputStream &rStrm)
Imports the DDEITEM_STRING record containing a string in a link result.
void importValues(const AttributeList &rAttribs)
Imports the values element containing the size of the DDE result matrix.
ResultMatrix::iterator maCurrIt
DDE/OLE link results.
void importDdeItemDouble(SequenceInputStream &rStrm)
Imports the DDEITEM_DOUBLE record containing a double value in a link result.
ExternalName(const ExternalLink &rParentLink)
ExternalNameModel maExtNameModel
External link this name belongs to.
void importDdeItem(const AttributeList &rAttribs)
Imports the ddeItem element describing an item of a DDE link.
const ExternalLink & mrParentLink
bool getDdeItemInfo(css::sheet::DDEItemInfo &orItemInfo) const
Returns the DDE item info needed by the XML formula parser.
void importExternalNameFlags(SequenceInputStream &rStrm)
Imports the EXTERNALNAMEFLAGS record containing the settings of an external name.
void importOleItem(const AttributeList &rAttribs)
Imports the oleItem element describing an object of an OLE link.
css::uno::Reference< css::sheet::XDDELink > mxDdeLink
Current position in result matrix.
ResultMatrix maResults
Additional name data.
bool mbDdeLinkCreated
Interface of a DDE link.
bool getDdeLinkData(OUString &orDdeServer, OUString &orDdeTopic, OUString &orDdeItem)
Returns the complete DDE link data of this DDE item.
void appendResultValue(const Type &rValue)
Appends the passed value to the result set.
void setResultSize(sal_Int32 nColumns, sal_Int32 nRows)
Sets the size of the result matrix.
static FunctionLibraryType getFuncLibTypeFromLibraryName(std::u16string_view rLibraryName)
Returns the library type associated with the passed URL of a function library (function add-in).
Contains indexes for a range of sheets in the spreadsheet document.
LinkSheetRangeType meType
void setSameSheet()
Sets this struct to "use current sheet" state.
sal_Int32 mnFirst
Document link token index for external links.
void setExternalRange(sal_Int32 nDocLink, sal_Int32 nFirst, sal_Int32 nLast)
Sets the passed external sheet cache range to the members of this struct.
sal_Int32 mnDocLink
Link sheet range type.
sal_Int32 mnLast
Index of the first sheet or index of first external sheet cache.
void setRange(sal_Int32 nFirst, sal_Int32 nLast)
Sets the passed absolute sheet range to the members of this struct.
void setDeleted()
Sets this struct to deleted state.
@ LINKSHEETRANGE_SAMESHEET
Sheet range in an external document.
@ LINKSHEETRANGE_EXTERNAL
Sheet range in the own document.
@ LINKSHEETRANGE_INTERNAL
Helper class to provide access to global workbook data.
AddressConverter & getAddressConverter() const
Returns the converter for string to cell address/range conversion.
ScDocument & getScDocument()
::oox::core::FilterBase & getBaseFilter() const
Returns the base filter object (base class of all filters).
const css::uno::Reference< css::sheet::XSpreadsheetDocument > & getDocument() const
Returns a reference to the source/target spreadsheet document model.
ExternalLinkBuffer & getExternalLinks() const
Returns the external links read from the external links substream.
SfxItemInfo const aItemInfos[]
#define SAL_WARN_IF(condition, area, stream)
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
constexpr std::enable_if_t< std::is_signed_v< T >, std::make_unsigned_t< T > > make_unsigned(T value)
std::shared_ptr< T > make_shared(Args &&... args)
std::shared_ptr< ExternalName > ExternalNameRef
const sal_uInt8 BIFF_ERR_NA
std::shared_ptr< ExternalLink > ExternalLinkRef
@ PathMissing
Link refers to an external spreadsheet document.
@ Library
Just for round-tripping (FIXME: Functionality not actually implemented after all.)
@ External
Link refers to the current sheet.
@ Same
Link refers to the current workbook.
@ DDE
Link refers to an external add-in.
FunctionLibraryType
This enumeration contains constants for all known external libraries containing supported sheet funct...
bool getFlag(Type nBitField, Type nMask)
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
#define CREATE_OFFICEDOC_RELATION_TYPE(ascii)
#define CREATE_OFFICEDOC_RELATION_TYPE_STRICT(ascii)
#define CREATE_MSOFFICE_RELATION_TYPE(ascii)
sal_Int32 mnSheet
The formula string.
OUString maFormula
The original name.
bool mbStdDocName
Picture link.
ExternalNameModel()
Iconified object link.
bool mbOleObj
Name is the StdDocumentName for DDE.
bool mbPreferPic
Notify application on data change.
bool mbIconified
Name is an OLE object.
Represents a REF entry in the BIFF12 EXTERNALSHEETS or in the BIFF8 EXTERNSHEET record.
sal_Int32 mnTabId1
Zero-based index into list of external documents.
void readBiff12Data(SequenceInputStream &rStrm)
RefSheetsModel()
Zero-based index to last sheet in external document.
sal_Int32 mnTabId2
Zero-based index to first sheet in external document.