Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #ifndef SC_XETABLE_HXX
30 : : #define SC_XETABLE_HXX
31 : :
32 : : #include "xltable.hxx"
33 : :
34 : : #include <deque>
35 : : #include <tools/mempool.hxx>
36 : : #include "xladdress.hxx"
37 : : #include "xerecord.hxx"
38 : : #include "xestring.hxx"
39 : : #include "xeformula.hxx"
40 : : #include "xestyle.hxx"
41 : : #include "xeextlst.hxx"
42 : :
43 : : #include <boost/shared_ptr.hpp>
44 : : #include <map>
45 : :
46 : : /* ============================================================================
47 : : Export of cell tables including row and column description.
48 : : - Managing all used and formatted cells in a sheet.
49 : : - Row and column properties, i.e. width/height, visibility.
50 : : - Find default row formatting and default column formatting.
51 : : - Merged cell ranges.
52 : : ============================================================================ */
53 : :
54 : : // ============================================================================
55 : : // Helper records for cell records
56 : : // ============================================================================
57 : :
58 : : /** Represents a STRING record that contains the result of a string formula. */
59 [ # # ][ # # ]: 0 : class XclExpStringRec : public XclExpRecord
60 : : {
61 : : public:
62 : : explicit XclExpStringRec( const XclExpRoot& rRoot, const String& rResult );
63 : :
64 : : private:
65 : : virtual void WriteBody( XclExpStream& rStrm );
66 : :
67 : : private:
68 : : XclExpStringRef mxResult;
69 : : };
70 : :
71 : : // Additional records for special formula ranges ==============================
72 : :
73 : : /** Base record for additional range formula records (i.e. ARRAY, SHRFMLA). */
74 [ # # ]: 0 : class XclExpRangeFmlaBase : public XclExpRecord
75 : : {
76 : : public:
77 : : /** Returns true, if the passed cell position is equal to own base position. */
78 : : bool IsBasePos( sal_uInt16 nXclCol, sal_uInt32 nXclRow ) const;
79 : :
80 : : /** Derived classes create the token array for a corresponding FORMULA cell record. */
81 : : virtual XclTokenArrayRef CreateCellTokenArray( const XclExpRoot& rRoot ) const = 0;
82 : : /** Derived classes return true, if the own formula contains volatile functions. */
83 : : virtual bool IsVolatile() const = 0;
84 : :
85 : : protected:
86 : : /** Constructs the record with a single cell. */
87 : : explicit XclExpRangeFmlaBase(
88 : : sal_uInt16 nRecId, sal_uInt32 nRecSize, const ScAddress& rScPos );
89 : : /** Constructs the record with a cell range. */
90 : : explicit XclExpRangeFmlaBase(
91 : : sal_uInt16 nRecId, sal_uInt32 nRecSize, const ScRange& rScRange );
92 : :
93 : : /** Extends the cell range to include the passed cell address. */
94 : : void Extend( const ScAddress& rScPos );
95 : :
96 : : /** Writes the range address covered by this record. */
97 : : void WriteRangeAddress( XclExpStream& rStrm ) const;
98 : :
99 : : protected:
100 : : XclRange maXclRange; /// Range described by this record.
101 : : XclAddress maBaseXclPos; /// Address of base cell (first FORMULA record).
102 : : };
103 : :
104 : : typedef boost::shared_ptr< XclExpRangeFmlaBase > XclExpRangeFmlaRef;
105 : :
106 : : // Array formulas =============================================================
107 : :
108 : : class ScTokenArray;
109 : :
110 : : /** Represents an ARRAY record that contains the token array of a matrix formula.
111 : :
112 : : An ARRAY record is stored following the first FORMULA record that is part
113 : : of a matrix formula. All FORMULA records of a matrix formula contain a
114 : : reference to the ARRAY record, while the ARRAY record contains the formula
115 : : token array used by all formulas.
116 : : */
117 [ # # ][ # # ]: 0 : class XclExpArray : public XclExpRangeFmlaBase
118 : : {
119 : : public:
120 : : explicit XclExpArray( XclTokenArrayRef xTokArr, const ScRange& rScRange );
121 : :
122 : : /** Creates and returns the token array for a corresponding FORMULA cell record. */
123 : : virtual XclTokenArrayRef CreateCellTokenArray( const XclExpRoot& rRoot ) const;
124 : : /** Returns true, if the array formula contains volatile functions. */
125 : : virtual bool IsVolatile() const;
126 : :
127 : : private:
128 : : virtual void WriteBody( XclExpStream& rStrm );
129 : :
130 : : private:
131 : : XclTokenArrayRef mxTokArr; /// The token array of a matrix formula.
132 : : };
133 : :
134 : : typedef boost::shared_ptr< XclExpArray > XclExpArrayRef;
135 : :
136 : : // ----------------------------------------------------------------------------
137 : :
138 : : /** Caches all ARRAY records. */
139 [ # # ]: 0 : class XclExpArrayBuffer : protected XclExpRoot
140 : : {
141 : : public:
142 : : explicit XclExpArrayBuffer( const XclExpRoot& rRoot );
143 : :
144 : : /** Inserts a new ARRAY record into the buffer and returns it. */
145 : : XclExpArrayRef CreateArray( const ScTokenArray& rScTokArr, const ScRange& rScRange );
146 : : /** Tries to find an ARRAY record that corresponds to an ocMatRef token. */
147 : : XclExpArrayRef FindArray( const ScTokenArray& rScTokArr ) const;
148 : :
149 : : private:
150 : : typedef ::std::map< ScAddress, XclExpArrayRef > XclExpArrayMap;
151 : : XclExpArrayMap maRecMap; /// Map containing the ARRAY records.
152 : : };
153 : :
154 : : // Shared formulas ============================================================
155 : :
156 : : /** Represents a SHRFMLA record that contains the token array of a shared formula.
157 : :
158 : : A SHRFMLA record is stored following the first FORMULA record that is part
159 : : of a shared formula. All FORMULA records of a shared formula contain a
160 : : reference to the SHRFMLA record, while the SHRFMLA record contains the
161 : : formula token array used by all formulas.
162 : : */
163 [ # # ][ # # ]: 0 : class XclExpShrfmla : public XclExpRangeFmlaBase
164 : : {
165 : : public:
166 : : /** Creates a SHRFMLA record that consists of the passed cell address only. */
167 : : explicit XclExpShrfmla( XclTokenArrayRef xTokArr, const ScAddress& rScPos );
168 : :
169 : : /** Extends the cell range to include the passed cell address. */
170 : : void ExtendRange( const ScAddress& rScPos );
171 : :
172 : : /** Creates and returns the token array for a corresponding FORMULA cell record. */
173 : : virtual XclTokenArrayRef CreateCellTokenArray( const XclExpRoot& rRoot ) const;
174 : : /** Returns true, if the shared formula contains volatile functions. */
175 : : virtual bool IsVolatile() const;
176 : :
177 : : private:
178 : : virtual void WriteBody( XclExpStream& rStrm );
179 : :
180 : : private:
181 : : XclTokenArrayRef mxTokArr; /// The token array of a shared formula.
182 : : sal_uInt8 mnUsedCount; /// Number of FORMULA records referring to this record.
183 : : };
184 : :
185 : : typedef boost::shared_ptr< XclExpShrfmla > XclExpShrfmlaRef;
186 : :
187 : : // ----------------------------------------------------------------------------
188 : :
189 : : /** Caches all SHRFMLA records and provides functions to update their ranges. */
190 [ # # ]: 0 : class XclExpShrfmlaBuffer : protected XclExpRoot
191 : : {
192 : : public:
193 : : explicit XclExpShrfmlaBuffer( const XclExpRoot& rRoot );
194 : :
195 : : /** Tries to create a new or to update an existing SHRFMLA record.
196 : : @return An empty reference, if the passed token array does not contain
197 : : a shared formula. If the token array is a shared formula, this
198 : : function updates its cell range to include the passed cell position,
199 : : if there is a SHRFMLA record for the passed token array; otherwise
200 : : this function creates and returns a new SHRFMLA record. */
201 : : XclExpShrfmlaRef CreateOrExtendShrfmla(
202 : : const ScTokenArray& rScTokArr, const ScAddress& rScPos );
203 : :
204 : : private:
205 : : typedef ::std::map< const ScTokenArray*, XclExpShrfmlaRef > XclExpShrfmlaMap;
206 : : XclExpShrfmlaMap maRecMap; /// Map containing the SHRFMLA records.
207 : : };
208 : :
209 : : // Multiple operations ========================================================
210 : :
211 : : struct XclMultipleOpRefs;
212 : :
213 : : /** Represents a TABLEOP record for a multiple operations range. */
214 [ # # ]: 0 : class XclExpTableop : public XclExpRangeFmlaBase
215 : : {
216 : : public:
217 : : explicit XclExpTableop( const ScAddress& rScPos,
218 : : const XclMultipleOpRefs& rRefs, sal_uInt8 nScMode );
219 : :
220 : : /** Returns true, if the cell range has been extended to the passed position.
221 : : @descr All references passed in rRefs must fit the ranges passed in the constructor. */
222 : : bool TryExtend( const ScAddress& rScPos, const XclMultipleOpRefs& rRefs );
223 : :
224 : : /** Finalizes the record. Tests on valid cell range and reference addresses. */
225 : : void Finalize();
226 : :
227 : : /** Creates and returns the token array for a corresponding FORMULA cell record. */
228 : : virtual XclTokenArrayRef CreateCellTokenArray( const XclExpRoot& rRoot ) const;
229 : : /** Returns true, if the multiple operations range is volatile. */
230 : : virtual bool IsVolatile() const;
231 : : /** Writes the record if it is valid. */
232 : : virtual void Save( XclExpStream& rStrm );
233 : :
234 : : private:
235 : : /** Returns true, if the passed cell position can be appended to this record. */
236 : : bool IsAppendable( sal_uInt16 nXclCol, sal_uInt16 nXclRow ) const;
237 : :
238 : : /** Writes the contents of the TABLEOP record. */
239 : : virtual void WriteBody( XclExpStream& rStrm );
240 : :
241 : : private:
242 : : SCTAB mnScTab; /// Sheet index of this record.
243 : : sal_uInt16 mnLastAppXclCol;/// Column index of last appended cell.
244 : : sal_uInt16 mnColInpXclCol; /// Column index of column input cell.
245 : : sal_uInt32 mnColInpXclRow; /// Row index of column input cell.
246 : : sal_uInt16 mnRowInpXclCol; /// Column index of row input cell.
247 : : sal_uInt32 mnRowInpXclRow; /// Row index of row input cell.
248 : : sal_uInt8 mnScMode; /// Type of the multiple operation (Calc constant).
249 : : bool mbValid; /// true = Contains valid references.
250 : : };
251 : :
252 : : typedef boost::shared_ptr< XclExpTableop > XclExpTableopRef;
253 : :
254 : : // ----------------------------------------------------------------------------
255 : :
256 : : /** Contains all created TABLEOP records and supports creating or updating them. */
257 [ # # ][ # # ]: 0 : class XclExpTableopBuffer : protected XclExpRoot
258 : : {
259 : : public:
260 : : explicit XclExpTableopBuffer( const XclExpRoot& rRoot );
261 : :
262 : : /** Tries to update an existing or to create a new TABLEOP record.
263 : : @return Reference to the TABLEOP record for this cell (existing or new),
264 : : or an empty reference, if rScTokArr does not contain a multiple
265 : : operations formula. */
266 : : XclExpTableopRef CreateOrExtendTableop(
267 : : const ScTokenArray& rScTokArr, const ScAddress& rScPos );
268 : :
269 : : /** Finalizes all contained TABLEOP records. */
270 : : void Finalize();
271 : :
272 : : private:
273 : : /** Tries to create a new TABLEOP record, if rRefs contains valid references. */
274 : : XclExpTableopRef TryCreate( const ScAddress& rScPos, const XclMultipleOpRefs& rRefs );
275 : :
276 : : private:
277 : : typedef XclExpRecordList< XclExpTableop > XclExpTableopList;
278 : : XclExpTableopList maTableopList; /// List of all TABLEOP records.
279 : : };
280 : :
281 : : // ============================================================================
282 : : // Cell records
283 : : // ============================================================================
284 : :
285 : : /** The base class of all cell records. */
286 [ # # ]: 0 : class XclExpCellBase : public XclExpRecord
287 : : {
288 : : public:
289 : : /** Returns the (first) address of the cell(s). */
290 : 0 : inline const XclAddress& GetXclPos() const { return maXclPos; }
291 : : /** Returns the (first) Excel column index of the cell(s). */
292 : 0 : inline sal_uInt16 GetXclCol() const { return maXclPos.mnCol; }
293 : : /** Returns the Excel row index of the cell. */
294 : 0 : inline sal_uInt32 GetXclRow() const { return maXclPos.mnRow; }
295 : :
296 : : /** Derived classes return the column index of the last contained cell. */
297 : : virtual sal_uInt16 GetLastXclCol() const = 0;
298 : : /** Derived classes return the XF identifier of the first contained cell. */
299 : : virtual sal_uInt32 GetFirstXFId() const = 0;
300 : : /** Derived classes return true, if this record does not contain at least one valid cell. */
301 : : virtual bool IsEmpty() const = 0;
302 : : /** Derived classes return whether the cell contains multi-line text. */
303 : : virtual bool IsMultiLineText() const;
304 : :
305 : : /** Derived classes try to merge the contents of the passed cell to own data. */
306 : : virtual bool TryMerge( const XclExpCellBase& rCell );
307 : : /** Derived classes convert the XF identifier(s) into the Excel XF index(es).
308 : : @param rXFIndexes The converted XF index(es) are inserted here. */
309 : : virtual void ConvertXFIndexes( const XclExpRoot& rRoot ) = 0;
310 : : /** Derived classes for blank cells insert the Excel XF index(es) into the passed vector. */
311 : : virtual void GetBlankXFIndexes( ScfUInt16Vec& rXFIndexes ) const;
312 : : /** Derived classes for blank cells remove unused Excel XF index(es). */
313 : : virtual void RemoveUnusedBlankCells( const ScfUInt16Vec& rXFIndexes );
314 : :
315 : : protected:
316 : : explicit XclExpCellBase(
317 : : sal_uInt16 nRecId, sal_Size nContSize, const XclAddress& rXclPos );
318 : :
319 : : /** Sets this record to a new column position. */
320 : 0 : inline void SetXclCol( sal_uInt16 nXclCol ) { maXclPos.mnCol = nXclCol; }
321 : : /** Sets this record to a new row position. */
322 : : inline void SetXclRow( sal_uInt32 nXclRow ) { maXclPos.mnRow = nXclRow; }
323 : :
324 : : private:
325 : : XclAddress maXclPos; /// Address of the cell.
326 : : };
327 : :
328 : : typedef boost::shared_ptr< XclExpCellBase > XclExpCellRef;
329 : :
330 : : // Single cell records ========================================================
331 : :
332 : : /** Base class for all cell records not supporting multiple contents. */
333 [ # # ]: 0 : class XclExpSingleCellBase : public XclExpCellBase
334 : : {
335 : : public:
336 : : /** Returns the last column, which is equal to the first column for single cells. */
337 : : virtual sal_uInt16 GetLastXclCol() const;
338 : : /** Return the XF identifier of the cell. */
339 : : virtual sal_uInt32 GetFirstXFId() const;
340 : : /** Returns true, if this record does not contain at least one valid cell. */
341 : : virtual bool IsEmpty() const;
342 : : /** Converts the XF identifier into the Excel XF index. */
343 : : virtual void ConvertXFIndexes( const XclExpRoot& rRoot );
344 : : /** Writes cell address, XF index, and calls WriteContents() for each cell. */
345 : : virtual void Save( XclExpStream& rStrm );
346 : :
347 : : protected:
348 : : explicit XclExpSingleCellBase( sal_uInt16 nRecId, sal_Size nContSize,
349 : : const XclAddress& rXclPos, sal_uInt32 nXFId );
350 : :
351 : : explicit XclExpSingleCellBase( const XclExpRoot& rRoot,
352 : : sal_uInt16 nRecId, sal_Size nContSize, const XclAddress& rXclPos,
353 : : const ScPatternAttr* pPattern, sal_Int16 nScript, sal_uInt32 nForcedXFId );
354 : :
355 : 0 : inline void SetContSize( sal_Size nContSize ) { mnContSize = nContSize; }
356 : 0 : inline sal_Size GetContSize() const { return mnContSize; }
357 : :
358 : 0 : inline void SetXFId( sal_uInt32 nXFId ) { maXFId.mnXFId = nXFId; }
359 : 0 : inline sal_uInt32 GetXFId() const { return maXFId.mnXFId; }
360 : :
361 : : private:
362 : : /** Writes cell address, XF index, and calls WriteContents() for each cell. */
363 : : virtual void WriteBody( XclExpStream& rStrm );
364 : : /** Derived classes write the contents of the specified cell (without XF index). */
365 : : virtual void WriteContents( XclExpStream& rStrm ) = 0;
366 : :
367 : : private:
368 : : XclExpXFId maXFId; /// The XF identifier of the cell formatting.
369 : : sal_Size mnContSize; /// The size of the cell contents.
370 : : };
371 : :
372 : : // ----------------------------------------------------------------------------
373 : :
374 : : /** Represents a NUMBER record that describes a cell with a double value. */
375 [ # # ]: 0 : class XclExpNumberCell : public XclExpSingleCellBase
376 : : {
377 [ # # ][ # # ]: 0 : DECL_FIXEDMEMPOOL_NEWDEL( XclExpNumberCell )
378 : :
379 : : public:
380 : : explicit XclExpNumberCell( const XclExpRoot& rRoot, const XclAddress& rXclPos,
381 : : const ScPatternAttr* pPattern, sal_uInt32 nForcedXFId,
382 : : double fValue );
383 : :
384 : : virtual void SaveXml( XclExpXmlStream& rStrm );
385 : : private:
386 : : virtual void WriteContents( XclExpStream& rStrm );
387 : :
388 : : private:
389 : : double mfValue; /// The cell value.
390 : : };
391 : :
392 : : // ----------------------------------------------------------------------------
393 : :
394 : : /** Represents a BOOLERR record that describes a cell with a Boolean value. */
395 [ # # ]: 0 : class XclExpBooleanCell : public XclExpSingleCellBase
396 : : {
397 [ # # ][ # # ]: 0 : DECL_FIXEDMEMPOOL_NEWDEL( XclExpBooleanCell )
398 : :
399 : : public:
400 : : explicit XclExpBooleanCell( const XclExpRoot rRoot, const XclAddress& rXclPos,
401 : : const ScPatternAttr* pPattern, sal_uInt32 nForcedXFId,
402 : : bool bValue );
403 : :
404 : : virtual void SaveXml( XclExpXmlStream& rStrm );
405 : : private:
406 : : virtual void WriteContents( XclExpStream& rStrm );
407 : :
408 : : private:
409 : : bool mbValue; /// The cell value.
410 : : };
411 : :
412 : : class ScStringCell;
413 : : class ScEditCell;
414 : : class XclExpHyperlinkHelper;
415 : :
416 : : /** Represents a text cell record.
417 : :
418 : : May contain a BIFF2-BIFF7 LABEL record for a simple string, or a BIFF2-BIFF7
419 : : RSTRING record for a formatted string, or a BIFF8 LABELSST string for any
420 : : string (simply stores a reference to the Shared String Table).
421 : : */
422 [ # # ][ # # ]: 0 : class XclExpLabelCell : public XclExpSingleCellBase
423 : : {
424 [ # # ][ # # ]: 0 : DECL_FIXEDMEMPOOL_NEWDEL( XclExpLabelCell )
425 : :
426 : : public:
427 : : /** Constructs the record from an unformatted Calc string cell. */
428 : : explicit XclExpLabelCell( const XclExpRoot& rRoot, const XclAddress& rXclPos,
429 : : const ScPatternAttr* pPattern, sal_uInt32 nForcedXFId,
430 : : const ScStringCell& rCell );
431 : :
432 : : /** Constructs the record from a formatted Calc edit cell. */
433 : : explicit XclExpLabelCell( const XclExpRoot& rRoot, const XclAddress& rXclPos,
434 : : const ScPatternAttr* pPattern, sal_uInt32 nForcedXFId,
435 : : const ScEditCell& rCell, XclExpHyperlinkHelper& rHlinkHelper );
436 : :
437 : : /** Returns true if the cell contains multi-line text. */
438 : : virtual bool IsMultiLineText() const;
439 : :
440 : : virtual void SaveXml( XclExpXmlStream& rStrm );
441 : : private:
442 : : /** Initializes the record contents. Called from constructors. */
443 : : void Init( const XclExpRoot& rRoot,
444 : : const ScPatternAttr* pPattern, XclExpStringRef xText );
445 : :
446 : : virtual void WriteContents( XclExpStream& rStrm );
447 : :
448 : : private:
449 : : XclExpStringRef mxText; /// The cell text.
450 : : sal_uInt32 mnSstIndex; /// Index into Shared String Table (only used for BIFF8).
451 : : bool mbLineBreak; /// True = cell has automatic linebreaks enabled.
452 : : };
453 : :
454 : : // ----------------------------------------------------------------------------
455 : :
456 : : class ScFormulaCell;
457 : :
458 : : /** Represents a FORMULA record that describes a cell with a formula. */
459 [ # # ][ # # ]: 0 : class XclExpFormulaCell : public XclExpSingleCellBase
[ # # ][ # # ]
460 : : {
461 [ # # ][ # # ]: 0 : DECL_FIXEDMEMPOOL_NEWDEL( XclExpFormulaCell )
462 : :
463 : : public:
464 : : explicit XclExpFormulaCell( const XclExpRoot& rRoot, const XclAddress& rXclPos,
465 : : const ScPatternAttr* pPattern, sal_uInt32 nForcedXFId,
466 : : const ScFormulaCell& rScFmlaCell,
467 : : XclExpArrayBuffer& rArrayBfr,
468 : : XclExpShrfmlaBuffer& rShrfmlaBfr,
469 : : XclExpTableopBuffer& rTableopBfr );
470 : :
471 : : /** Writes the FORMULA record and additional records related to the formula. */
472 : : virtual void Save( XclExpStream& rStrm );
473 : : virtual void SaveXml( XclExpXmlStream& rStrm );
474 : :
475 : : private:
476 : : virtual void WriteContents( XclExpStream& rStrm );
477 : :
478 : : private:
479 : : ScFormulaCell& mrScFmlaCell; /// The Calc formula cell.
480 : : XclTokenArrayRef mxTokArr; /// The token array of the formula.
481 : : XclExpRangeFmlaRef mxAddRec; /// Additional record for matrix/shared formulas.
482 : : XclExpRecordRef mxStringRec; /// STRING record for string result.
483 : : };
484 : :
485 : : // Multiple cell records ======================================================
486 : :
487 : : struct XclExpMultiXFId : public XclExpXFId
488 : : {
489 : : sal_uInt16 mnCount; /// Number of XF identifiers.
490 : :
491 : 0 : inline explicit XclExpMultiXFId( sal_uInt32 nXFId, sal_uInt16 nCount = 1 ) :
492 : 0 : XclExpXFId( nXFId ), mnCount( nCount ) {}
493 : : };
494 : :
495 : : // ----------------------------------------------------------------------------
496 : :
497 : : /** Base class for all cell records supporting multiple contents. */
498 [ # # ]: 0 : class XclExpMultiCellBase : public XclExpCellBase
499 : : {
500 : : public:
501 : : /** Returns the column index of the last cell this record describes. */
502 : : virtual sal_uInt16 GetLastXclCol() const;
503 : : /** Return the XF identifier of the first contained cell. */
504 : : virtual sal_uInt32 GetFirstXFId() const;
505 : : /** Returns true, if this record does not contain at least one valid cell. */
506 : : virtual bool IsEmpty() const;
507 : :
508 : : /** Convert all XF identifiers into the Excel XF indexes. */
509 : : virtual void ConvertXFIndexes( const XclExpRoot& rRoot );
510 : : /** Writes the record, calls WriteContents() for each contained cell.
511 : : @descr May write several records, if unused XF indexes are contained. */
512 : : virtual void Save( XclExpStream& rStrm );
513 : : virtual void SaveXml( XclExpXmlStream& rStrm );
514 : :
515 : : protected:
516 : : explicit XclExpMultiCellBase( sal_uInt16 nRecId, sal_uInt16 nMulRecId,
517 : : sal_Size nContSize, const XclAddress& rXclPos );
518 : :
519 : : /** Sets the size of the remaining contents of one cell (without the XF index). */
520 : : inline void SetContSize( sal_Size nContSize ) { mnContSize = nContSize; }
521 : : /** Returns the size of the remaining contents of one cell (without the XF index). */
522 : : inline sal_Size GetContSize() const { return mnContSize; }
523 : :
524 : : /** Returns the number of cells this record represents. */
525 : : sal_uInt16 GetCellCount() const;
526 : :
527 : : /** Appends the passed XF identifier nCount times to the list of XF identifiers. */
528 : : void AppendXFId( const XclExpMultiXFId& rXFId );
529 : : /** Appends the passed cell format nCount times to the list of XF identifiers. */
530 : : void AppendXFId( const XclExpRoot& rRoot,
531 : : const ScPatternAttr* pPattern, sal_uInt16 nScript,
532 : : sal_uInt32 nForcedXFId, sal_uInt16 nCount = 1 );
533 : :
534 : : /** Tries to merge the XF ID list of the passed cell with the own list. */
535 : : bool TryMergeXFIds( const XclExpMultiCellBase& rCell );
536 : : /** Inserts the Excel XF index(es) into the passed vector. */
537 : : void GetXFIndexes( ScfUInt16Vec& rXFIndexes ) const;
538 : :
539 : : /** Removes unused Excel XF index(es).
540 : : @param rXFIndexes Specifies which XF indexes are used. */
541 : : void RemoveUnusedXFIndexes( const ScfUInt16Vec& rXFIndexes );
542 : :
543 : : private:
544 : : /** Derived classes write the remaining contents of the specified cell (without XF index).
545 : : @param nRelCol Relative column index (starts with 0 for first cell of this record). */
546 : : virtual void WriteContents( XclExpStream& rStrm, sal_uInt16 nRelCol ) = 0;
547 : : virtual void WriteXmlContents( XclExpXmlStream& rStrm, const XclAddress& rAddress, sal_uInt32 nXFId, sal_uInt16 nRelCol ) = 0;
548 : :
549 : : private:
550 : : typedef ::std::deque< XclExpMultiXFId > XclExpMultiXFIdDeq;
551 : :
552 : : sal_uInt16 mnMulRecId; /// Record ID for multiple record variant.
553 : : sal_Size mnContSize; /// Data size of contents for one cell
554 : : XclExpMultiXFIdDeq maXFIds; /// The XF identifiers of the cell formatting.
555 : : };
556 : :
557 : : // ----------------------------------------------------------------------------
558 : :
559 : : /** Represents a BLANK or MULBLANK record that describes empty but formatted cells. */
560 [ # # ]: 0 : class XclExpBlankCell : public XclExpMultiCellBase
561 : : {
562 [ # # ][ # # ]: 0 : DECL_FIXEDMEMPOOL_NEWDEL( XclExpBlankCell )
563 : :
564 : : public:
565 : : explicit XclExpBlankCell( const XclAddress& rXclPos, const XclExpMultiXFId& rXFId );
566 : :
567 : : explicit XclExpBlankCell( const XclExpRoot& rRoot,
568 : : const XclAddress& rXclPos, sal_uInt16 nLastXclCol,
569 : : const ScPatternAttr* pPattern, sal_uInt32 nForcedXFId );
570 : :
571 : : /** Tries to merge the contents of the passed cell to own data. */
572 : : virtual bool TryMerge( const XclExpCellBase& rCell );
573 : : /** Inserts the Excel XF index(es) into the passed vector. */
574 : : virtual void GetBlankXFIndexes( ScfUInt16Vec& rXFIndexes ) const;
575 : : /** Tries to remove unused Excel XF index(es). */
576 : : virtual void RemoveUnusedBlankCells( const ScfUInt16Vec& rXFIndexes );
577 : :
578 : : private:
579 : : /** Writes the remaining contents of the specified cell (without XF index). */
580 : : virtual void WriteContents( XclExpStream& rStrm, sal_uInt16 nRelCol );
581 : : virtual void WriteXmlContents( XclExpXmlStream& rStrm, const XclAddress& rAddress, sal_uInt32 nXFId, sal_uInt16 nRelCol );
582 : : };
583 : :
584 : : // ----------------------------------------------------------------------------
585 : :
586 : : /** Represents an RK or MULRK record that describes cells with a compressed double values. */
587 [ # # ]: 0 : class XclExpRkCell : public XclExpMultiCellBase
588 : : {
589 [ # # ][ # # ]: 0 : DECL_FIXEDMEMPOOL_NEWDEL( XclExpRkCell )
590 : :
591 : : public:
592 : : explicit XclExpRkCell( const XclExpRoot& rRoot, const XclAddress& rXclPos,
593 : : const ScPatternAttr* pPattern, sal_uInt32 nForcedXFId,
594 : : sal_Int32 nRkValue );
595 : :
596 : : /** Tries to merge the contents of the passed cell to own data. */
597 : : virtual bool TryMerge( const XclExpCellBase& rCell );
598 : :
599 : : private:
600 : : /** Writes the remaining contents of the specified cell (without XF index). */
601 : : virtual void WriteContents( XclExpStream& rStrm, sal_uInt16 nRelCol );
602 : : virtual void WriteXmlContents( XclExpXmlStream& rStrm, const XclAddress& rAddress, sal_uInt32 nXFId, sal_uInt16 nRelCol );
603 : :
604 : : private:
605 : : ScfInt32Vec maRkValues; /// The cell values.
606 : : };
607 : :
608 : : // ============================================================================
609 : : // Rows and Columns
610 : : // ============================================================================
611 : :
612 : : class ScOutlineArray;
613 : :
614 : : /** Base class for buffers containing row or column outline data. */
615 : 0 : class XclExpOutlineBuffer
616 : : {
617 : : public:
618 : : /** Returns true, if a collapsed group ends at the last processed position. */
619 : 0 : inline bool IsCollapsed() const { return mbCurrCollapse; }
620 : : /** Returns the highest level of an open group at the last processed position. */
621 : 0 : inline sal_uInt8 GetLevel() const { return ::std::min( mnCurrLevel, EXC_OUTLINE_MAX ); }
622 : :
623 : : protected:
624 : : /** Constructs the outline buffer.
625 : : @param bRows true = Process row ouline array; false = Process column outline array. */
626 : : explicit XclExpOutlineBuffer( const XclExpRoot& rRoot, bool bRows );
627 : :
628 : : /** Updates the current state by processing the settings at the passed Calc position. */
629 : : void UpdateColRow( SCCOLROW nScPos );
630 : :
631 : : private:
632 : : /** Data about an outline level. */
633 : : struct XclExpLevelInfo
634 : : {
635 : : SCCOLROW mnScEndPos; /// The end position of a group in a level.
636 : : bool mbHidden; /// true = Group in this level is hidden.
637 : 0 : inline explicit XclExpLevelInfo() : mnScEndPos( 0 ), mbHidden( false ) {}
638 : : };
639 : : typedef ::std::vector< XclExpLevelInfo > XclExpLevelInfoVec;
640 : :
641 : : const ScOutlineArray* mpScOLArray; /// Pointer to Calc outline array.
642 : : XclExpLevelInfoVec maLevelInfos; /// Info for current row and all levels.
643 : : sal_uInt8 mnCurrLevel; /// Highest level of an open group for current position.
644 : : bool mbCurrCollapse; /// true = Collapsed group ends at current position.
645 : : };
646 : :
647 : : // ----------------------------------------------------------------------------
648 : :
649 : : /** The outline buffer for column outlines. */
650 : 0 : class XclExpColOutlineBuffer : public XclExpOutlineBuffer
651 : : {
652 : : public:
653 : 0 : inline explicit XclExpColOutlineBuffer( const XclExpRoot& rRoot ) :
654 : 0 : XclExpOutlineBuffer( rRoot, false ) {}
655 : :
656 : : /** Updates the current state by processing the settings of the passed Calc column. */
657 : 0 : inline void Update( SCCOL nScCol )
658 : 0 : { UpdateColRow( static_cast< SCCOLROW >( nScCol ) ); }
659 : : };
660 : :
661 : : // ----------------------------------------------------------------------------
662 : :
663 : : /** The outline buffer for row outlines. */
664 : 0 : class XclExpRowOutlineBuffer : public XclExpOutlineBuffer
665 : : {
666 : : public:
667 : 0 : inline explicit XclExpRowOutlineBuffer( const XclExpRoot& rRoot ) :
668 : 0 : XclExpOutlineBuffer( rRoot, true ) {}
669 : :
670 : : /** Updates the current state by processing the settings of the passed Calc row. */
671 : 0 : inline void Update( SCROW nScRow )
672 : 0 : { UpdateColRow( static_cast< SCCOLROW >( nScRow ) ); }
673 : : };
674 : :
675 : : // ----------------------------------------------------------------------------
676 : :
677 : : /** Represents a GUTS record containing the level count of row and column outlines. */
678 [ # # ]: 0 : class XclExpGuts : public XclExpRecord
679 : : {
680 : : public:
681 : : explicit XclExpGuts( const XclExpRoot& rRoot );
682 : :
683 : : private:
684 : : virtual void WriteBody( XclExpStream& rStrm );
685 : :
686 : : private:
687 : : sal_uInt16 mnColLevels; /// Number of visible column outline levels.
688 : : sal_uInt16 mnColWidth; /// Width of column outline area (pixels).
689 : : sal_uInt16 mnRowLevels; /// Number of visible row outline levels.
690 : : sal_uInt16 mnRowWidth; /// Width of row outline area (pixels).
691 : : };
692 : :
693 : : // ----------------------------------------------------------------------------
694 : :
695 : : /** Represents a DIMENSIONS record containing the used area of a sheet. */
696 [ # # ]: 0 : class XclExpDimensions : public XclExpRecord
697 : : {
698 : : public:
699 : : explicit XclExpDimensions( const XclExpRoot& rRoot );
700 : :
701 : : /** Sets the used area to the record. */
702 : : void SetDimensions(
703 : : sal_uInt16 nFirstUsedXclCol, sal_uInt32 nFirstUsedXclRow,
704 : : sal_uInt16 nFirstFreeXclCol, sal_uInt32 nFirstFreeXclRow );
705 : :
706 : : virtual void SaveXml( XclExpXmlStream& rStrm );
707 : : private:
708 : : /** Writes the contents of the DIMENSIONS record. */
709 : : virtual void WriteBody( XclExpStream& rStrm );
710 : :
711 : : private:
712 : : sal_uInt32 mnFirstUsedXclRow; /// First used row.
713 : : sal_uInt32 mnFirstFreeXclRow; /// First unused row after used area.
714 : : sal_uInt16 mnFirstUsedXclCol; /// First used column.
715 : : sal_uInt16 mnFirstFreeXclCol; /// First free column after used area.
716 : : };
717 : :
718 : : // ============================================================================
719 : :
720 : : /** Represents the DEFCOLWIDTH record containing the default column width of a sheet.
721 : :
722 : : Excel stores the default column width in entire character widths of the '0'
723 : : character using the application default font (i.e. the default width is 10,
724 : : if the '0' character fits 10 times into a cell in a column with default
725 : : width.
726 : :
727 : : The IsDefWidth() function returns true, if the passed width (measured in
728 : : 1/256 of the width of the '0' character) could be converted exactly to the
729 : : default width. If the passed width is rounded up or down to get the default
730 : : width, the function returns false.
731 : : */
732 [ # # ][ # # ]: 0 : class XclExpDefcolwidth : public XclExpUInt16Record, protected XclExpRoot
733 : : {
734 : : public:
735 : : explicit XclExpDefcolwidth( const XclExpRoot& rRoot );
736 : :
737 : : /** Returns true, if the own default width exactly matches the passed width. */
738 : : bool IsDefWidth( sal_uInt16 nXclColWidth ) const;
739 : :
740 : : /** Sets the passed column width (in 1/256 character width) as default width. */
741 : : void SetDefWidth( sal_uInt16 nXclColWidth );
742 : : };
743 : :
744 : : // ----------------------------------------------------------------------------
745 : :
746 : : /** Contains the column settings for a range of columns.
747 : :
748 : : After construction the record contains a temporary XF identifier returned
749 : : from the XF buffer. After creating the entire Excel document in memory, the
750 : : ConvertXFIndexes() function converts it into the real Excel XF index.
751 : : */
752 [ # # ][ # # ]: 0 : class XclExpColinfo : public XclExpRecord, protected XclExpRoot
753 : : {
754 : : public:
755 : : /** Constructs the record with the settings in the Calc document. */
756 : : explicit XclExpColinfo( const XclExpRoot& rRoot,
757 : : SCCOL nScCol, SCROW nLastScRow,
758 : : XclExpColOutlineBuffer& rOutlineBfr );
759 : :
760 : : /** Converts the XF identifier into the Excel XF index, returns the latter. */
761 : : sal_uInt16 ConvertXFIndexes();
762 : :
763 : : /** Tries to merge this record with the passed record.
764 : : @descr Possible, if passed record directly follows this record and has equal contents.
765 : : @return true = This record is equal to passed record and has been updated. */
766 : : bool TryMerge( const XclExpColinfo& rColInfo );
767 : :
768 : : /** Returns the Excel width of the column(s). */
769 : 0 : inline sal_uInt16 GetColWidth() const { return mnWidth; }
770 : : /** Returns the final Excel XF index of the column(s). */
771 : 0 : inline sal_uInt16 GetXFIndex() const { return maXFId.mnXFIndex; }
772 : : /** Returns the number of columns represented by this record. */
773 : 0 : inline sal_uInt16 GetColCount() const { return mnLastXclCol - mnFirstXclCol + 1; }
774 : :
775 : : /** Returns true, if the column has default format and width. */
776 : : bool IsDefault( const XclExpDefcolwidth& rDefColWidth ) const;
777 : :
778 : : virtual void SaveXml( XclExpXmlStream& rStrm );
779 : :
780 : : private:
781 : : /** Writes the contents of this COLINFO record. */
782 : : virtual void WriteBody( XclExpStream& rStrm );
783 : :
784 : : private:
785 : : XclExpXFId maXFId; /// The XF identifier for column default format.
786 : : sal_uInt16 mnWidth; /// Excel width of the column.
787 : : sal_uInt16 mnFlags; /// Additional column flags.
788 : : sal_uInt16 mnFirstXclCol; /// Index to first column.
789 : : sal_uInt16 mnLastXclCol; /// Index to last column.
790 : : };
791 : :
792 : : // ----------------------------------------------------------------------------
793 : :
794 : : /** Contains COLINFO records for all columns of a Calc sheet.
795 : :
796 : : On construction one COLINFO record per column is created. After creating
797 : : the entire Excel document in memory, the ConvertXFIndexes() function converts
798 : : all temporary XF identifiers into real Excel XF indexes and merges all equal
799 : : COLINFO records together.
800 : : */
801 [ # # ][ # # ]: 0 : class XclExpColinfoBuffer : public XclExpRecordBase, protected XclExpRoot
[ # # ][ # # ]
802 : : {
803 : : public:
804 : : explicit XclExpColinfoBuffer( const XclExpRoot& rRoot );
805 : :
806 : : /** Initializes the buffer: finds settings and formatting of all columns.
807 : : @param nLastScRow Last row used to find default formatting. */
808 : : void Initialize( SCROW nLastScRow );
809 : : /** Converts the XF identifiers into the Excel XF indexes and merges equal columns.
810 : : @param rXFIndexes Returns the final XF indexes of all columns. */
811 : : void Finalize( ScfUInt16Vec& rXFIndexes );
812 : :
813 : : /** Writes all COLINFO records of this buffer. */
814 : : virtual void Save( XclExpStream& rStrm );
815 : : virtual void SaveXml( XclExpXmlStream& rStrm );
816 : :
817 : : private:
818 : : typedef XclExpRecordList< XclExpColinfo > XclExpColinfoList;
819 : : typedef XclExpColinfoList::RecordRefType XclExpColinfoRef;
820 : :
821 : : XclExpColinfoList maColInfos; /// List of COLINFO records.
822 : : XclExpDefcolwidth maDefcolwidth; /// The DEFCOLWIDTH record.
823 : : XclExpColOutlineBuffer maOutlineBfr; /// Buffer for column outline groups.
824 : : };
825 : :
826 : : // ============================================================================
827 : :
828 : : class XclExpRow;
829 : :
830 : : /** Contains all possible default row settings. */
831 : : struct XclExpDefaultRowData
832 : : {
833 : : sal_uInt16 mnFlags; /// Default flags for unspecified rows.
834 : : sal_uInt16 mnHeight; /// Default height for unspecified rows.
835 : :
836 : : explicit XclExpDefaultRowData();
837 : : explicit XclExpDefaultRowData( const XclExpRow& rRow );
838 : :
839 : : /** Returns true, if rows are hidden by default. */
840 : 0 : inline bool IsHidden() const { return ::get_flag( mnFlags, EXC_DEFROW_HIDDEN ); }
841 : : /** Returns true, if the rows have a manually set height by default. */
842 : 0 : inline bool IsUnsynced() const { return ::get_flag( mnFlags, EXC_DEFROW_UNSYNCED ); }
843 : : };
844 : :
845 : : // ----------------------------------------------------------------------------
846 : :
847 : : /** Represents a DEFROWHEIGHT record containing default format for unused rows. */
848 [ # # ]: 0 : class XclExpDefrowheight : public XclExpRecord
849 : : {
850 : : public:
851 : : explicit XclExpDefrowheight();
852 : :
853 : : /** Sets the passed default data as current record contents. */
854 : : void SetDefaultData( const XclExpDefaultRowData& rDefData );
855 : :
856 : : private:
857 : : /** Writes the contents of the record. */
858 : : virtual void WriteBody( XclExpStream& rStrm );
859 : :
860 : : private:
861 : : XclExpDefaultRowData maDefData; /// Record data.
862 : : };
863 : :
864 : : // ----------------------------------------------------------------------------
865 : :
866 : : /** Represents a ROW record and additionally contains all cells records of a row.
867 : :
868 : : This class contains all cell records of a row in a spreadsheet. There are 2
869 : : cell records in Excel that support storing a range of cells in one record
870 : : (MULBLANK for multiple blank cells, and MULRK for multiple RK values). The
871 : : insertion functions try to merge a new inserted cell with existing
872 : : neighbors, if this is supported by the current type of cell record.
873 : :
874 : : The Finalize() function converts the XF identifiers of all cell records to
875 : : the final Excel XF indexes. Then a default
876 : : */
877 [ # # ][ # # ]: 0 : class XclExpRow : public XclExpRecord, protected XclExpRoot
[ # # ]
878 : : {
879 : : public:
880 : : /** Constructs the ROW record and converts the Calc row settings.
881 : : @param bAlwaysEmpty true = This row will not be filled with blank cells
882 : : in the Finalize() function. */
883 : : explicit XclExpRow( const XclExpRoot& rRoot, sal_uInt32 nXclRow,
884 : : XclExpRowOutlineBuffer& rOutlineBfr, bool bAlwaysEmpty );
885 : :
886 : : /** Returns the excel row index of this ROW record. */
887 : 0 : inline sal_uInt32 GetXclRow() const { return mnXclRow; }
888 : : /** Returns the height of the row in twips. */
889 : 0 : inline sal_uInt16 GetHeight() const { return mnHeight; }
890 : : /** Returns true, if this row does not contain at least one valid cell. */
891 : 0 : inline bool IsEmpty() const { return maCellList.IsEmpty(); }
892 : : /** Returns true, if this row is hidden. */
893 : 0 : inline bool IsHidden() const { return ::get_flag( mnFlags, EXC_ROW_HIDDEN ); }
894 : : /** Returns true, if this row contains a manually set height. */
895 : 0 : inline bool IsUnsynced() const { return ::get_flag( mnFlags, EXC_ROW_UNSYNCED ); }
896 : : /** Returns true, if this row is enabled (will be exported). */
897 : 0 : inline bool IsEnabled() const { return mbEnabled; }
898 : :
899 : : /** Appends the passed cell object to this row. */
900 : : void AppendCell( XclExpCellRef xCell, bool bIsMergedBase );
901 : :
902 : : /** Converts all XF identifiers into the Excel XF indexes. */
903 : : void Finalize( const ScfUInt16Vec& rColXFIndexes );
904 : :
905 : : /** Returns the column index of the first used cell in this row.
906 : : @descr This function can only be called after Finalize(). */
907 : : sal_uInt16 GetFirstUsedXclCol() const;
908 : : /** Returns the column index of the first unused cell following all used cells in this row.
909 : : @descr This function can only be called after Finalize(). */
910 : : sal_uInt16 GetFirstFreeXclCol() const;
911 : :
912 : : /** Returns true, if this row may be omitted by using the DEFROWHEIGHT record.
913 : : @descr A row may be omitted, if it does not contain any cell or
914 : : explicit default cell formatting, and is not part of an outline.
915 : : This function can only be called after Finalize(). */
916 : : bool IsDefaultable() const;
917 : : /** Disables this row, if it is defaultable and has the passed default format.
918 : : @descr Disabled rows will not be saved.
919 : : This function can only be called after Finalize(). */
920 : : void DisableIfDefault( const XclExpDefaultRowData& rDefRowData );
921 : :
922 : : /** Writes all cell records of this row. */
923 : : void WriteCellList( XclExpStream& rStrm );
924 : :
925 : : /** Writes the ROW record if the row is not disabled (see DisableIfDefault() function). */
926 : : virtual void Save( XclExpStream& rStrm );
927 : : virtual void SaveXml( XclExpXmlStream& rStrm );
928 : :
929 : : private:
930 : : /** Initializes the record data. Called from constructors. */
931 : : void Init( sal_uInt16 nXclRow, XclExpRowOutlineBuffer* pOutlineBfr );
932 : : /** Inserts a cell at the specified list position, tries to merge with neighbors. */
933 : : void InsertCell( XclExpCellRef xCell, size_t nPos, bool bIsMergedBase );
934 : :
935 : : /** Writes the contents of the ROW record. */
936 : : virtual void WriteBody( XclExpStream& rStrm );
937 : :
938 : : private:
939 : : typedef XclExpRecordList< XclExpCellBase > XclExpCellList;
940 : :
941 : : XclExpCellList maCellList; /// List of cell records for this row.
942 : : sal_uInt32 mnXclRow; /// Excel row index of this row.
943 : : sal_uInt16 mnHeight; /// Row height in twips.
944 : : sal_uInt16 mnFlags; /// Flags for the ROW record.
945 : : sal_uInt16 mnXFIndex; /// Default row formatting.
946 : : sal_uInt16 mnOutlineLevel; /// Outline Level (for OOXML)
947 : : bool mbAlwaysEmpty; /// true = Do not add blank cells in Finalize().
948 : : bool mbEnabled; /// true = Write this ROW record.
949 : : };
950 : :
951 : : // ----------------------------------------------------------------------------
952 : :
953 : : /** Collects all rows which contain all cells of a sheet.
954 : :
955 : : This row buffer automatically creates ROW records when cells are inserted
956 : : with the AppendCell() function. It is possible to force creation of more
957 : : ROW records with the CreateRows() function. In both cases, all preceding
958 : : missing ROW records are inserted too.
959 : : */
960 [ # # ][ # # ]: 0 : class XclExpRowBuffer : public XclExpRecordBase, protected XclExpRoot
[ # # ]
961 : : {
962 : : public:
963 : : explicit XclExpRowBuffer( const XclExpRoot& rRoot );
964 : :
965 : : /** Appends the passed cell object to the row that the cell specifies. */
966 : : void AppendCell( XclExpCellRef xCell, bool bIsMergedBase );
967 : : /** Forces insertion of all ROW records before the passed row. */
968 : : void CreateRows( SCROW nFirstFreeScRow );
969 : :
970 : : /** Converts all XF identifiers into the Excel XF indexes and calculates default formats.
971 : : @param rDefRowData (out-param) The default row format is returned here.
972 : : @param rColXFIndexes The column default XF indexes. */
973 : : void Finalize( XclExpDefaultRowData& rDefRowData, const ScfUInt16Vec& rColXFIndexes );
974 : :
975 : : /** Writes the DIMENSIONS record, all ROW records and all cell records. */
976 : : virtual void Save( XclExpStream& rStrm );
977 : : virtual void SaveXml( XclExpXmlStream& rStrm );
978 : :
979 : : XclExpDimensions* GetDimensions();
980 : :
981 : : private:
982 : : /** Returns access to the specified ROW record. Inserts preceding missing ROW records.
983 : : @param bRowAlwaysEmpty true = Created rows will not be filled with blank cells
984 : : in the XclExpRow::Finalize() function. */
985 : : XclExpRow& GetOrCreateRow( sal_uInt32 nXclRow, bool bRowAlwaysEmpty );
986 : :
987 : : private:
988 : : typedef ::boost::shared_ptr<XclExpRow> RowRef;
989 : : typedef ::std::map<sal_uInt32, RowRef> RowMap;
990 : :
991 : : RowMap maRowMap;
992 : : XclExpRowOutlineBuffer maOutlineBfr; /// Buffer for row outline groups.
993 : : XclExpDimensions maDimensions; /// DIMENSIONS record for used area.
994 : : };
995 : :
996 : : // ============================================================================
997 : : // Cell Table
998 : : // ============================================================================
999 : :
1000 : : class XclExpNote;
1001 : : class XclExpMergedcells;
1002 : : class XclExpHyperlink;
1003 : : class XclExpDval;
1004 : :
1005 : : /** This class contains the cell contents and more of an entire sheet.
1006 : :
1007 : : The cell table includes the settings and default formatting of all columns,
1008 : : the settings and default formatting of all used rows, and the contents of
1009 : : all cells of one sheet in a spreadsheet document.
1010 : :
1011 : : The constructor does all the work creating the cell table. It reads the
1012 : : Calc sheet and converts all columns, rows, and cells to Excel record data.
1013 : : Additioanlly, hyperlink records, note records, additional records for
1014 : : formula cells, data validation records, and outline records are created.
1015 : :
1016 : : The Finalize() function does even more work. It calculates default column
1017 : : settings and removes column records that are equal to this default. The
1018 : : same happens with rows: A default format is calculated for each row, and
1019 : : all blank cells in this row that have the same format are removed. Then,
1020 : : the most used row settings are calculated, and all empty rows that have the
1021 : : same settings are removed too.
1022 : :
1023 : : Records that are not stored inside the cell table area in an Excel file
1024 : : (i.e. DEFROWHEIGHT record, NOTE records, MERGEDCELLS record, HLINK records,
1025 : : DVAL and DV records for data validation) can be accessed with the function
1026 : : CreateRecord(). It returns the reference to the respective record (or
1027 : : record list) which can be inserted into a record list.
1028 : : */
1029 [ # # ][ # # ]: 0 : class XclExpCellTable : public XclExpRecordBase, protected XclExpRoot
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
1030 : : {
1031 : : public:
1032 : : explicit XclExpCellTable( const XclExpRoot& rRoot );
1033 : :
1034 : : /** Converts all XF identifiers into the Excel XF indexes and calculates default formats. */
1035 : : void Finalize();
1036 : :
1037 : : /** Returns the reference to an internal record specified by the passed record id.
1038 : : @param nRecId The record identifier that specifies which record is
1039 : : returned. Possible values are: EXC_ID_DEFROWHEIGHT, EXC_ID_NOTE,
1040 : : EXC_ID_MERGEDCELLS, EXC_ID_HLINK, EXC_ID_DVAL. */
1041 : : XclExpRecordRef CreateRecord( sal_uInt16 nRecId ) const;
1042 : : /** Saves the entire cell table. */
1043 : : virtual void Save( XclExpStream& rStrm );
1044 : : virtual void SaveXml( XclExpXmlStream& rStrm );
1045 : :
1046 : : private:
1047 : : typedef XclExpRecordList< XclExpNote > XclExpNoteList;
1048 : : typedef XclExpRecordList< XclExpHyperlink > XclExpHyperlinkList;
1049 : :
1050 : : typedef boost::shared_ptr< XclExpDefrowheight > XclExpDefrowhRef;
1051 : : typedef boost::shared_ptr< XclExpNoteList > XclExpNoteListRef;
1052 : : typedef boost::shared_ptr< XclExpMergedcells > XclExpMergedcellsRef;
1053 : : typedef boost::shared_ptr< XclExpHyperlinkList > XclExpHyperlinkRef;
1054 : : typedef boost::shared_ptr< XclExpDval > XclExpDvalRef;
1055 : : typedef boost::shared_ptr< XclExtLst > XclExtLstRef;
1056 : :
1057 : : XclExpColinfoBuffer maColInfoBfr; /// Buffer for column formatting.
1058 : : XclExpRowBuffer maRowBfr; /// Rows and cell records.
1059 : : XclExpArrayBuffer maArrayBfr; /// Buffer for ARRAY records.
1060 : : XclExpShrfmlaBuffer maShrfmlaBfr; /// Buffer for SHRFMLA records.
1061 : : XclExpTableopBuffer maTableopBfr; /// Buffer for TABLEOP records.
1062 : : XclExpDefrowhRef mxDefrowheight; /// DEFROWHEIGHT record for default row format.
1063 : : XclExpRecordRef mxGuts; /// GUTS record for outline areas.
1064 : : XclExpNoteListRef mxNoteList; /// List of NOTE records.
1065 : : XclExpMergedcellsRef mxMergedcells; /// MERGEDCELLS record for merged cell ranges.
1066 : : XclExpHyperlinkRef mxHyperlinkList; /// List of HLINK records.
1067 : : XclExpDvalRef mxDval; /// Data validation with DVAL and DV records.
1068 : : XclExtLstRef mxExtLst;
1069 : : };
1070 : :
1071 : : #endif
1072 : :
1073 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|