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 .
22 #include <rangelst.hxx>
23 #include "xistring.hxx"
25 #include <validat.hxx>
26 #include <tabprotection.hxx>
35 /* ============================================================================
36 Classes to import the big Excel document contents (related to several cells or
37 globals for the document).
42 - Conditional formatting
46 ============================================================================ */
48 // Shared string table ========================================================
50 /** The SST (shared string table) contains all strings used in a BIFF8 file.
52 This class loads the SST, provides access to the strings, and is able to
53 create Calc string or edit cells.
55 class XclImpSst
: protected XclImpRoot
58 explicit XclImpSst( const XclImpRoot
& rRoot
);
60 /** Reads the entire SST record.
61 @descr Import stream must be located at start of a SST record. */
62 void ReadSst( XclImpStream
& rStrm
);
64 /** Returns a pointer to the string with the passed index. */
65 const XclImpString
* GetString( sal_uInt32 nSstIndex
) const;
68 typedef ::std::vector
< XclImpString
> XclImpStringVec
;
69 XclImpStringVec maStrings
; /// List with all strings in the SST.
72 // Hyperlinks =================================================================
74 /** Provides importing hyperlinks and inserting them into a document. */
78 /** delete copy constructor */
79 XclImpHyperlink(const XclImpHyperlink
&) = delete;
80 /** delete copy-assignment operator */
81 const XclImpHyperlink
& operator=(const XclImpHyperlink
&) = delete;
82 /** We don't want anybody to instantiate this class, since it is just a
83 collection of static methods. */
84 XclImpHyperlink() = delete;
86 /** Reads a HLINK record and inserts it into the document.
87 @descr Import stream must be located at start of a HLINK record. */
88 static void ReadHlink( XclImpStream
& rStrm
);
90 /** Reads the (undocumented) embedded hyperlink data and returns the URL. */
91 static OUString
ReadEmbeddedData( XclImpStream
& rStrm
);
93 /** Inserts the URL into a range of cells. Does not modify value or formula cells. */
94 static void InsertUrl( XclImpRoot
& rRoot
, const XclRange
& rXclRange
, const OUString
& rUrl
);
96 /** Convert the sheet name with invalid character(s) in URL when the URL is
97 to a location within the same document (e.g. #'Sheet&Name'.A1). */
98 static void ConvertToValidTabName(OUString
& rName
);
101 // Label ranges ===============================================================
103 /** Provides importing label ranges and inserting them into a document. */
104 class XclImpLabelranges
107 /** delete copy constructor */
108 XclImpLabelranges(const XclImpLabelranges
&) = delete;
109 /** delete copy-assignment operator */
110 const XclImpLabelranges
& operator=(const XclImpLabelranges
&) = delete;
111 /** We don't want anybody to instantiate this class, since it is just a
112 collection of static methods. */
113 XclImpLabelranges() = delete;
114 /** Reads a LABELRANGES record and inserts the label ranges into the document.
115 @descr Import stream must be located at start of a LABELRANGES record. */
116 static void ReadLabelranges( XclImpStream
& rStrm
);
119 // Conditional formatting =====================================================
121 /** Represents a conditional format with condition formulas, and formatting attributes. */
122 class XclImpCondFormat
: protected XclImpRoot
125 explicit XclImpCondFormat( const XclImpRoot
& rRoot
, sal_uInt32 nFormatIndex
);
126 virtual ~XclImpCondFormat() override
;
128 /** Reads a CONDFMT record and initializes this conditional format. */
129 void ReadCondfmt( XclImpStream
& rStrm
);
130 /** Reads a CF record and adds a new condition and the formatting attributes. */
131 void ReadCF( XclImpStream
& rStrm
);
133 /** Inserts this conditional format into the document. */
137 typedef ::std::unique_ptr
< ScConditionalFormat
> ScCondFmtPtr
;
139 ScRangeList maRanges
; /// Destination cell ranges.
140 ScCondFmtPtr mxScCondFmt
; /// Calc conditional format.
141 sal_uInt32 mnFormatIndex
; /// Index of this conditional format in list.
142 sal_uInt16 mnCondCount
; /// Number of conditions to be inserted.
143 sal_uInt16 mnCondIndex
; /// Condition index to be inserted next.
146 /** Imports and collects all conditional formatting of a sheet. */
147 class XclImpCondFormatManager
: protected XclImpRoot
150 explicit XclImpCondFormatManager( const XclImpRoot
& rRoot
);
152 /** Reads a CONDFMT record and starts a new conditional format to be filled from CF records. */
153 void ReadCondfmt( XclImpStream
& rStrm
);
154 /** Reads a CF record and inserts the formatting data to the current conditional format. */
155 void ReadCF( XclImpStream
& rStrm
);
157 /** Inserts the conditional formatting into the document. */
161 std::vector
< std::unique_ptr
<XclImpCondFormat
> >
162 maCondFmtList
; /// List with all conditional formatting.
165 // Data Validation ============================================================
167 /** Imports validation data. */
168 class XclImpValidationManager
: protected XclImpRoot
171 explicit XclImpValidationManager( const XclImpRoot
& rRoot
);
173 /** Reads a DVAL record and sets marks the dropdown arrow control to be ignored. */
174 static void ReadDval( XclImpStream
& rStrm
);
175 /** Reads a DV record and inserts validation data into the document. */
176 void ReadDV( XclImpStream
& rStrm
);
182 ScRangeList maRanges
;
183 ScValidationData maValidData
;
185 explicit DVItem ( ScRangeList aRanges
, const ScValidationData
& rValidData
);
188 std::vector
< std::unique_ptr
<DVItem
> > maDVItems
;
191 // Web queries ================================================================
193 /** Stores the data of one web query. */
197 explicit XclImpWebQuery( const ScRange
& rDestRange
);
199 /** Reads a PARAMQRY record and sets data to the web query. */
200 void ReadParamqry( XclImpStream
& rStrm
);
201 /** Reads a WQSTRING record and sets URL. */
202 void ReadWqstring( XclImpStream
& rStrm
);
203 /** Reads a WEBQRYSETTINGS record and sets refresh rate. */
204 void ReadWqsettings( XclImpStream
& rStrm
);
205 /** Reads a WEBQRYTABLES record and sets source range list. */
206 void ReadWqtables( XclImpStream
& rStrm
);
208 /** Inserts the web query into the document. */
209 void Apply( ScDocument
& rDoc
, const OUString
& rFilterName
);
212 /** Specifies the type of the web query (which ranges are imported). */
213 enum XclImpWebQueryMode
215 xlWQUnknown
, /// Not specified.
216 xlWQDocument
, /// Entire document.
217 xlWQAllTables
, /// All tables.
218 xlWQSpecTables
/// Specific tables.
221 OUString maURL
; /// Source document URL.
222 OUString maTables
; /// List of source range names.
223 ScRange maDestRange
; /// Destination range.
224 XclImpWebQueryMode meMode
; /// Current mode of the web query.
225 sal_uInt16 mnRefresh
; /// Refresh time in minutes.
228 class XclImpWebQueryBuffer
: protected XclImpRoot
231 explicit XclImpWebQueryBuffer( const XclImpRoot
& rRoot
);
233 /** Reads the QSI record and creates a new web query in the buffer. */
234 void ReadQsi( XclImpStream
& rStrm
);
235 /** Reads a PARAMQRY record and sets data to the current web query. */
236 void ReadParamqry( XclImpStream
& rStrm
);
237 /** Reads a WQSTRING record and sets URL to the current web query. */
238 void ReadWqstring( XclImpStream
& rStrm
);
239 /** Reads a WEBQRYSETTINGS record and sets refresh rate to the current web query. */
240 void ReadWqsettings( XclImpStream
& rStrm
);
241 /** Reads a WEBQRYTABLES record and sets source range list to the current web query. */
242 void ReadWqtables( XclImpStream
& rStrm
);
244 /** Inserts all web queries into the document. */
248 typedef std::vector
< XclImpWebQuery
> XclImpWebQueryList
;
249 XclImpWebQueryList maWQList
; /// List of the web query objects.
252 // Decryption =================================================================
254 /** Provides static functions to import stream decryption settings. */
255 class XclImpDecryptHelper
258 /** delete copy constructor */
259 XclImpDecryptHelper(const XclImpDecryptHelper
&) = delete;
260 /** delete copy-assignment operator */
261 const XclImpDecryptHelper
& operator=(const XclImpDecryptHelper
&) = delete;
262 /** We don't want anybody to instantiate this class, since it is just a
263 collection of static methods. */
264 XclImpDecryptHelper() = delete;
266 /** Reads the FILEPASS record, queries a password and sets decryption algorithm.
267 @return Error code that may cause an error message after import. */
268 static const ErrCode
& ReadFilepass( XclImpStream
& rStrm
);
271 // Document protection ========================================================
273 class XclImpDocProtectBuffer
: protected XclImpRoot
276 explicit XclImpDocProtectBuffer( const XclImpRoot
& rRoot
);
278 /** document structure protection flag */
279 void ReadDocProtect( XclImpStream
& rStrm
);
281 /** document windows properties protection flag */
282 void ReadWinProtect( XclImpStream
& rStrm
);
284 void ReadPasswordHash( XclImpStream
& rStrm
);
289 sal_uInt16 mnPassHash
;
294 // Sheet protection ===========================================================
296 class XclImpSheetProtectBuffer
: protected XclImpRoot
299 explicit XclImpSheetProtectBuffer( const XclImpRoot
& rRoot
);
301 void ReadProtect( XclImpStream
& rStrm
, SCTAB nTab
);
303 void ReadOptions( XclImpStream
& rStrm
, SCTAB nTab
);
305 void AppendEnhancedProtection( const ScEnhancedProtection
& rProt
, SCTAB nTab
);
307 void ReadPasswordHash( XclImpStream
& rStrm
, SCTAB nTab
);
315 sal_uInt16 mnPasswordHash
;
316 sal_uInt16 mnOptions
;
317 ::std::vector
< ScEnhancedProtection
> maEnhancedProtections
;
320 Sheet(const Sheet
& r
);
323 Sheet
* GetSheetItem( SCTAB nTab
);
326 typedef ::std::map
<SCTAB
, Sheet
> ProtectedSheetMap
;
327 ProtectedSheetMap maProtectedSheets
;
330 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */