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>
52 using ::oox::core::Relation;
53 using ::oox::core::Relations;
57 const sal_uInt16 BIFF12_EXTERNALBOOK_BOOK = 0;
58 const sal_uInt16 BIFF12_EXTERNALBOOK_DDE = 1;
59 const sal_uInt16 BIFF12_EXTERNALBOOK_OLE = 2;
61 const sal_uInt16 BIFF12_EXTNAME_AUTOMATIC = 0x0002;
62 const sal_uInt16 BIFF12_EXTNAME_PREFERPIC = 0x0004;
63 const sal_uInt16 BIFF12_EXTNAME_STDDOCNAME = 0x0008;
64 const sal_uInt16 BIFF12_EXTNAME_OLEOBJECT = 0x0010;
65 const 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" );
157 "ExternalName::importExternalNameFlags - wrong OLE flag in external name" );
162 sal_Int32 nRows, nCols;
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 );
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 ) )
429 aItemInfos.push_back( 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;
Helper class to provide access to global workbook data.
void importDdeItem(const AttributeList &rAttribs)
Imports the ddeItem element describing an item of a DDE link.
css::uno::Reference< css::sheet::XDDELink > mxDdeLink
Current position in result matrix.
ExternalLink(const WorkbookHelper &rHelper)
void importExternalSelf(SequenceInputStream &rStrm)
Imports the EXTERNALSELF record from the passed stream.
void storeRangeNameTokens(sal_uInt16 nFileId, const OUString &rName, const ScTokenArray &rArray)
bool getDdeLinkData(OUString &orDdeServer, OUString &orDdeTopic, OUString &orDdeItem)
Returns the complete DDE link data of this DDE item.
ExternalLinkRef getExternalLink(sal_Int32 nRefId, bool bUseRefSheets=true) const
Returns the external link for the passed reference identifier.
OptValue< bool > getBool(sal_Int32 nAttrToken) const
FunctionLibraryType meFuncLibType
Type of this link object.
ExternalLinkVec maLinks
Implicit self reference at index 0.
const sal_uInt8 BIFF_ERR_NA
static const VectorType::value_type * getVectorElement(const VectorType &rVector, sal_Int32 nIndex)
OptValue< OUString > getXString(sal_Int32 nAttrToken) const
std::shared_ptr< ExternalLink > ExternalLinkRef
ExternalLinkRef mxSelfRef
OptValue< sal_Int32 > getInteger(sal_Int32 nAttrToken) const
Link refers to the current sheet.
static double calcDoubleFromError(sal_uInt8 nErrorCode)
Converts the passed BIFF error to a double containing the respective Calc error code.
sal_Int32 mnSheet
The formula string.
void appendResultValue(const Type &rValue)
Appends the passed value to the result set.
void importExternalSelf(SequenceInputStream &rStrm)
Imports the EXTERNALSELF record from the passed stream.
ResultMatrix maResults
Additional name data.
#define CREATE_OFFICEDOC_RELATION_TYPE(ascii)
std::unique_ptr< ScTokenArray > CompileString(const OUString &rFormula)
Tokenize formula expression string into an array of tokens.
Link refers to the current workbook.
css::uno::Any getAnyProperty(sal_Int32 nPropId) const
const ScAddress & getMaxApiAddress() const
Returns the biggest valid cell address in the own Calc document.
void importExternalNameFlags(SequenceInputStream &rStrm)
Imports the EXTERNALNAMEFLAGS record containing the settings of an external name. ...
value_type get(sal_Int32 nIndex) const
Link refers to an external add-in.
sal_uInt16 getExternalFileId(const OUString &rFile)
void SetExternalLinks(const css::uno::Sequence< css::sheet::ExternalLinkInfo > &rLinks)
Set external link info for ScAddress::CONV_XL_OOX.
void setExternalTargetUrl(const OUString &rTargetUrl, const OUString &rTargetType)
Link refers to an external spreadsheet document.
OptValue< OUString > getString(sal_Int32 nAttrToken) const
ExternalLinkVec maExtLinks
List of link structures for all kinds of links.
std::shared_ptr< T > make_shared(Args &&...args)
void importExternalName(SequenceInputStream &rStrm)
Imports the EXTERNALNAME record containing the name (only).
const ExternalLink & mrParentLink
bool mbOleObj
Name is the StdDocumentName for DDE.
void importExternalReference(const AttributeList &rAttribs)
Imports the externalReference element containing the relation identifier.
bool mbIconified
Name is an OLE object.
LinkSheetRangeType meType
OUString maFormula
The original name.
sal_Int32 mnTabId1
Zero-based index into list of external documents.
ExternalLinkType getLinkType() const
Returns the type of this external link.
Base class for defined names and external names.
void importExternalAddin(SequenceInputStream &rStrm)
Imports the EXTERNALADDIN record from the passed stream.
SC_DLLPUBLIC void CheckLinkFormulaNeedingCheck(const ScTokenArray &rCode)
Check token array and set link check if ocDde/ocWebservice is contained.
css::uno::Reference< css::sheet::XExternalDocLink > mxDocLink
Target link, DDE topic, OLE target.
void importSheetName(const AttributeList &rAttribs)
Imports the sheetName element containing the sheet name in an externally linked document.
sal_Int32 mnTabId2
Zero-based index to first sheet in external document.
sal_Int32 mnDocLink
Link sheet range type.
::oox::core::FilterBase & getBaseFilter() const
Returns the base filter object (base class of all filters).
SC_DLLPUBLIC ScExternalRefManager * GetExternalRefManager() const
RefSheetsModel()
Zero-based index to last sheet in external document.
const RefSheetsModel * getRefSheets(sal_Int32 nRefId) const
Returns the specified sheet indexes for a reference identifier.
ExternalNameRef importExternalName(SequenceInputStream &rStrm)
Imports the EXTERNALNAME record describing an external name.
Just for round-tripping (FIXME: Functionality not actually implemented after all.) ...
void importExternalRef(SequenceInputStream &rStrm)
Imports the EXTERNALREF record from the passed stream.
bool getFlag(Type nBitField, Type nMask)
ExternalName(const ExternalLink &rParentLink)
static FunctionLibraryType getFuncLibTypeFromLibraryName(std::u16string_view rLibraryName)
Returns the library type associated with the passed URL of a function library (function add-in)...
sal_Int32 getDocumentLinkIndex() const
Returns the token index of the external document.
void 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.
#define CREATE_OFFICEDOC_RELATION_TYPE_STRICT(ascii)
void setSameSheet()
Sets this struct to "use current sheet" state.
void importExternalAddin(SequenceInputStream &rStrm)
Imports the EXTERNALADDIN record from the passed stream.
void resize(size_type nWidth, size_type nHeight)
const css::uno::Reference< css::sheet::XSpreadsheetDocument > & getDocument() const
Returns a reference to the source/target spreadsheet document model.
ExternalNameRef importOleItem(const AttributeList &rAttribs)
Imports the oleItem element describing an object of an OLE link.
std::vector< sal_Int32 > maSheetCaches
Interface for an external document.
ExternalLinkBuffer & getExternalLinks() const
Returns the external links read from the external links substream.
Sheet range in an external document.
static OUString readString(SequenceInputStream &rStrm, bool b32BitLen=true)
Reads a BIFF12 string with leading 16-bit or 32-bit length field.
#define CREATE_MSOFFICE_RELATION_TYPE(ascii)
ScDocument & getScDocument()
bool mbUseRefSheets
Sheet indexes for reference ids.
constexpr std::enable_if_t< std::is_signed_v< T >, std::make_unsigned_t< T > > make_unsigned(T value)
void importOleLink(const ::oox::core::Relations &rRelations, const AttributeList &rAttribs)
Imports the oleLink element describing an OLE link.
sal_Int32 mnLast
Index of the first sheet or index of first external sheet cache.
ExternalLinkBuffer(const WorkbookHelper &rHelper)
void readBiff12Data(SequenceInputStream &rStrm)
const OUString & getTargetUrl() const
Returns the target URL of this external link.
sal_Int32 mnFirst
Document link token index for external links.
void importExternalSame(SequenceInputStream &rStrm)
Imports the EXTERNALSAME record from the passed stream.
ExternalNameRef createExternalName()
void setResultSize(sal_Int32 nColumns, sal_Int32 nRows)
Sets the size of the result matrix.
RefSheetsModelVec maRefSheets
Real external links needed for formula parser.
FunctionLibraryType
This enumeration contains constants for all known external libraries containing supported sheet funct...
void importValues(const AttributeList &rAttribs)
Imports the values element containing the size of the DDE result matrix.
ExternalLinkRef importExternalReference(const AttributeList &rAttribs)
Imports the externalReference element containing .
bool mbPreferPic
Notify application on data change.
void importDefinedName(const AttributeList &rAttribs)
Imports the definedName element describing an external name.
css::uno::Sequence< css::sheet::ExternalLinkInfo > getLinkInfos() const
Returns the sequence of link infos needed by the XML formula parser.
sal_Int64 getRemaining() const
void setExternalRange(sal_Int32 nDocLink, sal_Int32 nFirst, sal_Int32 nLast)
Sets the passed external sheet cache range to the members of this struct.
void setDeleted()
Sets this struct to deleted state.
ExternalLinkType meLinkType
#define SAL_WARN_IF(condition, area, stream)
ExternalNameModel maExtNameModel
External link this name belongs to.
Represents a REF entry in the BIFF12 EXTERNALSHEETS or in the BIFF8 EXTERNSHEET record.
void importDdeItemValues(SequenceInputStream &rStrm)
Imports the DDEITEMVALUES record containing the size of the DDE result matrix.
RefVector< ExternalName > maExtNames
External sheet cache indexes.
void importDdeLink(const AttributeList &rAttribs)
Imports the ddeLink element describing a DDE link.
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
void importExternalSame(SequenceInputStream &rStrm)
Imports the EXTERNALSAME record from the passed stream.
Sheet range in the own document.
static css::uno::Sequence< css::uno::Sequence< typename MatrixType::value_type > > matrixToSequenceSequence(const MatrixType &rMatrix)
LinkSheetRange getSheetRange(sal_Int32 nRefId) const
Returns the sheet range for the specified reference (BIFF8 only).
void importDdeItemError(SequenceInputStream &rStrm)
Imports the DDEITEM_ERROR record containing an error code in a link result.
const OUString & getClassName() const
Returns the class name of this external link.
SfxItemInfo const aItemInfos[]
sal_Int32 getSheetCacheIndex(sal_Int32 nTabId) const
Returns the external sheet cache index or for the passed sheet.
void importExternalSheets(SequenceInputStream &rStrm)
Imports the EXTERNALSHEETS record from the passed stream.
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...
OUString maClassName
Relation identifier for the external link fragment.
Contains indexes for a range of sheets in the spreadsheet document.
void parseExternalReference(const ::oox::core::Relations &rRelations, const OUString &rRelId)
ExternalLinkRef importExternalRef(SequenceInputStream &rStrm)
Imports the EXTERNALREF record from the passed stream.
void importDdeItemString(SequenceInputStream &rStrm)
Imports the DDEITEM_STRING record containing a string in a link result.
css::sheet::ExternalLinkInfo getLinkInfo() const
Returns the link info needed by the XML formula parser.
OUString maTargetUrl
DDE service, OLE class name.
OUString getAbsoluteUrl(const OUString &rUrl) const
void importExtSheetNames(SequenceInputStream &rStrm)
Imports the EXTSHEETNAMES record containing the sheet names in an externally linked document...
void importExternalBook(const ::oox::core::Relations &rRelations, const AttributeList &rAttribs)
Imports the externalBook element describing an externally linked document.
bool mbDdeLinkCreated
Interface of a DDE link.
css::uno::Reference< css::sheet::XExternalSheetCache > getSheetCache(sal_Int32 nTabId) const
Returns the sheet cache of the external sheet with the passed index.
ExternalLinkRef createExternalLink()
Creates a new external link and inserts it into the list of links.
void importDdeItemBool(SequenceInputStream &rStrm)
Imports the DDEITEM_BOOL record containing a boolean value in a link result.
bool getDdeItemInfo(css::sheet::DDEItemInfo &orItemInfo) const
Returns the DDE item info needed by the XML formula parser.
void setDdeOleTargetUrl(const OUString &rClassName, const OUString &rTargetUrl, ExternalLinkType eLinkType)
void setRange(sal_Int32 nFirst, sal_Int32 nLast)
Sets the passed absolute sheet range to the members of this struct.
void importDefinedName(const AttributeList &rAttribs)
Imports the definedName element.
FunctionLibraryType getFuncLibraryType() const
Returns the type of the external library if this is a library link.
std::shared_ptr< ExternalName > ExternalNameRef
ExternalNameRef importDdeItem(const AttributeList &rAttribs)
Imports the ddeItem element describing an item of a DDE link.
ResultMatrix::iterator maCurrIt
DDE/OLE link results.
OUString maRelId
Type of the function library, if link type is ExternalLinkType::Library.
bool mbStdDocName
Picture link.
void importDdeItemDouble(SequenceInputStream &rStrm)
Imports the DDEITEM_DOUBLE record containing a double value in a link result.
ExternalNameRef getNameByIndex(sal_Int32 nIndex) const
Returns the external name with the passed zero-based index.
AddressConverter & getAddressConverter() const
Returns the converter for string to cell address/range conversion.
bool m_bDetectedRangeSegmentation false
ExternalNameModel()
Iconified object link.