22 #include <com/sun/star/beans/XPropertySet.hpp>
23 #include <com/sun/star/sheet/DDELinkInfo.hpp>
24 #include <com/sun/star/sheet/ExternalLinkType.hpp>
25 #include <com/sun/star/sheet/XDDELinks.hpp>
26 #include <com/sun/star/sheet/XDDELinkResults.hpp>
27 #include <com/sun/star/sheet/XExternalDocLinks.hpp>
28 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
30 #include <osl/diagnose.h>
35 #include <oox/token/namespaces.hxx>
36 #include <oox/token/properties.hxx>
38 #include <oox/token/tokens.hxx>
47 using ::oox::core::Relation;
48 using ::oox::core::Relations;
52 const sal_uInt16 BIFF12_EXTERNALBOOK_BOOK = 0;
53 const sal_uInt16 BIFF12_EXTERNALBOOK_DDE = 1;
54 const sal_uInt16 BIFF12_EXTERNALBOOK_OLE = 2;
56 const sal_uInt16 BIFF12_EXTNAME_AUTOMATIC = 0x0002;
57 const sal_uInt16 BIFF12_EXTNAME_PREFERPIC = 0x0004;
58 const sal_uInt16 BIFF12_EXTNAME_STDDOCNAME = 0x0008;
59 const sal_uInt16 BIFF12_EXTNAME_OLEOBJECT = 0x0010;
60 const sal_uInt16 BIFF12_EXTNAME_ICONIFIED = 0x0020;
67 mbStdDocName( false ),
75 mrParentLink( rParentLink ),
76 mbDdeLinkCreated( false )
83 OSL_ENSURE( !
maModel.
maName.isEmpty(),
"ExternalName::importDefinedName - empty name" );
91 OSL_ENSURE( !
maModel.
maName.isEmpty(),
"ExternalName::importDdeItem - empty name" );
106 OSL_ENSURE( !
maModel.
maName.isEmpty(),
"ExternalName::importOleItem - empty name" );
116 OSL_ENSURE( !
maModel.
maName.isEmpty(),
"ExternalName::importExternalName - empty name" );
134 "ExternalName::importExternalNameFlags - wrong OLE flag in external name" );
139 sal_Int32 nRows, nCols;
147 appendResultValue< double >( (rStrm.
readuInt8() == 0) ? 0.0 : 1.0 );
184 Reference< XDDELinks > xDdeLinks( aDocProps.
getAnyProperty( PROP_DDELinks ), UNO_QUERY_THROW );
189 Reference< XDDELinkResults > xResults( mxDdeLink, UNO_QUERY_THROW );
195 OSL_FAIL(
"ExternalName::getDdeLinkData - cannot create DDE link" );
200 orDdeServer =
mxDdeLink->getApplication();
214 "ExternalName::setResultSize - wrong link type" );
215 OSL_ENSURE( (nRows > 0) && (nColumns > 0),
"ExternalName::setResultSize - invalid matrix size" );
217 if( (0 < nRows) && (nRows <= rMaxPos.
Row() + 1) && (0 < nColumns) && (nColumns <= rMaxPos.
Col() + 1) )
241 mnFirst = ::std::min( nFirst, nLast );
242 mnLast = ::std::max( nFirst, nLast );
255 mnFirst = ::std::min( nFirst, nLast );
256 mnLast = ::std::max( nFirst, nLast );
289 OUString aDdeService = rAttribs.
getXString( XML_ddeService, OUString() );
290 OUString aDdeTopic = rAttribs.
getXString( XML_ddeTopic, OUString() );
297 xExtName->importDdeItem( rAttribs );
303 OUString aProgId = rAttribs.
getXString( XML_progId, OUString() );
304 OUString aTargetUrl = rRelations.getExternalTargetFromRelId( rAttribs.
getString( R_TOKEN(
id ), OUString() ) );
311 xExtName->importOleItem( rAttribs );
339 case BIFF12_EXTERNALBOOK_BOOK:
342 case BIFF12_EXTERNALBOOK_DDE:
344 OUString aDdeService, aDdeTopic;
345 rStrm >> aDdeService >> aDdeTopic;
349 case BIFF12_EXTERNALBOOK_OLE:
357 OSL_FAIL(
"ExternalLink::importExternalBook - unknown link type" );
375 xExtName->importExternalName( rStrm );
381 ExternalLinkInfo aLinkInfo;
386 aLinkInfo.Type = css::sheet::ExternalLinkType::SELF;
389 aLinkInfo.Type = css::sheet::ExternalLinkType::DOCUMENT;
394 aLinkInfo.Type = css::sheet::ExternalLinkType::SPECIAL;
398 aLinkInfo.Type = css::sheet::ExternalLinkType::DDE;
399 DDELinkInfo aDdeLinkInfo;
403 DDEItemInfo aItemInfo;
405 if( rxExtName->getDdeItemInfo( aItemInfo ) )
406 aItemInfos.push_back( aItemInfo );
408 aLinkInfo.Data <<= aDdeLinkInfo;
412 aLinkInfo.Type = css::sheet::ExternalLinkType::UNKNOWN;
437 if(
mxDocLink.is() && (nCacheIdx >= 0) )
try
440 Reference< XExternalSheetCache > xSheetCache(
mxDocLink->getByIndex( nCacheIdx ), UNO_QUERY_THROW );
458 orSheetRange.
setRange( nTabId1, nTabId2 );
507 Reference< XExternalDocLinks > xDocLinks( aDocProps.
getAnyProperty( PROP_ExternalDocLinks ), UNO_QUERY_THROW );
520 OSL_ENSURE(
meLinkType == eLinkType,
"ExternalLink::setDdeOleTargetUrl - missing classname or target" );
525 if(
const Relation* pRelation = rRelations.getRelationFromRelId( rRelId ) )
531 OSL_ENSURE( !rSheetName.isEmpty(),
"ExternalLink::insertExternalSheet - empty sheet name" );
534 Reference< XExternalSheetCache > xSheetCache =
mxDocLink->addSheetCache( rSheetName,
false );
535 sal_Int32 nCacheIdx = xSheetCache.is() ? xSheetCache->getTokenIndex() : -1;
564 mbUseRefSheets( false )
572 xExtLink->importExternalReference( rAttribs );
581 xExtLink->importExternalRef( rStrm );
606 OSL_ENSURE(
mbUseRefSheets,
"ExternalLinkBuffer::importExternalSheets - missing EXTERNALREFS records" );
608 OSL_ENSURE(
maRefSheets.empty(),
"ExternalLinkBuffer::importExternalSheets - multiple EXTERNALSHEETS records" );
612 size_t nMaxCount = getLimitedValue< size_t, sal_Int64 >( nRefCount, 0, rStrm.
getRemaining() / 12 );
614 for(
size_t nRefId = 0; !rStrm.
isEof() && (nRefId < nMaxCount); ++nRefId )
624 ::std::vector< ExternalLinkInfo > aLinkInfos;
626 aLinkInfos.push_back(
mxSelfRef->getLinkInfo() );
628 aLinkInfos.push_back( rxExtLink->getLinkInfo() );
640 xExtLink =
maLinks.
get( pRefSheets->mnExtRefId );
646 OSL_ENSURE(
mbUseRefSheets,
"ExternalLinkBuffer::getSheetRange - wrong BIFF version" );
650 pExtLink->getSheetRange( aSheetRange, pRefSheets->mnTabId1, pRefSheets->mnTabId2 );
666 &
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.
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)
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.
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
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.
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).
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)
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.
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)
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.
static FunctionLibraryType getFuncLibTypeFromLibraryName(const OUString &rLibraryName)
Returns the library type associated with the passed URL of a function library (function add-in)...
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.
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...
static css::uno::Sequence< typename VectorType::value_type > vectorToSequence(const VectorType &rVector)
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.
ExternalNameModel()
Iconified object link.