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 48 explicit SheetDataContextBase( const WorksheetHelper& rHelper ); 49 virtual ~SheetDataContextBase(); 50 }; 51 52 // ============================================================================ 53 54 /** This class implements importing the sheetData element. 55 56 The sheetData element contains all row settings and all cells in a single 57 sheet of a spreadsheet document. 58 */ 59 class SheetDataContext : public WorksheetContextBase, private SheetDataContextBase 60 { 61 public: 62 explicit SheetDataContext( WorksheetFragmentBase& rFragment ); 63 64 protected: 65 virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ); 66 virtual void onCharacters( const ::rtl::OUString& rChars ); 67 virtual void onEndElement(); 68 69 virtual ::oox::core::ContextHandlerRef onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm ); 70 71 private: 72 /** Different types of cell records. */ 73 enum CellType { CELLTYPE_VALUE, CELLTYPE_MULTI, CELLTYPE_FORMULA }; 74 75 /** Imports row settings from a row element. */ 76 void importRow( const AttributeList& rAttribs ); 77 /** Imports cell settings from a c element. */ 78 bool importCell( const AttributeList& rAttribs ); 79 /** Imports cell settings from an f element. */ 80 void importFormula( const AttributeList& rAttribs ); 81 82 /** Imports row settings from a ROW record. */ 83 void importRow( SequenceInputStream& rStrm ); 84 85 /** Reads a cell address and the following XF identifier. */ 86 bool readCellHeader( SequenceInputStream& rStrm, CellType eCellType ); 87 /** Reads a cell formula for the current cell. */ 88 ApiTokenSequence readCellFormula( SequenceInputStream& rStrm ); 89 /** Reads the formula range used by shared formulas, arrays, and data tables. */ 90 bool readFormulaRef( SequenceInputStream& rStrm ); 91 92 /** Imports an empty cell from a CELL_BLANK or MULTCELL_BLANK record. */ 93 void importCellBlank( SequenceInputStream& rStrm, CellType eCellType ); 94 /** Imports a boolean cell from a CELL_BOOL, MULTCELL_BOOL, or FORMULA_BOOL record. */ 95 void importCellBool( SequenceInputStream& rStrm, CellType eCellType ); 96 /** Imports a numeric cell from a CELL_DOUBLE, MULTCELL_DOUBLE, or FORMULA_DOUBLE record. */ 97 void importCellDouble( SequenceInputStream& rStrm, CellType eCellType ); 98 /** Imports an error code cell from a CELL_ERROR, MULTCELL_ERROR, or FORMULA_ERROR record. */ 99 void importCellError( SequenceInputStream& rStrm, CellType eCellType ); 100 /** Imports an encoded numeric cell from a CELL_RK or MULTCELL_RK record. */ 101 void importCellRk( SequenceInputStream& rStrm, CellType eCellType ); 102 /** Imports a rich-string cell from a CELL_RSTRING or MULTCELL_RSTRING record. */ 103 void importCellRString( SequenceInputStream& rStrm, CellType eCellType ); 104 /** Imports a string cell from a CELL_SI or MULTCELL_SI record. */ 105 void importCellSi( SequenceInputStream& rStrm, CellType eCellType ); 106 /** Imports a string cell from a CELL_STRING, MULTCELL_STRING, or FORMULA_STRING record. */ 107 void importCellString( SequenceInputStream& rStrm, CellType eCellType ); 108 109 /** Imports an array formula from an ARRAY record. */ 110 void importArray( SequenceInputStream& rStrm ); 111 /** Imports table operation from a DATATABLE record. */ 112 void importDataTable( SequenceInputStream& rStrm ); 113 /** Imports a shared formula from a SHAREDFORMULA record. */ 114 void importSharedFmla( SequenceInputStream& rStrm ); 115 116 private: 117 ::rtl::OUString maCellValue; /// Cell value string (OOXML only). 118 RichStringRef mxInlineStr; /// Inline rich string (OOXML only). 119 ApiTokenSequence maTokens; /// Formula token array (OOXML only). 120 DataTableModel maTableData; /// Settings for table operations. 121 BinAddress maCurrPos; /// Current cell position (BIFF12 only). 122 bool mbHasFormula; /// True = current cell has formula data (OOXML only). 123 bool mbValidRange; /// True = maFmlaData.maFormulaRef is valid (OOXML only). 124 }; 125 126 // ============================================================================ 127 128 /** This class implements importing row settings and all cells of a sheet. 129 */ 130 class BiffSheetDataContext : public BiffWorksheetContextBase, private SheetDataContextBase 131 { 132 public: 133 explicit BiffSheetDataContext( const WorksheetHelper& rHelper ); 134 135 /** Tries to import a sheet data record. */ 136 virtual void importRecord( BiffInputStream& rStrm ); 137 138 private: 139 /** Imports row settings from a ROW record. */ 140 void importRow( BiffInputStream& rStrm ); 141 142 /** Reads an XF identifier and initializes a new cell. */ 143 bool readCellXfId( BiffInputStream& rStrm, const BinAddress& rAddr, bool bBiff2 ); 144 /** Reads a BIFF cell address and the following XF identifier. */ 145 bool readCellHeader( BiffInputStream& rStrm, bool bBiff2 ); 146 /** Reads the formula range used by shared formulas, arrays, and data tables. */ 147 bool readFormulaRef( BiffInputStream& rStrm ); 148 149 /** Imports a BLANK record describing a blank but formatted cell. */ 150 void importBlank( BiffInputStream& rStrm ); 151 /** Imports a BOOLERR record describing a boolean or error code cell. */ 152 void importBoolErr( BiffInputStream& rStrm ); 153 /** Imports a FORMULA record describing a formula cell. */ 154 void importFormula( BiffInputStream& rStrm ); 155 /** Imports an INTEGER record describing a BIFF2 integer cell. */ 156 void importInteger( BiffInputStream& rStrm ); 157 /** Imports a LABEL record describing an unformatted string cell. */ 158 void importLabel( BiffInputStream& rStrm ); 159 /** Imports a LABELSST record describing a string cell using the shared string list. */ 160 void importLabelSst( BiffInputStream& rStrm ); 161 /** Imports a MULTBLANK record describing a range of blank but formatted cells. */ 162 void importMultBlank( BiffInputStream& rStrm ); 163 /** Imports a MULTRK record describing a range of numeric cells. */ 164 void importMultRk( BiffInputStream& rStrm ); 165 /** Imports a NUMBER record describing a floating-point cell. */ 166 void importNumber( BiffInputStream& rStrm ); 167 /** Imports an RK record describing a numeric cell. */ 168 void importRk( BiffInputStream& rStrm ); 169 170 /** Imports an ARRAY record describing an array formula of a cell range. */ 171 void importArray( BiffInputStream& rStrm ); 172 /** Imports table operation from a DATATABLE or DATATABLE2 record. */ 173 void importDataTable( BiffInputStream& rStrm ); 174 /** Imports a SHAREDFMLA record describing a shared formula in a cell range. */ 175 void importSharedFmla( BiffInputStream& rStrm ); 176 177 private: 178 sal_uInt32 mnFormulaSkipSize; /// Number of bytes to be ignored in FORMULA record. 179 sal_uInt32 mnArraySkipSize; /// Number of bytes to be ignored in ARRAY record. 180 sal_uInt16 mnBiff2XfId; /// Current XF identifier from IXFE record. 181 OptValue< bool > mobBiff2HasXfs; /// Select XF formatting or direct formatting in BIFF2. 182 }; 183 184 // ============================================================================ 185 186 } // namespace xls 187 } // namespace oox 188 189 #endif 190