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_XECONTENT_HXX
21 #define INCLUDED_SC_SOURCE_FILTER_INC_XECONTENT_HXX
24 #include <rangelst.hxx>
25 #include "xladdress.hxx"
26 #include "xerecord.hxx"
28 #include "xestring.hxx"
29 #include "xeextlst.hxx"
30 #include "xlformula.hxx"
32 #include <colorscale.hxx>
34 /* ============================================================================
35 Classes to export the big Excel document contents (related to several cells or
36 globals for the sheet or document).
41 - Conditional formatting
44 ============================================================================ */
46 // Shared string table ========================================================
50 /** Provides export of the SST (shared string table) record.
51 @descr Contains all strings in the document and writes the SST. */
52 class XclExpSst
: public XclExpRecordBase
56 virtual ~XclExpSst() override
;
58 /** Inserts a new string into the table.
59 @return The index of the string in the SST, used in other records. */
60 sal_uInt32
Insert( const XclExpStringRef
& xString
);
62 /** Writes the complete SST and EXTSST records. */
63 virtual void Save( XclExpStream
& rStrm
) override
;
64 virtual void SaveXml( XclExpXmlStream
& rStrm
) override
;
67 typedef std::unique_ptr
< XclExpSstImpl
> XclExpSstImplPtr
;
68 XclExpSstImplPtr mxImpl
;
71 // Merged cells ===============================================================
73 /** Represents a MERGEDCELLS record containing all merged cell ranges in a sheet. */
74 class XclExpMergedcells
: public XclExpRecordBase
, protected XclExpRoot
77 explicit XclExpMergedcells( const XclExpRoot
& rRoot
);
79 /** Appends a new range to the list of merged cell ranges. */
80 void AppendRange( const ScRange
& rRange
, sal_uInt32 nBaseXFId
);
81 /** Returns the XF identifier of the top-left cell in a merged range. */
82 sal_uInt32
GetBaseXFId( const ScAddress
& rPos
) const;
84 /** Writes the record, if it contains at least one merged cell range. */
85 virtual void Save( XclExpStream
& rStrm
) override
;
86 virtual void SaveXml( XclExpXmlStream
& rStrm
) override
;
89 ScRangeList maMergedRanges
; /// All merged cell ranges of the sheet.
90 ScfUInt32Vec maBaseXFIds
; /// The XF identifiers of the top-left cells.
93 // Hyperlinks =================================================================
97 /** Provides export of hyperlink data. */
98 class XclExpHyperlink
: public XclExpRecord
101 /** Constructs the HLINK record from a URL text field. */
102 explicit XclExpHyperlink( const XclExpRoot
& rRoot
,
103 const SvxURLField
& rUrlField
, const ScAddress
& rScPos
);
104 virtual ~XclExpHyperlink() override
;
106 /** Returns the cell representation text or 0, if not available. */
107 const OUString
* GetRepr() const { return m_Repr
.isEmpty() ? nullptr : &m_Repr
; }
109 virtual void SaveXml( XclExpXmlStream
& rStrm
) override
;
111 void WriteEmbeddedData( XclExpStream
& rStrm
);
113 /** Builds file name from the passed file URL. Tries to convert to relative file name.
114 @param rnLevel (out-param) The parent directory level.
115 @param rbRel (out-param) true = path is relative.
116 @param bEncoded if true return an IURI encoded name, not a DOS name. */
117 static OUString
BuildFileName(
118 sal_uInt16
& rnLevel
, bool& rbRel
,
119 const OUString
& rUrl
, const XclExpRoot
& rRoot
, bool bEncoded
);
122 /** Writes the body of the HLINK record. */
123 virtual void WriteBody( XclExpStream
& rStrm
) override
;
126 typedef std::unique_ptr
< SvStream
> SvStreamPtr
;
128 ScAddress
const maScPos
; /// Position of the hyperlink.
129 OUString m_Repr
; /// Cell representation text.
130 SvStreamPtr mxVarData
; /// Buffer stream with variable data.
131 sal_uInt32 mnFlags
; /// Option flags.
132 XclExpStringRef mxTextMark
; /// Location within m_Repr
133 OUString msTarget
; /// Target URL
136 typedef XclExpRecordList
< XclExpHyperlink
> XclExpHyperlinkList
;
138 // Label ranges ===============================================================
140 /** Provides export of the row/column label range list of a sheet. */
141 class XclExpLabelranges
: public XclExpRecordBase
, protected XclExpRoot
144 /** Fills the cell range lists with all ranges of the current sheet. */
145 explicit XclExpLabelranges( const XclExpRoot
& rRoot
);
147 /** Writes the LABELRANGES record if it contains at least one range. */
148 virtual void Save( XclExpStream
& rStrm
) override
;
151 /** Fills the specified range list with all label headers of the current sheet.
152 @param rRanges The cell range list to fill.
153 @param xLabelRangesRef The core range list with all ranges.
154 @param nScTab The current Calc sheet index. */
155 static void FillRangeList( ScRangeList
& rScRanges
,
156 const ScRangePairListRef
& xLabelRangesRef
, SCTAB nScTab
);
159 ScRangeList maRowRanges
; /// Cell range list for row labels.
160 ScRangeList maColRanges
; /// Cell range list for column labels.
163 // Conditional formatting =====================================================
167 /** Represents a CF record that contains one condition of a conditional format. */
168 class XclExpCF
: public XclExpRecord
, protected XclExpRoot
171 explicit XclExpCF( const XclExpRoot
& rRoot
, const ScCondFormatEntry
& rFormatEntry
, sal_Int32 nPriority
, ScAddress aOrigin
);
172 virtual ~XclExpCF() override
;
174 virtual void SaveXml( XclExpXmlStream
& rStrm
) override
;
177 /** Writes the body of the CF record. */
178 virtual void WriteBody( XclExpStream
& rStrm
) override
;
181 typedef std::unique_ptr
< XclExpCFImpl
> XclExpCFImplPtr
;
182 XclExpCFImplPtr mxImpl
;
185 class XclExpDateFormat
: public XclExpRecord
, protected XclExpRoot
188 explicit XclExpDateFormat( const XclExpRoot
& rRoot
, const ScCondDateFormatEntry
& rFormatEntry
, sal_Int32 nPriority
);
189 virtual ~XclExpDateFormat() override
;
191 virtual void SaveXml( XclExpXmlStream
& rStrm
) override
;
194 const ScCondDateFormatEntry
& mrFormatEntry
;
195 sal_Int32
const mnPriority
;
198 class XclExpCfvo
: public XclExpRecord
, protected XclExpRoot
201 explicit XclExpCfvo( const XclExpRoot
& rRoot
, const ScColorScaleEntry
& rFormatEntry
, const ScAddress
& rPos
, bool bFirst
= true);
203 virtual void SaveXml( XclExpXmlStream
& rStrm
) override
;
205 const ScColorScaleEntry
& mrEntry
;
206 ScAddress
const maSrcPos
;
210 class XclExpColScaleCol
: public XclExpRecord
, protected XclExpRoot
213 explicit XclExpColScaleCol( const XclExpRoot
& rRoot
, const Color
& rColor
);
214 virtual ~XclExpColScaleCol() override
;
216 virtual void SaveXml( XclExpXmlStream
& rStrm
) override
;
218 const Color
& mrColor
;
221 /** Represents a CONDFMT record that contains all conditions of a conditional format.
222 @descr Contains the conditions which are stored in CF records. */
223 class XclExpCondfmt
: public XclExpRecord
, protected XclExpRoot
226 explicit XclExpCondfmt( const XclExpRoot
& rRoot
, const ScConditionalFormat
& rCondFormat
, const XclExtLstRef
& xExtLst
, sal_Int32
& rIndex
);
227 virtual ~XclExpCondfmt() override
;
229 /** Returns true, if this conditional format contains at least one cell range and CF record. */
230 bool IsValidForBinary() const;
231 bool IsValidForXml() const;
233 /** Writes the CONDFMT record with following CF records, if there is valid data. */
234 virtual void Save( XclExpStream
& rStrm
) override
;
235 virtual void SaveXml( XclExpXmlStream
& rStrm
) override
;
238 /** Writes the body of the CONDFMT record. */
239 virtual void WriteBody( XclExpStream
& rStrm
) override
;
242 typedef XclExpRecordList
< XclExpRecord
> XclExpCFList
;
244 XclExpCFList maCFList
; /// List of CF records.
245 XclRangeList maXclRanges
; /// Cell ranges for this conditional format.
246 OUString msSeqRef
; /// OOXML Sequence of References
249 class XclExpColorScale
: public XclExpRecord
, protected XclExpRoot
252 explicit XclExpColorScale( const XclExpRoot
& rRoot
, const ScColorScaleFormat
& rFormat
, sal_Int32 nPriority
);
254 virtual void SaveXml( XclExpXmlStream
& rStrm
) override
;
256 typedef XclExpRecordList
< XclExpCfvo
> XclExpCfvoList
;
257 typedef XclExpRecordList
< XclExpColScaleCol
> XclExpColScaleColList
;
259 XclExpCfvoList maCfvoList
;
260 XclExpColScaleColList maColList
;
261 sal_Int32
const mnPriority
;
264 class XclExpDataBar
: public XclExpRecord
, protected XclExpRoot
267 explicit XclExpDataBar( const XclExpRoot
& rRoot
, const ScDataBarFormat
& rFormat
, sal_Int32 nPriority
, const OString
& rGUID
);
269 virtual void SaveXml( XclExpXmlStream
& rStrm
) override
;
271 std::unique_ptr
<XclExpCfvo
> mpCfvoLowerLimit
;
272 std::unique_ptr
<XclExpCfvo
> mpCfvoUpperLimit
;
273 std::unique_ptr
<XclExpColScaleCol
> mpCol
;
275 const ScDataBarFormat
& mrFormat
;
276 sal_Int32
const mnPriority
;
277 OString
const maGUID
;
280 class XclExpIconSet
: public XclExpRecord
, protected XclExpRoot
283 explicit XclExpIconSet( const XclExpRoot
& rRoot
, const ScIconSetFormat
& rFormat
, sal_Int32 nPriority
);
285 virtual void SaveXml( XclExpXmlStream
& rStrm
) override
;
287 typedef XclExpRecordList
< XclExpCfvo
> XclExpCfvoList
;
289 XclExpCfvoList maCfvoList
;
290 const ScIconSetFormat
& mrFormat
;
291 sal_Int32
const mnPriority
;
294 /** Contains all conditional formats of a specific sheet. */
295 class XclExpCondFormatBuffer
: public XclExpRecordBase
, protected XclExpRoot
298 /** Constructs CONDFMT and CF records containing the conditional formats of the current sheet. */
299 explicit XclExpCondFormatBuffer( const XclExpRoot
& rRoot
, const XclExtLstRef
& xExtLst
);
301 /** Writes all contained CONDFMT records with their CF records. */
302 virtual void Save( XclExpStream
& rStrm
) override
;
303 virtual void SaveXml( XclExpXmlStream
& rStrm
) override
;
306 typedef XclExpRecordList
< XclExpCondfmt
> XclExpCondfmtList
;
307 XclExpCondfmtList maCondfmtList
; /// List of CONDFMT records.
310 // Data Validation ============================================================
312 /** Provides export of the data of a DV record.
313 @descr This record contains the settings for a data validation. In detail
314 this is a pointer to the core validation data and a cell range list with all
315 affected cells. The handle index is used to optimize list search algorithm. */
316 class XclExpDV
: public XclExpRecord
, protected XclExpRoot
319 explicit XclExpDV( const XclExpRoot
& rRoot
, sal_uLong nScHandle
);
320 virtual ~XclExpDV() override
;
322 /** Returns the core handle of the validation data. */
323 sal_uLong
GetScHandle() const { return mnScHandle
; }
325 /** Inserts a new cell range into the cell range list. */
326 void InsertCellRange( const ScRange
& rPos
);
327 /** Converts the Calc range list to the Excel range list.
328 @return false = Resulting range list empty - do not write this record. */
331 virtual void SaveXml( XclExpXmlStream
& rStrm
) override
;
334 /** Writes the body of the DV record. */
335 virtual void WriteBody( XclExpStream
& rStrm
) override
;
338 ScRangeList maScRanges
; /// Calc range list with all affected cells.
339 XclRangeList maXclRanges
; /// Excel range list with all affected cells.
340 XclExpString maPromptTitle
; /// The prompt title.
341 XclExpString maPromptText
; /// The prompt text.
342 XclExpString maErrorTitle
; /// The error title.
343 XclExpString maErrorText
; /// The error text.
344 XclExpStringRef mxString1
; /// String for first condition formula.
345 XclTokenArrayRef mxTokArr1
; /// Formula for first condition.
346 OUString msFormula1
; /// OOXML Formula for first condition.
347 XclTokenArrayRef mxTokArr2
; /// Formula for second condition.
348 OUString msFormula2
; /// OOXML Formula for second condition.
349 sal_uInt32 mnFlags
; /// Miscellaneous flags.
350 sal_uLong mnScHandle
; /// The core handle for quick list search.
353 /** This class contains the DV record list following the DVAL record. */
354 class XclExpDval
: public XclExpRecord
, protected XclExpRoot
357 explicit XclExpDval( const XclExpRoot
& rRoot
);
358 virtual ~XclExpDval() override
;
360 /** Inserts the cell range into the range list of the DV record with the specified handle. */
361 void InsertCellRange( const ScRange
& rRange
, sal_uLong nScHandle
);
363 /** Writes the DVAL record and the DV record list. */
364 virtual void Save( XclExpStream
& rStrm
) override
;
365 virtual void SaveXml( XclExpXmlStream
& rStrm
) override
;
368 /** Searches for or creates a XclExpDV record object with the specified handle. */
369 XclExpDV
& SearchOrCreateDv( sal_uLong nScHandle
);
371 /** Writes the body of the DVAL record. */
372 virtual void WriteBody( XclExpStream
& rStrm
) override
;
375 typedef XclExpRecordList
< XclExpDV
> XclExpDVList
;
376 typedef XclExpDVList::RecordRefType XclExpDVRef
;
378 XclExpDVList maDVList
; /// List of DV records
379 XclExpDVRef mxLastFoundDV
; /// For search optimization.
382 // Web Queries ================================================================
384 /** Contains all records for a web query (linked tables in an HTML document).
385 @descr mode 1 (entire document): mpQryTables==0, mbEntireDoc==true;
386 mode 2 (all tables): mpQryTables==0, mbEntireDoc==false;
387 mode 3 (custom range list): mpQryTables!=0, mbEntireDoc==false. */
388 class XclExpWebQuery
: public XclExpRecordBase
391 /** Constructs a web query record container with settings from Calc. */
392 explicit XclExpWebQuery(
393 const OUString
& rRangeName
,
394 const OUString
& rUrl
,
395 const OUString
& rSource
,
396 sal_Int32 nRefrSecs
);
397 virtual ~XclExpWebQuery() override
;
399 /** Writes all needed records for this web query. */
400 virtual void Save( XclExpStream
& rStrm
) override
;
403 XclExpString
const maDestRange
; /// Destination range.
404 XclExpString
const maUrl
; /// Source document URL.
405 XclExpStringRef mxQryTables
; /// List of source range names.
406 sal_Int16 mnRefresh
; /// Refresh time in minutes.
407 bool mbEntireDoc
; /// true = entire document.
410 /** Contains all web query records for this document. */
411 class XclExpWebQueryBuffer
: public XclExpRecordList
< XclExpWebQuery
>
414 explicit XclExpWebQueryBuffer( const XclExpRoot
& rRoot
);
419 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */