1*38d50f7bSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*38d50f7bSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*38d50f7bSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*38d50f7bSAndrew Rist * distributed with this work for additional information 6*38d50f7bSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*38d50f7bSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*38d50f7bSAndrew Rist * "License"); you may not use this file except in compliance 9*38d50f7bSAndrew Rist * with the License. You may obtain a copy of the License at 10*38d50f7bSAndrew Rist * 11*38d50f7bSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*38d50f7bSAndrew Rist * 13*38d50f7bSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*38d50f7bSAndrew Rist * software distributed under the License is distributed on an 15*38d50f7bSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*38d50f7bSAndrew Rist * KIND, either express or implied. See the License for the 17*38d50f7bSAndrew Rist * specific language governing permissions and limitations 18*38d50f7bSAndrew Rist * under the License. 19*38d50f7bSAndrew Rist * 20*38d50f7bSAndrew Rist *************************************************************/ 21*38d50f7bSAndrew Rist 22*38d50f7bSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #ifndef SC_XILINK_HXX 25cdf0e10cSrcweir #define SC_XILINK_HXX 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <map> 28cdf0e10cSrcweir #include "xllink.hxx" 29cdf0e10cSrcweir #include "xiroot.hxx" 30cdf0e10cSrcweir 31cdf0e10cSrcweir /* ============================================================================ 32cdf0e10cSrcweir Classes for import of different kinds of internal/external references. 33cdf0e10cSrcweir - 3D cell and cell range links 34cdf0e10cSrcweir - External cell and cell range links 35cdf0e10cSrcweir - External defined names 36cdf0e10cSrcweir - Add-in functions 37cdf0e10cSrcweir - DDE links 38cdf0e10cSrcweir - OLE object links 39cdf0e10cSrcweir ============================================================================ */ 40cdf0e10cSrcweir 41cdf0e10cSrcweir // Excel sheet indexes ======================================================== 42cdf0e10cSrcweir 43cdf0e10cSrcweir /** A buffer containing information about names and creation order of sheets. 44cdf0e10cSrcweir 45cdf0e10cSrcweir The first purpose of this buffer is to translate original Excel 46cdf0e10cSrcweir sheet names into Calc sheet indexes. This is not trivial because the filter 47cdf0e10cSrcweir may rename the Calc sheets during creation. This buffer stores the original 48cdf0e10cSrcweir Excel sheet names with the corresponding Calc sheet indexes. 49cdf0e10cSrcweir 50cdf0e10cSrcweir The second purpose is to store the creation order of all sheets inside the 51cdf0e10cSrcweir Excel workbook. The creation order list is contained in the TABID record 52cdf0e10cSrcweir and needed to import the change log. Example: If the list contains 3;1;2 53cdf0e10cSrcweir this means that the second sheet in the file was created first, than the 54cdf0e10cSrcweir third sheet in the file was created and finally the first sheet. 55cdf0e10cSrcweir */ 56cdf0e10cSrcweir class XclImpTabInfo 57cdf0e10cSrcweir { 58cdf0e10cSrcweir public: 59cdf0e10cSrcweir // original Excel sheet names --------------------------------------------- 60cdf0e10cSrcweir 61cdf0e10cSrcweir /** Appends an original Excel sheet name with corresponding Calc sheet index. */ 62cdf0e10cSrcweir void AppendXclTabName( const String& rXclTabName, SCTAB nScTab ); 63cdf0e10cSrcweir /** Inserts a Calc sheet index (increases all following sheet indexes). */ 64cdf0e10cSrcweir void InsertScTab( SCTAB nScTab ); 65cdf0e10cSrcweir 66cdf0e10cSrcweir /** Returns the Calc sheet index from the passed original Excel sheet name. */ 67cdf0e10cSrcweir SCTAB GetScTabFromXclName( const String& rXclTabName ) const; 68cdf0e10cSrcweir 69cdf0e10cSrcweir // record creation order - TABID record ----------------------------------- 70cdf0e10cSrcweir 71cdf0e10cSrcweir /** Reads the TABID record. */ 72cdf0e10cSrcweir void ReadTabid( XclImpStream& rStrm ); 73cdf0e10cSrcweir 74cdf0e10cSrcweir /** Returns the current sheet index calculated from creation index. 75cdf0e10cSrcweir @param nCreatedId The creation index of the sheet (1-based). 76cdf0e10cSrcweir @param nMaxTabId All values greater than this parameter are not used to find the index. 77cdf0e10cSrcweir @return The 0-based index of the sheet nCreatedId if it is contained in the list. 78cdf0e10cSrcweir Example: The buffer is 3;5;2;4;1, nCreatedId is 1 and nMaxTabId is 3. The function will 79cdf0e10cSrcweir return 2 which is the 0-based index of sheet 1 in the list 3;2;1. */ 80cdf0e10cSrcweir sal_uInt16 GetCurrentIndex( sal_uInt16 nCreatedId, sal_uInt16 nMaxTabId = 0xFFFF ) const; 81cdf0e10cSrcweir 82cdf0e10cSrcweir private: 83cdf0e10cSrcweir typedef ::std::map< String, SCTAB > XclTabNameMap; 84cdf0e10cSrcweir 85cdf0e10cSrcweir XclTabNameMap maTabNames; /// All Excel sheet names with Calc sheet index. 86cdf0e10cSrcweir ScfUInt16Vec maTabIdVec; /// The vector with sheet indexes. 87cdf0e10cSrcweir }; 88cdf0e10cSrcweir 89cdf0e10cSrcweir // External names ============================================================= 90cdf0e10cSrcweir 91cdf0e10cSrcweir /** Type of an external name. */ 92cdf0e10cSrcweir enum XclImpExtNameType 93cdf0e10cSrcweir { 94cdf0e10cSrcweir xlExtName, /// An external defined name. 95cdf0e10cSrcweir xlExtAddIn, /// An add-in function name. 96cdf0e10cSrcweir xlExtDDE, /// A DDE link range. 97cdf0e10cSrcweir xlExtOLE, /// An OLE object link. 98cdf0e10cSrcweir xlExtEuroConvert /// An external in Excel, but internal in OO function name. 99cdf0e10cSrcweir }; 100cdf0e10cSrcweir 101cdf0e10cSrcweir // ---------------------------------------------------------------------------- 102cdf0e10cSrcweir 103cdf0e10cSrcweir class XclImpCachedMatrix; 104cdf0e10cSrcweir class ScTokenArray; 105cdf0e10cSrcweir class XclImpSupbook; 106cdf0e10cSrcweir 107cdf0e10cSrcweir /** Stores contents of an external name. 108cdf0e10cSrcweir @descr Supported: External defined names, AddIn names, DDE links and OLE objects. */ 109cdf0e10cSrcweir class XclImpExtName 110cdf0e10cSrcweir { 111cdf0e10cSrcweir public: 112cdf0e10cSrcweir /** Reads the external name from the stream. */ 113cdf0e10cSrcweir explicit XclImpExtName( const XclImpSupbook& rSupbook, XclImpStream& rStrm, 114cdf0e10cSrcweir XclSupbookType eSubType, ExcelToSc* pFormulaConv ); 115cdf0e10cSrcweir ~XclImpExtName(); 116cdf0e10cSrcweir 117cdf0e10cSrcweir /** Create and apply the cached list of this DDE Link to the document. */ 118cdf0e10cSrcweir void CreateDdeData( ScDocument& rDoc, 119cdf0e10cSrcweir const String& rApplc, const String& rExtDoc ) const; 120cdf0e10cSrcweir 121cdf0e10cSrcweir void CreateExtNameData( ScDocument& rDoc, sal_uInt16 nFileId ) const; 122cdf0e10cSrcweir 123cdf0e10cSrcweir bool HasFormulaTokens() const; 124cdf0e10cSrcweir GetType() const125cdf0e10cSrcweir inline XclImpExtNameType GetType() const { return meType; } GetName() const126cdf0e10cSrcweir inline const String& GetName() const { return maName; } GetStorageId() const127cdf0e10cSrcweir inline sal_uInt32 GetStorageId() const { return mnStorageId; } 128cdf0e10cSrcweir 129cdf0e10cSrcweir private: 130cdf0e10cSrcweir typedef ::std::auto_ptr< XclImpCachedMatrix > XclImpCachedMatrixPtr; 131cdf0e10cSrcweir typedef ::std::auto_ptr< ScTokenArray > TokenArrayPtr; 132cdf0e10cSrcweir 133cdf0e10cSrcweir XclImpCachedMatrixPtr mxDdeMatrix; /// Cached results of the DDE link. 134cdf0e10cSrcweir TokenArrayPtr mxArray; /// Formula tokens for external name. 135cdf0e10cSrcweir String maName; /// The name of the external name. 136cdf0e10cSrcweir sal_uInt32 mnStorageId; /// Storage ID for OLE object storages. 137cdf0e10cSrcweir XclImpExtNameType meType; /// Type of the external name. 138cdf0e10cSrcweir }; 139cdf0e10cSrcweir 140cdf0e10cSrcweir // Import link manager ======================================================== 141cdf0e10cSrcweir 142cdf0e10cSrcweir class XclImpLinkManagerImpl; 143cdf0e10cSrcweir 144cdf0e10cSrcweir /** This is the central class for the import of all internal/external links. 145cdf0e10cSrcweir @descr This manager stores all data about external documents with their sheets 146cdf0e10cSrcweir and cached cell contents. Additionally it handles external names, such as add-in 147cdf0e10cSrcweir function names, DDE links, and OLE object links. 148cdf0e10cSrcweir File contents in BIFF8: 149cdf0e10cSrcweir - Record SUPBOOK: Contains the name of an external document and the names of its sheets. 150cdf0e10cSrcweir This record is optionally followed by NAME, EXTERNNAME, XCT and CRN records. 151cdf0e10cSrcweir - Record XCT: Contains the number and sheet index of the following CRN records. 152cdf0e10cSrcweir - Record CRN: Contains addresses (row and column) and values of external referenced cells. 153cdf0e10cSrcweir - Record NAME: Contains defined names of the own workbook. 154cdf0e10cSrcweir - Record EXTERNNAME: Contains external defined names, DDE links, or OLE object links. 155cdf0e10cSrcweir - Record EXTERNSHEET: Contains indexes to URLs of external documents (SUPBOOKs) 156cdf0e10cSrcweir and sheet indexes for each external reference used anywhere in the workbook. 157cdf0e10cSrcweir This record follows a list of SUPBOOK records (with their attached records). 158cdf0e10cSrcweir */ 159cdf0e10cSrcweir class XclImpLinkManager : protected XclImpRoot 160cdf0e10cSrcweir { 161cdf0e10cSrcweir public: 162cdf0e10cSrcweir explicit XclImpLinkManager( const XclImpRoot& rRoot ); 163cdf0e10cSrcweir ~XclImpLinkManager(); 164cdf0e10cSrcweir 165cdf0e10cSrcweir /** Reads the EXTERNSHEET record. */ 166cdf0e10cSrcweir void ReadExternsheet( XclImpStream& rStrm ); 167cdf0e10cSrcweir /** Reads a SUPBOOK record. */ 168cdf0e10cSrcweir void ReadSupbook( XclImpStream& rStrm ); 169cdf0e10cSrcweir /** Reads an XCT record and appends it to the current SUPBOOK. */ 170cdf0e10cSrcweir void ReadXct( XclImpStream& rStrm ); 171cdf0e10cSrcweir /** Reads a CRN record and appends it to the current SUPBOOK. */ 172cdf0e10cSrcweir void ReadCrn( XclImpStream& rStrm ); 173cdf0e10cSrcweir /** Reads an EXTERNNAME record and appends it to the current SUPBOOK. */ 174cdf0e10cSrcweir void ReadExternname( XclImpStream& rStrm, ExcelToSc* pFormulaConv = NULL ); 175cdf0e10cSrcweir 176cdf0e10cSrcweir /** Returns true, if the specified XTI entry contains an internal reference. */ 177cdf0e10cSrcweir bool IsSelfRef( sal_uInt16 nXtiIndex ) const; 178cdf0e10cSrcweir /** Returns the Calc sheet index range of the specified XTI entry. 179cdf0e10cSrcweir @return true = XTI data found, returned sheet index range is valid. */ 180cdf0e10cSrcweir bool GetScTabRange( 181cdf0e10cSrcweir SCTAB& rnFirstScTab, SCTAB& rnLastScTab, 182cdf0e10cSrcweir sal_uInt16 nXtiIndex ) const; 183cdf0e10cSrcweir /** Returns the specified external name or 0 on error. */ 184cdf0e10cSrcweir const XclImpExtName* GetExternName( sal_uInt16 nXtiIndex, sal_uInt16 nExtName ) const; 185cdf0e10cSrcweir 186cdf0e10cSrcweir const String* GetSupbookUrl( sal_uInt16 nXtiIndex ) const; 187cdf0e10cSrcweir 188cdf0e10cSrcweir const String& GetSupbookTabName( sal_uInt16 nXti, sal_uInt16 nXtiTab ) const; 189cdf0e10cSrcweir 190cdf0e10cSrcweir /** Tries to decode the URL of the specified XTI entry to OLE or DDE link components. 191cdf0e10cSrcweir @descr For DDE links: Decodes to application name and topic. 192cdf0e10cSrcweir For OLE object links: Decodes to class name and document URL. 193cdf0e10cSrcweir @return true = decoding was successful, returned strings are valid (not empty). */ 194cdf0e10cSrcweir bool GetLinkData( String& rApplic, String& rTopic, sal_uInt16 nXtiIndex ) const; 195cdf0e10cSrcweir /** Returns the specified macro name or an empty string on error. */ 196cdf0e10cSrcweir const String& GetMacroName( sal_uInt16 nExtSheet, sal_uInt16 nExtName ) const; 197cdf0e10cSrcweir 198cdf0e10cSrcweir private: 199cdf0e10cSrcweir typedef ::std::auto_ptr< XclImpLinkManagerImpl > XclImpLinkMgrImplPtr; 200cdf0e10cSrcweir XclImpLinkMgrImplPtr mxImpl; 201cdf0e10cSrcweir }; 202cdf0e10cSrcweir 203cdf0e10cSrcweir // ============================================================================ 204cdf0e10cSrcweir 205cdf0e10cSrcweir #endif 206cdf0e10cSrcweir 207