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
23 #include "rangelst.hxx"
24 #include "xlcontent.hxx"
25 #include "xladdress.hxx"
26 #include "xerecord.hxx"
28 #include "xestring.hxx"
29 #include "xeformula.hxx"
30 #include "xeextlst.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
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 an URL text field. */
102 explicit XclExpHyperlink( const XclExpRoot
& rRoot
,
103 const SvxURLField
& rUrlField
, const ScAddress
& rScPos
);
104 virtual ~XclExpHyperlink();
106 /** Returns the cell representation text or 0, if not available. */
107 inline 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 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
134 bool mbSetDisplay
; /// True if display attribute it written
137 typedef XclExpRecordList
< XclExpHyperlink
> XclExpHyperlinkList
;
139 // Label ranges ===============================================================
141 /** Provides export of the row/column label range list of a sheet. */
142 class XclExpLabelranges
: public XclExpRecordBase
, protected XclExpRoot
145 /** Fills the cell range lists with all ranges of the current sheet. */
146 explicit XclExpLabelranges( const XclExpRoot
& rRoot
);
148 /** Writes the LABELRANGES record if it contains at least one range. */
149 virtual void Save( XclExpStream
& rStrm
) override
;
152 /** Fills the specified range list with all label headers of the current sheet.
153 @param rRanges The cell range list to fill.
154 @param xLabelRangesRef The core range list with all ranges.
155 @param nScTab The current Calc sheet index. */
156 static void FillRangeList( ScRangeList
& rScRanges
,
157 const ScRangePairListRef
& xLabelRangesRef
, SCTAB nScTab
);
160 ScRangeList maRowRanges
; /// Cell range list for row labels.
161 ScRangeList maColRanges
; /// Cell range list for column labels.
164 // Conditional formatting =====================================================
166 class ScCondFormatEntry
;
169 /** Represents a CF record that contains one condition of a conditional format. */
170 class XclExpCF
: public XclExpRecord
, protected XclExpRoot
173 explicit XclExpCF( const XclExpRoot
& rRoot
, const ScCondFormatEntry
& rFormatEntry
, sal_Int32 nPriority
);
176 virtual void SaveXml( XclExpXmlStream
& rStrm
) override
;
179 /** Writes the body of the CF record. */
180 virtual void WriteBody( XclExpStream
& rStrm
) override
;
183 typedef std::unique_ptr
< XclExpCFImpl
> XclExpCFImplPtr
;
184 XclExpCFImplPtr mxImpl
;
187 class XclExpDateFormat
: public XclExpRecord
, protected XclExpRoot
190 explicit XclExpDateFormat( const XclExpRoot
& rRoot
, const ScCondDateFormatEntry
& rFormatEntry
, sal_Int32 nPriority
);
191 virtual ~XclExpDateFormat();
193 virtual void SaveXml( XclExpXmlStream
& rStrm
) override
;
196 const ScCondDateFormatEntry
& mrFormatEntry
;
197 sal_Int32 mnPriority
;
200 class XclExpCfvo
: public XclExpRecord
, protected XclExpRoot
203 explicit XclExpCfvo( const XclExpRoot
& rRoot
, const ScColorScaleEntry
& rFormatEntry
, const ScAddress
& rPos
, bool bFirst
= true);
204 virtual ~XclExpCfvo() {}
206 virtual void SaveXml( XclExpXmlStream
& rStrm
) override
;
208 const ScColorScaleEntry
& mrEntry
;
213 class XclExpColScaleCol
: public XclExpRecord
, protected XclExpRoot
216 explicit XclExpColScaleCol( const XclExpRoot
& rRoot
, const Color
& rColor
);
217 virtual ~XclExpColScaleCol();
219 virtual void SaveXml( XclExpXmlStream
& rStrm
) override
;
221 const Color
& mrColor
;
224 class ScConditionalFormat
;
226 /** Represents a CONDFMT record that contains all conditions of a conditional format.
227 @descr Contains the conditions which are stored in CF records. */
228 class XclExpCondfmt
: public XclExpRecord
, protected XclExpRoot
231 explicit XclExpCondfmt( const XclExpRoot
& rRoot
, const ScConditionalFormat
& rCondFormat
, XclExtLstRef xExtLst
, sal_Int32
& rIndex
);
232 virtual ~XclExpCondfmt();
234 /** Returns true, if this conditional format contains at least one cell range and CF record. */
235 bool IsValid() const;
237 /** Writes the CONDFMT record with following CF records, if there is valid data. */
238 virtual void Save( XclExpStream
& rStrm
) override
;
239 virtual void SaveXml( XclExpXmlStream
& rStrm
) override
;
242 /** Writes the body of the CONDFMT record. */
243 virtual void WriteBody( XclExpStream
& rStrm
) override
;
246 typedef XclExpRecordList
< XclExpRecord
> XclExpCFList
;
248 XclExpCFList maCFList
; /// List of CF records.
249 XclRangeList maXclRanges
; /// Cell ranges for this conditional format.
250 OUString msSeqRef
; /// OOXML Sequence of References
253 class XclExpColorScale
: public XclExpRecord
, protected XclExpRoot
256 explicit XclExpColorScale( const XclExpRoot
& rRoot
, const ScColorScaleFormat
& rFormat
, sal_Int32 nPriority
);
258 virtual void SaveXml( XclExpXmlStream
& rStrm
) override
;
260 typedef XclExpRecordList
< XclExpCfvo
> XclExpCfvoList
;
261 typedef XclExpRecordList
< XclExpColScaleCol
> XclExpColScaleColList
;
263 XclExpCfvoList maCfvoList
;
264 XclExpColScaleColList maColList
;
265 sal_Int32 mnPriority
;
268 class XclExpDataBar
: public XclExpRecord
, protected XclExpRoot
271 explicit XclExpDataBar( const XclExpRoot
& rRoot
, const ScDataBarFormat
& rFormat
, sal_Int32 nPriority
, const OString
& rGUID
);
273 virtual void SaveXml( XclExpXmlStream
& rStrm
) override
;
275 std::unique_ptr
<XclExpCfvo
> mpCfvoLowerLimit
;
276 std::unique_ptr
<XclExpCfvo
> mpCfvoUpperLimit
;
277 std::unique_ptr
<XclExpColScaleCol
> mpCol
;
279 const ScDataBarFormat
& mrFormat
;
280 sal_Int32 mnPriority
;
284 class XclExpIconSet
: public XclExpRecord
, protected XclExpRoot
287 explicit XclExpIconSet( const XclExpRoot
& rRoot
, const ScIconSetFormat
& rFormat
, sal_Int32 nPriority
);
289 virtual void SaveXml( XclExpXmlStream
& rStrm
) override
;
291 typedef XclExpRecordList
< XclExpCfvo
> XclExpCfvoList
;
293 XclExpCfvoList maCfvoList
;
294 const ScIconSetFormat
& mrFormat
;
295 sal_Int32 mnPriority
;
298 /** Contains all conditional formats of a specific sheet. */
299 class XclExpCondFormatBuffer
: public XclExpRecordBase
, protected XclExpRoot
302 /** Constructs CONDFMT and CF records containing the conditional formats of the current sheet. */
303 explicit XclExpCondFormatBuffer( const XclExpRoot
& rRoot
, XclExtLstRef xExtLst
);
305 /** Writes all contained CONDFMT records with their CF records. */
306 virtual void Save( XclExpStream
& rStrm
) override
;
307 virtual void SaveXml( XclExpXmlStream
& rStrm
) override
;
310 typedef XclExpRecordList
< XclExpCondfmt
> XclExpCondfmtList
;
311 XclExpCondfmtList maCondfmtList
; /// List of CONDFMT records.
314 // Data Validation ============================================================
316 /** Provides export of the data of a DV record.
317 @descr This record contains the settings for a data validation. In detail
318 this is a pointer to the core validation data and a cell range list with all
319 affected cells. The handle index is used to optimize list search algorithm. */
320 class XclExpDV
: public XclExpRecord
, protected XclExpRoot
323 explicit XclExpDV( const XclExpRoot
& rRoot
, sal_uLong nScHandle
);
326 /** Returns the core handle of the validation data. */
327 inline sal_uLong
GetScHandle() const { return mnScHandle
; }
329 /** Inserts a new cell range into the cell range list. */
330 void InsertCellRange( const ScRange
& rPos
);
331 /** Converts the Calc range list to the Excel range list.
332 @return false = Resulting range list empty - do not write this record. */
335 virtual void SaveXml( XclExpXmlStream
& rStrm
) override
;
338 /** Writes the body of the DV record. */
339 virtual void WriteBody( XclExpStream
& rStrm
) override
;
342 ScRangeList maScRanges
; /// Calc range list with all affected cells.
343 XclRangeList maXclRanges
; /// Excel range list with all affected cells.
344 XclExpString maPromptTitle
; /// The prompt title.
345 XclExpString maPromptText
; /// The prompt text.
346 XclExpString maErrorTitle
; /// The error title.
347 XclExpString maErrorText
; /// The error text.
348 XclExpStringRef mxString1
; /// String for first condition formula.
349 XclTokenArrayRef mxTokArr1
; /// Formula for first condition.
350 OUString msFormula1
; /// OOXML Formula for first condition.
351 XclTokenArrayRef mxTokArr2
; /// Formula for second condition.
352 OUString msFormula2
; /// OOXML Formula for second condition.
353 sal_uInt32 mnFlags
; /// Miscellaneous flags.
354 sal_uLong mnScHandle
; /// The core handle for quick list search.
357 /** This class contains the DV record list following the DVAL record. */
358 class XclExpDval
: public XclExpRecord
, protected XclExpRoot
361 explicit XclExpDval( const XclExpRoot
& rRoot
);
362 virtual ~XclExpDval();
364 /** Inserts the cell range into the range list of the DV record with the specified handle. */
365 void InsertCellRange( const ScRange
& rRange
, sal_uLong nScHandle
);
367 /** Writes the DVAL record and the DV record list. */
368 virtual void Save( XclExpStream
& rStrm
) override
;
369 virtual void SaveXml( XclExpXmlStream
& rStrm
) override
;
372 /** Searches for or creates a XclExpDV record object with the specified handle. */
373 XclExpDV
& SearchOrCreateDv( sal_uLong nScHandle
);
375 /** Writes the body of the DVAL record. */
376 virtual void WriteBody( XclExpStream
& rStrm
) override
;
379 typedef XclExpRecordList
< XclExpDV
> XclExpDVList
;
380 typedef XclExpDVList::RecordRefType XclExpDVRef
;
382 XclExpDVList maDVList
; /// List of DV records
383 XclExpDVRef mxLastFoundDV
; /// For search optimization.
386 // Web Queries ================================================================
388 /** Contains all records for a web query (linked tables in an HTML document).
389 @descr mode 1 (entire document): mpQryTables==0, mbEntireDoc==true;
390 mode 2 (all tables): mpQryTables==0, mbEntireDoc==false;
391 mode 3 (custom range list): mpQryTables!=0, mbEntireDoc==false. */
392 class XclExpWebQuery
: public XclExpRecordBase
395 /** Constructs a web query record container with settings from Calc. */
396 explicit XclExpWebQuery(
397 const OUString
& rRangeName
,
398 const OUString
& rUrl
,
399 const OUString
& rSource
,
400 sal_Int32 nRefrSecs
);
401 virtual ~XclExpWebQuery();
403 /** Writes all needed records for this web query. */
404 virtual void Save( XclExpStream
& rStrm
) override
;
407 XclExpString maDestRange
; /// Destination range.
408 XclExpString maUrl
; /// Source document URL.
409 XclExpStringRef mxQryTables
; /// List of source range names.
410 sal_Int16 mnRefresh
; /// Refresh time in minutes.
411 bool mbEntireDoc
; /// true = entire document.
414 /** Contains all web query records for this document. */
415 class XclExpWebQueryBuffer
: public XclExpRecordList
< XclExpWebQuery
>
418 explicit XclExpWebQueryBuffer( const XclExpRoot
& rRoot
);
423 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */