xref: /trunk/main/oox/inc/oox/xls/sheetdatacontext.hxx (revision 9c741048) !
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef OOX_XLS_SHEETDATACONTEXT_HXX
25 #define OOX_XLS_SHEETDATACONTEXT_HXX
26 
27 #include "oox/xls/excelhandlers.hxx"
28 #include "oox/xls/richstring.hxx"
29 #include "oox/xls/sheetdatabuffer.hxx"
30 
31 namespace oox {
32 namespace xls {
33 
34 // ============================================================================
35 
36 /** Used as base for sheet data context classes. Provides fast access to often
37     used converter objects and sheet index, to improve performance.
38  */
39 struct SheetDataContextBase
40 {
41     AddressConverter&   mrAddressConv;      /// The address converter.
42     FormulaParser&      mrFormulaParser;    /// The formula parser.
43     SheetDataBuffer&    mrSheetData;        /// The sheet data buffer for cell content and formatting.
44     CellModel           maCellData;         /// Position, contents, formatting of current imported cell.
45     CellFormulaModel    maFmlaData;         /// Settings for a cell formula.
46     sal_Int16           mnSheet;            /// Index of the current sheet.
47     ::com::sun::star::table::CellAddress
48                         maLastCellAddress;  /// The address of the most recently populated cell.
49 
50     explicit            SheetDataContextBase( const WorksheetHelper& rHelper );
51     virtual             ~SheetDataContextBase();
52 };
53 
54 // ============================================================================
55 
56 /** This class implements importing the sheetData element.
57 
58     The sheetData element contains all row settings and all cells in a single
59     sheet of a spreadsheet document.
60  */
61 class SheetDataContext : public WorksheetContextBase, private SheetDataContextBase
62 {
63 public:
64     explicit            SheetDataContext( WorksheetFragmentBase& rFragment );
65 
66 protected:
67     virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs );
68     virtual void        onCharacters( const ::rtl::OUString& rChars );
69     virtual void        onEndElement();
70 
71     virtual ::oox::core::ContextHandlerRef onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm );
72 
73 private:
74     /** Different types of cell records. */
75     enum CellType { CELLTYPE_VALUE, CELLTYPE_MULTI, CELLTYPE_FORMULA };
76 
77     /** Imports row settings from a row element. */
78     void                importRow( const AttributeList& rAttribs );
79     /** Imports cell settings from a c element. */
80     bool                importCell( const AttributeList& rAttribs );
81     /** Imports cell settings from an f element. */
82     void                importFormula( const AttributeList& rAttribs );
83 
84     /** Imports row settings from a ROW record. */
85     void                importRow( SequenceInputStream& rStrm );
86 
87     /** Reads a cell address and the following XF identifier. */
88     bool                readCellHeader( SequenceInputStream& rStrm, CellType eCellType );
89     /** Reads a cell formula for the current cell. */
90     ApiTokenSequence    readCellFormula( SequenceInputStream& rStrm );
91     /** Reads the formula range used by shared formulas, arrays, and data tables. */
92     bool                readFormulaRef( SequenceInputStream& rStrm );
93 
94     /** Imports an empty cell from a CELL_BLANK or MULTCELL_BLANK record. */
95     void                importCellBlank( SequenceInputStream& rStrm, CellType eCellType );
96     /** Imports a boolean cell from a CELL_BOOL, MULTCELL_BOOL, or FORMULA_BOOL record. */
97     void                importCellBool( SequenceInputStream& rStrm, CellType eCellType );
98     /** Imports a numeric cell from a CELL_DOUBLE, MULTCELL_DOUBLE, or FORMULA_DOUBLE record. */
99     void                importCellDouble( SequenceInputStream& rStrm, CellType eCellType );
100     /** Imports an error code cell from a CELL_ERROR, MULTCELL_ERROR, or FORMULA_ERROR record. */
101     void                importCellError( SequenceInputStream& rStrm, CellType eCellType );
102     /** Imports an encoded numeric cell from a CELL_RK or MULTCELL_RK record. */
103     void                importCellRk( SequenceInputStream& rStrm, CellType eCellType );
104     /** Imports a rich-string cell from a CELL_RSTRING or MULTCELL_RSTRING record. */
105     void                importCellRString( SequenceInputStream& rStrm, CellType eCellType );
106     /** Imports a string cell from a CELL_SI or MULTCELL_SI record. */
107     void                importCellSi( SequenceInputStream& rStrm, CellType eCellType );
108     /** Imports a string cell from a CELL_STRING, MULTCELL_STRING, or FORMULA_STRING record. */
109     void                importCellString( SequenceInputStream& rStrm, CellType eCellType );
110 
111     /** Imports an array formula from an ARRAY record. */
112     void                importArray( SequenceInputStream& rStrm );
113     /** Imports table operation from a DATATABLE record. */
114     void                importDataTable( SequenceInputStream& rStrm );
115     /** Imports a shared formula from a SHAREDFORMULA record. */
116     void                importSharedFmla( SequenceInputStream& rStrm );
117 
118 private:
119     ::rtl::OUString     maCellValue;        /// Cell value string (OOXML only).
120     RichStringRef       mxInlineStr;        /// Inline rich string (OOXML only).
121     ApiTokenSequence    maTokens;           /// Formula token array (OOXML only).
122     DataTableModel      maTableData;        /// Settings for table operations.
123     BinAddress          maCurrPos;          /// Current cell position (BIFF12 only).
124     bool                mbHasFormula;       /// True = current cell has formula data (OOXML only).
125     bool                mbValidRange;       /// True = maFmlaData.maFormulaRef is valid (OOXML only).
126 };
127 
128 // ============================================================================
129 
130 /** This class implements importing row settings and all cells of a sheet.
131  */
132 class BiffSheetDataContext : public BiffWorksheetContextBase, private SheetDataContextBase
133 {
134 public:
135     explicit            BiffSheetDataContext( const WorksheetHelper& rHelper );
136 
137     /** Tries to import a sheet data record. */
138     virtual void        importRecord( BiffInputStream& rStrm );
139 
140 private:
141     /** Imports row settings from a ROW record. */
142     void                importRow( BiffInputStream& rStrm );
143 
144     /** Reads an XF identifier and initializes a new cell. */
145     bool                readCellXfId( BiffInputStream& rStrm, const BinAddress& rAddr, bool bBiff2 );
146     /** Reads a BIFF cell address and the following XF identifier. */
147     bool                readCellHeader( BiffInputStream& rStrm, bool bBiff2 );
148     /** Reads the formula range used by shared formulas, arrays, and data tables. */
149     bool                readFormulaRef( BiffInputStream& rStrm );
150 
151     /** Imports a BLANK record describing a blank but formatted cell. */
152     void                importBlank( BiffInputStream& rStrm );
153     /** Imports a BOOLERR record describing a boolean or error code cell. */
154     void                importBoolErr( BiffInputStream& rStrm );
155     /** Imports a FORMULA record describing a formula cell. */
156     void                importFormula( BiffInputStream& rStrm );
157     /** Imports an INTEGER record describing a BIFF2 integer cell. */
158     void                importInteger( BiffInputStream& rStrm );
159     /** Imports a LABEL record describing an unformatted string cell. */
160     void                importLabel( BiffInputStream& rStrm );
161     /** Imports a LABELSST record describing a string cell using the shared string list. */
162     void                importLabelSst( BiffInputStream& rStrm );
163     /** Imports a MULTBLANK record describing a range of blank but formatted cells. */
164     void                importMultBlank( BiffInputStream& rStrm );
165     /** Imports a MULTRK record describing a range of numeric cells. */
166     void                importMultRk( BiffInputStream& rStrm );
167     /** Imports a NUMBER record describing a floating-point cell. */
168     void                importNumber( BiffInputStream& rStrm );
169     /** Imports an RK record describing a numeric cell. */
170     void                importRk( BiffInputStream& rStrm );
171 
172     /** Imports an ARRAY record describing an array formula of a cell range. */
173     void                importArray( BiffInputStream& rStrm );
174     /** Imports table operation from a DATATABLE or DATATABLE2 record. */
175     void                importDataTable( BiffInputStream& rStrm );
176     /** Imports a SHAREDFMLA record describing a shared formula in a cell range. */
177     void                importSharedFmla( BiffInputStream& rStrm );
178 
179 private:
180     sal_uInt32          mnFormulaSkipSize;  /// Number of bytes to be ignored in FORMULA record.
181     sal_uInt32          mnArraySkipSize;    /// Number of bytes to be ignored in ARRAY record.
182     sal_uInt16          mnBiff2XfId;        /// Current XF identifier from IXFE record.
183     OptValue< bool >    mobBiff2HasXfs;     /// Select XF formatting or direct formatting in BIFF2.
184 };
185 
186 // ============================================================================
187 
188 } // namespace xls
189 } // namespace oox
190 
191 #endif
192