1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_SC_SOURCE_FILTER_INC_XILINK_HXX
21 #define INCLUDED_SC_SOURCE_FILTER_INC_XILINK_HXX
32 class SharedStringPool
;
36 /* ============================================================================
37 Classes for import of different kinds of internal/external references.
38 - 3D cell and cell range links
39 - External cell and cell range links
40 - External defined names
44 ============================================================================ */
46 // Excel sheet indexes ========================================================
48 /** A buffer containing information about names and creation order of sheets.
50 The first purpose of this buffer is to translate original Excel
51 sheet names into Calc sheet indexes. This is not trivial because the filter
52 may rename the Calc sheets during creation. This buffer stores the original
53 Excel sheet names with the corresponding Calc sheet indexes.
55 The second purpose is to store the creation order of all sheets inside the
56 Excel workbook. The creation order list is contained in the TABID record
57 and needed to import the change log. Example: if the list contains 3;1;2
58 this means that the second sheet in the file was created first, then the
59 third sheet in the file was created and finally the first sheet.
64 // original Excel sheet names ---------------------------------------------
66 /** Appends an original Excel sheet name with corresponding Calc sheet index. */
67 void AppendXclTabName( const OUString
& rXclTabName
, SCTAB nScTab
);
68 /** Inserts a Calc sheet index (increases all following sheet indexes). */
69 void InsertScTab( SCTAB nScTab
);
71 /** Returns the Calc sheet index from the passed original Excel sheet name. */
72 SCTAB
GetScTabFromXclName( const OUString
& rXclTabName
) const;
74 // record creation order - TABID record -----------------------------------
76 /** Reads the TABID record. */
77 void ReadTabid( XclImpStream
& rStrm
);
79 /** Returns the current sheet index calculated from creation index.
80 @param nCreatedId The creation index of the sheet (1-based).
81 @param nMaxTabId All values greater than this parameter are not used to find the index.
82 @return The 0-based index of the sheet nCreatedId if it is contained in the list.
83 Example: The buffer is 3;5;2;4;1, nCreatedId is 1 and nMaxTabId is 3. The function will
84 return 2 which is the 0-based index of sheet 1 in the list 3;2;1. */
85 sal_uInt16
GetCurrentIndex( sal_uInt16 nCreatedId
, sal_uInt16 nMaxTabId
) const;
88 typedef ::std::map
< OUString
, SCTAB
> XclTabNameMap
;
90 XclTabNameMap maTabNames
; /// All Excel sheet names with Calc sheet index.
91 ScfUInt16Vec maTabIdVec
; /// The vector with sheet indexes.
94 // External names =============================================================
96 /** Type of an external name. */
97 enum XclImpExtNameType
99 xlExtName
, /// An external defined name.
100 xlExtAddIn
, /// An add-in function name.
101 xlExtDDE
, /// A DDE link range.
102 xlExtOLE
, /// An OLE object link.
103 xlExtEuroConvert
/// An external in Excel, but internal in OO function name.
106 class XclImpCachedMatrix
;
110 /** Stores contents of an external name.
111 @descr Supported: External defined names, AddIn names, DDE links and OLE objects. */
115 * MOper, multiple operands, stores cached values of external range
116 * specified in the record.
121 MOper(svl::SharedStringPool
& rPool
, XclImpStream
& rStrm
);
122 const ScMatrix
& GetCache() const;
124 ScMatrixRef mxCached
;
128 /** Reads the external name from the stream. */
129 explicit XclImpExtName( XclImpSupbook
& rSupbook
, XclImpStream
& rStrm
,
130 XclSupbookType eSubType
, ExcelToSc
* pFormulaConv
);
133 /** Create and apply the cached list of this DDE Link to the document. */
134 void CreateDdeData( ScDocument
& rDoc
,
135 const OUString
& rApplc
, const OUString
& rExtDoc
) const;
137 void CreateExtNameData( const ScDocument
& rDoc
, sal_uInt16 nFileId
) const;
140 * Create OLE link data. OLE link data is converted to external
141 * reference, since OLE link doesn't work cross-platform, and is not very
142 * reliable even on Windows.
144 bool CreateOleData(ScDocument
& rDoc
, const OUString
& rUrl
,
145 sal_uInt16
& rFileId
, OUString
& rTabName
, ScRange
& rRange
) const;
147 bool HasFormulaTokens() const;
149 XclImpExtNameType
GetType() const { return meType
; }
150 const OUString
& GetName() const { return maName
; }
151 sal_uInt32
GetStorageId() const { return mnStorageId
; }
154 typedef ::std::unique_ptr
< XclImpCachedMatrix
> XclImpCachedMatrixPtr
;
155 typedef ::std::unique_ptr
< ScTokenArray
> TokenArrayPtr
;
157 XclImpCachedMatrixPtr mxDdeMatrix
; /// Cached results of the DDE link.
158 std::unique_ptr
<MOper
> mpMOper
; /// Cached values for OLE link
159 TokenArrayPtr mxArray
; /// Formula tokens for external name.
160 OUString maName
; /// The name of the external name.
161 sal_uInt32 mnStorageId
; /// Storage ID for OLE object storages.
162 XclImpExtNameType meType
; /// Type of the external name.
165 // Import link manager ========================================================
167 class XclImpLinkManagerImpl
;
169 /** This is the central class for the import of all internal/external links.
170 @descr This manager stores all data about external documents with their sheets
171 and cached cell contents. Additionally it handles external names, such as add-in
172 function names, DDE links, and OLE object links.
173 File contents in BIFF8:
174 - Record SUPBOOK: Contains the name of an external document and the names of its sheets.
175 This record is optionally followed by NAME, EXTERNNAME, XCT and CRN records.
176 - Record XCT: Contains the number and sheet index of the following CRN records.
177 - Record CRN: Contains addresses (row and column) and values of external referenced cells.
178 - Record NAME: Contains defined names of the own workbook.
179 - Record EXTERNNAME: Contains external defined names, DDE links, or OLE object links.
180 - Record EXTERNSHEET: Contains indexes to URLs of external documents (SUPBOOKs)
181 and sheet indexes for each external reference used anywhere in the workbook.
182 This record follows a list of SUPBOOK records (with their attached records).
184 class XclImpLinkManager
: protected XclImpRoot
187 explicit XclImpLinkManager( const XclImpRoot
& rRoot
);
188 virtual ~XclImpLinkManager() override
;
190 /** Reads the EXTERNSHEET record. */
191 void ReadExternsheet( XclImpStream
& rStrm
);
192 /** Reads a SUPBOOK record. */
193 void ReadSupbook( XclImpStream
& rStrm
);
194 /** Reads an XCT record and appends it to the current SUPBOOK. */
195 void ReadXct( XclImpStream
& rStrm
);
196 /** Reads a CRN record and appends it to the current SUPBOOK. */
197 void ReadCrn( XclImpStream
& rStrm
);
198 /** Reads an EXTERNNAME record and appends it to the current SUPBOOK. */
199 void ReadExternname( XclImpStream
& rStrm
, ExcelToSc
* pFormulaConv
);
201 /** Returns true, if the specified XTI entry contains an internal reference. */
202 bool IsSelfRef( sal_uInt16 nXtiIndex
) const;
203 /** Returns the Calc sheet index range of the specified XTI entry.
204 @return true = XTI data found, returned sheet index range is valid. */
206 SCTAB
& rnFirstScTab
, SCTAB
& rnLastScTab
,
207 sal_uInt16 nXtiIndex
) const;
208 /** Returns the specified external name or 0 on error. */
209 const XclImpExtName
* GetExternName( sal_uInt16 nXtiIndex
, sal_uInt16 nExtName
) const;
211 const OUString
* GetSupbookUrl( sal_uInt16 nXtiIndex
) const;
213 const OUString
& GetSupbookTabName( sal_uInt16 nXti
, sal_uInt16 nXtiTab
) const;
215 /** Tries to decode the URL of the specified XTI entry to OLE or DDE link components.
216 @descr For DDE links: Decodes to application name and topic.
217 For OLE object links: Decodes to class name and document URL.
218 @return true = decoding was successful, returned strings are valid (not empty). */
219 bool GetLinkData( OUString
& rApplic
, OUString
& rTopic
, sal_uInt16 nXtiIndex
) const;
220 /** Returns the specified macro name or an empty string on error. */
221 const OUString
& GetMacroName( sal_uInt16 nExtSheet
, sal_uInt16 nExtName
) const;
224 typedef ::std::unique_ptr
< XclImpLinkManagerImpl
> XclImpLinkMgrImplPtr
;
225 XclImpLinkMgrImplPtr mxImpl
;
230 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */