xref: /trunk/main/oox/source/xls/sheetdatacontext.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir #include "oox/xls/sheetdatacontext.hxx"
29*cdf0e10cSrcweir 
30*cdf0e10cSrcweir #include <com/sun/star/table/CellContentType.hpp>
31*cdf0e10cSrcweir #include <com/sun/star/table/XCell.hpp>
32*cdf0e10cSrcweir #include <com/sun/star/table/XCellRange.hpp>
33*cdf0e10cSrcweir #include <com/sun/star/text/XText.hpp>
34*cdf0e10cSrcweir #include "oox/helper/attributelist.hxx"
35*cdf0e10cSrcweir #include "oox/helper/propertyset.hxx"
36*cdf0e10cSrcweir #include "oox/xls/addressconverter.hxx"
37*cdf0e10cSrcweir #include "oox/xls/biffinputstream.hxx"
38*cdf0e10cSrcweir #include "oox/xls/formulaparser.hxx"
39*cdf0e10cSrcweir #include "oox/xls/richstringcontext.hxx"
40*cdf0e10cSrcweir #include "oox/xls/unitconverter.hxx"
41*cdf0e10cSrcweir 
42*cdf0e10cSrcweir namespace oox {
43*cdf0e10cSrcweir namespace xls {
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir // ============================================================================
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir using namespace ::com::sun::star::sheet;
48*cdf0e10cSrcweir using namespace ::com::sun::star::table;
49*cdf0e10cSrcweir using namespace ::com::sun::star::text;
50*cdf0e10cSrcweir using namespace ::com::sun::star::uno;
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir using ::oox::core::ContextHandlerRef;
53*cdf0e10cSrcweir using ::rtl::OUString;
54*cdf0e10cSrcweir 
55*cdf0e10cSrcweir // ============================================================================
56*cdf0e10cSrcweir 
57*cdf0e10cSrcweir namespace {
58*cdf0e10cSrcweir 
59*cdf0e10cSrcweir // record constants -----------------------------------------------------------
60*cdf0e10cSrcweir 
61*cdf0e10cSrcweir const sal_uInt32 BIFF12_CELL_SHOWPHONETIC   = 0x01000000;
62*cdf0e10cSrcweir 
63*cdf0e10cSrcweir const sal_uInt8 BIFF12_DATATABLE_ROW        = 0x01;
64*cdf0e10cSrcweir const sal_uInt8 BIFF12_DATATABLE_2D         = 0x02;
65*cdf0e10cSrcweir const sal_uInt8 BIFF12_DATATABLE_REF1DEL    = 0x04;
66*cdf0e10cSrcweir const sal_uInt8 BIFF12_DATATABLE_REF2DEL    = 0x08;
67*cdf0e10cSrcweir 
68*cdf0e10cSrcweir const sal_uInt16 BIFF12_ROW_THICKTOP        = 0x0001;
69*cdf0e10cSrcweir const sal_uInt16 BIFF12_ROW_THICKBOTTOM     = 0x0002;
70*cdf0e10cSrcweir const sal_uInt16 BIFF12_ROW_COLLAPSED       = 0x0800;
71*cdf0e10cSrcweir const sal_uInt16 BIFF12_ROW_HIDDEN          = 0x1000;
72*cdf0e10cSrcweir const sal_uInt16 BIFF12_ROW_CUSTOMHEIGHT    = 0x2000;
73*cdf0e10cSrcweir const sal_uInt16 BIFF12_ROW_CUSTOMFORMAT    = 0x4000;
74*cdf0e10cSrcweir const sal_uInt8 BIFF12_ROW_SHOWPHONETIC     = 0x01;
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir const sal_uInt16 BIFF_DATATABLE_ROW         = 0x0004;
77*cdf0e10cSrcweir const sal_uInt16 BIFF_DATATABLE_2D          = 0x0008;
78*cdf0e10cSrcweir const sal_uInt16 BIFF_DATATABLE_REF1DEL     = 0x0010;
79*cdf0e10cSrcweir const sal_uInt16 BIFF_DATATABLE_REF2DEL     = 0x0020;
80*cdf0e10cSrcweir 
81*cdf0e10cSrcweir const sal_uInt8 BIFF_FORMULA_RES_STRING     = 0;        /// Result is a string.
82*cdf0e10cSrcweir const sal_uInt8 BIFF_FORMULA_RES_BOOL       = 1;        /// Result is Boolean value.
83*cdf0e10cSrcweir const sal_uInt8 BIFF_FORMULA_RES_ERROR      = 2;        /// Result is error code.
84*cdf0e10cSrcweir const sal_uInt8 BIFF_FORMULA_RES_EMPTY      = 3;        /// Result is empty cell (BIFF8 only).
85*cdf0e10cSrcweir const sal_uInt16 BIFF_FORMULA_SHARED        = 0x0008;   /// Shared formula cell.
86*cdf0e10cSrcweir 
87*cdf0e10cSrcweir const sal_uInt8 BIFF2_ROW_CUSTOMFORMAT      = 0x01;
88*cdf0e10cSrcweir const sal_uInt16 BIFF_ROW_DEFAULTHEIGHT     = 0x8000;
89*cdf0e10cSrcweir const sal_uInt16 BIFF_ROW_HEIGHTMASK        = 0x7FFF;
90*cdf0e10cSrcweir const sal_uInt32 BIFF_ROW_COLLAPSED         = 0x00000010;
91*cdf0e10cSrcweir const sal_uInt32 BIFF_ROW_HIDDEN            = 0x00000020;
92*cdf0e10cSrcweir const sal_uInt32 BIFF_ROW_CUSTOMHEIGHT      = 0x00000040;
93*cdf0e10cSrcweir const sal_uInt32 BIFF_ROW_CUSTOMFORMAT      = 0x00000080;
94*cdf0e10cSrcweir const sal_uInt32 BIFF_ROW_THICKTOP          = 0x10000000;
95*cdf0e10cSrcweir const sal_uInt32 BIFF_ROW_THICKBOTTOM       = 0x20000000;
96*cdf0e10cSrcweir const sal_uInt32 BIFF_ROW_SHOWPHONETIC      = 0x40000000;
97*cdf0e10cSrcweir 
98*cdf0e10cSrcweir const sal_Int32 BIFF2_CELL_USEIXFE          = 63;
99*cdf0e10cSrcweir 
100*cdf0e10cSrcweir } // namespace
101*cdf0e10cSrcweir 
102*cdf0e10cSrcweir // ============================================================================
103*cdf0e10cSrcweir 
104*cdf0e10cSrcweir SheetDataContextBase::SheetDataContextBase( const WorksheetHelper& rHelper ) :
105*cdf0e10cSrcweir     mrAddressConv( rHelper.getAddressConverter() ),
106*cdf0e10cSrcweir     mrFormulaParser( rHelper.getFormulaParser() ),
107*cdf0e10cSrcweir     mrSheetData( rHelper.getSheetData() ),
108*cdf0e10cSrcweir     mnSheet( rHelper.getSheetIndex() )
109*cdf0e10cSrcweir {
110*cdf0e10cSrcweir }
111*cdf0e10cSrcweir 
112*cdf0e10cSrcweir SheetDataContextBase::~SheetDataContextBase()
113*cdf0e10cSrcweir {
114*cdf0e10cSrcweir }
115*cdf0e10cSrcweir 
116*cdf0e10cSrcweir // ============================================================================
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir SheetDataContext::SheetDataContext( WorksheetFragmentBase& rFragment ) :
119*cdf0e10cSrcweir     WorksheetContextBase( rFragment ),
120*cdf0e10cSrcweir     SheetDataContextBase( rFragment ),
121*cdf0e10cSrcweir     mbHasFormula( false ),
122*cdf0e10cSrcweir     mbValidRange( false )
123*cdf0e10cSrcweir {
124*cdf0e10cSrcweir }
125*cdf0e10cSrcweir 
126*cdf0e10cSrcweir ContextHandlerRef SheetDataContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
127*cdf0e10cSrcweir {
128*cdf0e10cSrcweir     switch( getCurrentElement() )
129*cdf0e10cSrcweir     {
130*cdf0e10cSrcweir         case XLS_TOKEN( sheetData ):
131*cdf0e10cSrcweir             if( nElement == XLS_TOKEN( row ) ) { importRow( rAttribs ); return this; }
132*cdf0e10cSrcweir         break;
133*cdf0e10cSrcweir 
134*cdf0e10cSrcweir         case XLS_TOKEN( row ):
135*cdf0e10cSrcweir             // do not process cell elements with invalid (out-of-range) address
136*cdf0e10cSrcweir             if( nElement == XLS_TOKEN( c ) && importCell( rAttribs ) )
137*cdf0e10cSrcweir                 return this;
138*cdf0e10cSrcweir         break;
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir         case XLS_TOKEN( c ):
141*cdf0e10cSrcweir             switch( nElement )
142*cdf0e10cSrcweir             {
143*cdf0e10cSrcweir                 case XLS_TOKEN( is ):
144*cdf0e10cSrcweir                     mxInlineStr.reset( new RichString( *this ) );
145*cdf0e10cSrcweir                     return new RichStringContext( *this, mxInlineStr );
146*cdf0e10cSrcweir                 case XLS_TOKEN( v ):
147*cdf0e10cSrcweir                     return this;    // characters contain cell value
148*cdf0e10cSrcweir                 case XLS_TOKEN( f ):
149*cdf0e10cSrcweir                     importFormula( rAttribs );
150*cdf0e10cSrcweir                     return this;    // characters contain formula string
151*cdf0e10cSrcweir             }
152*cdf0e10cSrcweir         break;
153*cdf0e10cSrcweir     }
154*cdf0e10cSrcweir     return 0;
155*cdf0e10cSrcweir }
156*cdf0e10cSrcweir 
157*cdf0e10cSrcweir void SheetDataContext::onCharacters( const OUString& rChars )
158*cdf0e10cSrcweir {
159*cdf0e10cSrcweir     switch( getCurrentElement() )
160*cdf0e10cSrcweir     {
161*cdf0e10cSrcweir         case XLS_TOKEN( v ):
162*cdf0e10cSrcweir             maCellValue = rChars;
163*cdf0e10cSrcweir         break;
164*cdf0e10cSrcweir         case XLS_TOKEN( f ):
165*cdf0e10cSrcweir             if( maFmlaData.mnFormulaType != XML_TOKEN_INVALID )
166*cdf0e10cSrcweir                 maTokens = mrFormulaParser.importFormula( maCellData.maCellAddr, rChars );
167*cdf0e10cSrcweir         break;
168*cdf0e10cSrcweir     }
169*cdf0e10cSrcweir }
170*cdf0e10cSrcweir 
171*cdf0e10cSrcweir void SheetDataContext::onEndElement()
172*cdf0e10cSrcweir {
173*cdf0e10cSrcweir     if( getCurrentElement() == XLS_TOKEN( c ) )
174*cdf0e10cSrcweir     {
175*cdf0e10cSrcweir         // try to create a formula cell
176*cdf0e10cSrcweir         if( mbHasFormula ) switch( maFmlaData.mnFormulaType )
177*cdf0e10cSrcweir         {
178*cdf0e10cSrcweir             case XML_normal:
179*cdf0e10cSrcweir                 mrSheetData.setFormulaCell( maCellData, maTokens );
180*cdf0e10cSrcweir             break;
181*cdf0e10cSrcweir             case XML_shared:
182*cdf0e10cSrcweir                 if( maFmlaData.mnSharedId >= 0 )
183*cdf0e10cSrcweir                 {
184*cdf0e10cSrcweir                     if( mbValidRange && maFmlaData.isValidSharedRef( maCellData.maCellAddr ) )
185*cdf0e10cSrcweir                         mrSheetData.createSharedFormula( maFmlaData.mnSharedId, maTokens );
186*cdf0e10cSrcweir                     mrSheetData.setFormulaCell( maCellData, maFmlaData.mnSharedId );
187*cdf0e10cSrcweir                 }
188*cdf0e10cSrcweir                 else
189*cdf0e10cSrcweir                     // no success, set plain cell value and formatting below
190*cdf0e10cSrcweir                     mbHasFormula = false;
191*cdf0e10cSrcweir             break;
192*cdf0e10cSrcweir             case XML_array:
193*cdf0e10cSrcweir                 if( mbValidRange && maFmlaData.isValidArrayRef( maCellData.maCellAddr ) )
194*cdf0e10cSrcweir                     mrSheetData.createArrayFormula( maFmlaData.maFormulaRef, maTokens );
195*cdf0e10cSrcweir                 // set cell formatting, but do not set result as cell value
196*cdf0e10cSrcweir                 mrSheetData.setBlankCell( maCellData );
197*cdf0e10cSrcweir             break;
198*cdf0e10cSrcweir             case XML_dataTable:
199*cdf0e10cSrcweir                 if( mbValidRange )
200*cdf0e10cSrcweir                     mrSheetData.createTableOperation( maFmlaData.maFormulaRef, maTableData );
201*cdf0e10cSrcweir                 // set cell formatting, but do not set result as cell value
202*cdf0e10cSrcweir                 mrSheetData.setBlankCell( maCellData );
203*cdf0e10cSrcweir             break;
204*cdf0e10cSrcweir             default:
205*cdf0e10cSrcweir                 OSL_ENSURE( maFmlaData.mnFormulaType == XML_TOKEN_INVALID, "SheetDataContext::onEndElement - unknown formula type" );
206*cdf0e10cSrcweir                 mbHasFormula = false;
207*cdf0e10cSrcweir         }
208*cdf0e10cSrcweir 
209*cdf0e10cSrcweir         if( !mbHasFormula )
210*cdf0e10cSrcweir         {
211*cdf0e10cSrcweir             // no formula created: try to set the cell value
212*cdf0e10cSrcweir             if( maCellValue.getLength() > 0 ) switch( maCellData.mnCellType )
213*cdf0e10cSrcweir             {
214*cdf0e10cSrcweir                 case XML_n:
215*cdf0e10cSrcweir                     mrSheetData.setValueCell( maCellData, maCellValue.toDouble() );
216*cdf0e10cSrcweir                 break;
217*cdf0e10cSrcweir                 case XML_b:
218*cdf0e10cSrcweir                     mrSheetData.setBooleanCell( maCellData, maCellValue.toDouble() != 0.0 );
219*cdf0e10cSrcweir                 break;
220*cdf0e10cSrcweir                 case XML_e:
221*cdf0e10cSrcweir                     mrSheetData.setErrorCell( maCellData, maCellValue );
222*cdf0e10cSrcweir                 break;
223*cdf0e10cSrcweir                 case XML_str:
224*cdf0e10cSrcweir                     mrSheetData.setStringCell( maCellData, maCellValue );
225*cdf0e10cSrcweir                 break;
226*cdf0e10cSrcweir                 case XML_s:
227*cdf0e10cSrcweir                     mrSheetData.setStringCell( maCellData, maCellValue.toInt32() );
228*cdf0e10cSrcweir                 break;
229*cdf0e10cSrcweir             }
230*cdf0e10cSrcweir             else if( (maCellData.mnCellType == XML_inlineStr) && mxInlineStr.get() )
231*cdf0e10cSrcweir             {
232*cdf0e10cSrcweir                 mxInlineStr->finalizeImport();
233*cdf0e10cSrcweir                 mrSheetData.setStringCell( maCellData, mxInlineStr );
234*cdf0e10cSrcweir             }
235*cdf0e10cSrcweir             else
236*cdf0e10cSrcweir             {
237*cdf0e10cSrcweir                 // empty cell, update cell type
238*cdf0e10cSrcweir                 maCellData.mnCellType = XML_TOKEN_INVALID;
239*cdf0e10cSrcweir                 mrSheetData.setBlankCell( maCellData );
240*cdf0e10cSrcweir             }
241*cdf0e10cSrcweir         }
242*cdf0e10cSrcweir     }
243*cdf0e10cSrcweir }
244*cdf0e10cSrcweir 
245*cdf0e10cSrcweir ContextHandlerRef SheetDataContext::onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm )
246*cdf0e10cSrcweir {
247*cdf0e10cSrcweir     switch( getCurrentElement() )
248*cdf0e10cSrcweir     {
249*cdf0e10cSrcweir         case BIFF12_ID_SHEETDATA:
250*cdf0e10cSrcweir             if( nRecId == BIFF12_ID_ROW ) { importRow( rStrm ); return this; }
251*cdf0e10cSrcweir         break;
252*cdf0e10cSrcweir 
253*cdf0e10cSrcweir         case BIFF12_ID_ROW:
254*cdf0e10cSrcweir             switch( nRecId )
255*cdf0e10cSrcweir             {
256*cdf0e10cSrcweir                 case BIFF12_ID_ARRAY:           importArray( rStrm );                           break;
257*cdf0e10cSrcweir                 case BIFF12_ID_CELL_BOOL:       importCellBool( rStrm, CELLTYPE_VALUE );        break;
258*cdf0e10cSrcweir                 case BIFF12_ID_CELL_BLANK:      importCellBlank( rStrm, CELLTYPE_VALUE );       break;
259*cdf0e10cSrcweir                 case BIFF12_ID_CELL_DOUBLE:     importCellDouble( rStrm, CELLTYPE_VALUE );      break;
260*cdf0e10cSrcweir                 case BIFF12_ID_CELL_ERROR:      importCellError( rStrm, CELLTYPE_VALUE );       break;
261*cdf0e10cSrcweir                 case BIFF12_ID_CELL_RK:         importCellRk( rStrm, CELLTYPE_VALUE );          break;
262*cdf0e10cSrcweir                 case BIFF12_ID_CELL_RSTRING:    importCellRString( rStrm, CELLTYPE_VALUE );     break;
263*cdf0e10cSrcweir                 case BIFF12_ID_CELL_SI:         importCellSi( rStrm, CELLTYPE_VALUE );          break;
264*cdf0e10cSrcweir                 case BIFF12_ID_CELL_STRING:     importCellString( rStrm, CELLTYPE_VALUE );      break;
265*cdf0e10cSrcweir                 case BIFF12_ID_DATATABLE:       importDataTable( rStrm );                       break;
266*cdf0e10cSrcweir                 case BIFF12_ID_FORMULA_BOOL:    importCellBool( rStrm, CELLTYPE_FORMULA );      break;
267*cdf0e10cSrcweir                 case BIFF12_ID_FORMULA_DOUBLE:  importCellDouble( rStrm, CELLTYPE_FORMULA );    break;
268*cdf0e10cSrcweir                 case BIFF12_ID_FORMULA_ERROR:   importCellError( rStrm, CELLTYPE_FORMULA );     break;
269*cdf0e10cSrcweir                 case BIFF12_ID_FORMULA_STRING:  importCellString( rStrm, CELLTYPE_FORMULA );    break;
270*cdf0e10cSrcweir                 case BIFF12_ID_MULTCELL_BOOL:   importCellBool( rStrm, CELLTYPE_MULTI );        break;
271*cdf0e10cSrcweir                 case BIFF12_ID_MULTCELL_BLANK:  importCellBlank( rStrm, CELLTYPE_MULTI );       break;
272*cdf0e10cSrcweir                 case BIFF12_ID_MULTCELL_DOUBLE: importCellDouble( rStrm, CELLTYPE_MULTI );      break;
273*cdf0e10cSrcweir                 case BIFF12_ID_MULTCELL_ERROR:  importCellError( rStrm, CELLTYPE_MULTI );       break;
274*cdf0e10cSrcweir                 case BIFF12_ID_MULTCELL_RK:     importCellRk( rStrm, CELLTYPE_MULTI );          break;
275*cdf0e10cSrcweir                 case BIFF12_ID_MULTCELL_RSTRING:importCellRString( rStrm, CELLTYPE_MULTI );     break;
276*cdf0e10cSrcweir                 case BIFF12_ID_MULTCELL_SI:     importCellSi( rStrm, CELLTYPE_MULTI );          break;
277*cdf0e10cSrcweir                 case BIFF12_ID_MULTCELL_STRING: importCellString( rStrm, CELLTYPE_MULTI );      break;
278*cdf0e10cSrcweir                 case BIFF12_ID_SHAREDFMLA:      importSharedFmla( rStrm );                      break;
279*cdf0e10cSrcweir             }
280*cdf0e10cSrcweir         break;
281*cdf0e10cSrcweir     }
282*cdf0e10cSrcweir     return 0;
283*cdf0e10cSrcweir }
284*cdf0e10cSrcweir 
285*cdf0e10cSrcweir // private --------------------------------------------------------------------
286*cdf0e10cSrcweir 
287*cdf0e10cSrcweir void SheetDataContext::importRow( const AttributeList& rAttribs )
288*cdf0e10cSrcweir {
289*cdf0e10cSrcweir     RowModel aModel;
290*cdf0e10cSrcweir     aModel.mnRow          = rAttribs.getInteger( XML_r, -1 );
291*cdf0e10cSrcweir     aModel.mfHeight       = rAttribs.getDouble( XML_ht, -1.0 );
292*cdf0e10cSrcweir     aModel.mnXfId         = rAttribs.getInteger( XML_s, -1 );
293*cdf0e10cSrcweir     aModel.mnLevel        = rAttribs.getInteger( XML_outlineLevel, 0 );
294*cdf0e10cSrcweir     aModel.mbCustomHeight = rAttribs.getBool( XML_customHeight, false );
295*cdf0e10cSrcweir     aModel.mbCustomFormat = rAttribs.getBool( XML_customFormat, false );
296*cdf0e10cSrcweir     aModel.mbShowPhonetic = rAttribs.getBool( XML_ph, false );
297*cdf0e10cSrcweir     aModel.mbHidden       = rAttribs.getBool( XML_hidden, false );
298*cdf0e10cSrcweir     aModel.mbCollapsed    = rAttribs.getBool( XML_collapsed, false );
299*cdf0e10cSrcweir     aModel.mbThickTop     = rAttribs.getBool( XML_thickTop, false );
300*cdf0e10cSrcweir     aModel.mbThickBottom  = rAttribs.getBool( XML_thickBot, false );
301*cdf0e10cSrcweir 
302*cdf0e10cSrcweir     // decode the column spans (space-separated list of colon-separated integer pairs)
303*cdf0e10cSrcweir     OUString aColSpansText = rAttribs.getString( XML_spans, OUString() );
304*cdf0e10cSrcweir     sal_Int32 nMaxCol = mrAddressConv.getMaxApiAddress().Column;
305*cdf0e10cSrcweir     sal_Int32 nIndex = 0;
306*cdf0e10cSrcweir     while( nIndex >= 0 )
307*cdf0e10cSrcweir     {
308*cdf0e10cSrcweir         OUString aColSpanToken = aColSpansText.getToken( 0, ' ', nIndex );
309*cdf0e10cSrcweir         sal_Int32 nSepPos = aColSpanToken.indexOf( ':' );
310*cdf0e10cSrcweir         if( (0 < nSepPos) && (nSepPos + 1 < aColSpanToken.getLength()) )
311*cdf0e10cSrcweir         {
312*cdf0e10cSrcweir             // OOXML uses 1-based integer column indexes, row model expects 0-based colspans
313*cdf0e10cSrcweir             sal_Int32 nLastCol = ::std::min( aColSpanToken.copy( nSepPos + 1 ).toInt32() - 1, nMaxCol );
314*cdf0e10cSrcweir             aModel.insertColSpan( ValueRange( aColSpanToken.copy( 0, nSepPos ).toInt32() - 1, nLastCol ) );
315*cdf0e10cSrcweir         }
316*cdf0e10cSrcweir     }
317*cdf0e10cSrcweir 
318*cdf0e10cSrcweir     // set row properties in the current sheet
319*cdf0e10cSrcweir     setRowModel( aModel );
320*cdf0e10cSrcweir }
321*cdf0e10cSrcweir 
322*cdf0e10cSrcweir bool SheetDataContext::importCell( const AttributeList& rAttribs )
323*cdf0e10cSrcweir {
324*cdf0e10cSrcweir     bool bValidAddr = mrAddressConv.convertToCellAddress( maCellData.maCellAddr, rAttribs.getString( XML_r, OUString() ), mnSheet, true );
325*cdf0e10cSrcweir     if( bValidAddr )
326*cdf0e10cSrcweir     {
327*cdf0e10cSrcweir         maCellData.mnCellType     = rAttribs.getToken( XML_t, XML_n );
328*cdf0e10cSrcweir         maCellData.mnXfId         = rAttribs.getInteger( XML_s, -1 );
329*cdf0e10cSrcweir         maCellData.mbShowPhonetic = rAttribs.getBool( XML_ph, false );
330*cdf0e10cSrcweir 
331*cdf0e10cSrcweir         // reset cell value, formula settings, and inline string
332*cdf0e10cSrcweir         maCellValue = OUString();
333*cdf0e10cSrcweir         mxInlineStr.reset();
334*cdf0e10cSrcweir         mbHasFormula = false;
335*cdf0e10cSrcweir 
336*cdf0e10cSrcweir         // update used area of the sheet
337*cdf0e10cSrcweir         extendUsedArea( maCellData.maCellAddr );
338*cdf0e10cSrcweir     }
339*cdf0e10cSrcweir     return bValidAddr;
340*cdf0e10cSrcweir }
341*cdf0e10cSrcweir 
342*cdf0e10cSrcweir void SheetDataContext::importFormula( const AttributeList& rAttribs )
343*cdf0e10cSrcweir {
344*cdf0e10cSrcweir     mbHasFormula = true;
345*cdf0e10cSrcweir     mbValidRange = mrAddressConv.convertToCellRange( maFmlaData.maFormulaRef, rAttribs.getString( XML_ref, OUString() ), mnSheet, true, true );
346*cdf0e10cSrcweir 
347*cdf0e10cSrcweir     maFmlaData.mnFormulaType = rAttribs.getToken( XML_t, XML_normal );
348*cdf0e10cSrcweir     maFmlaData.mnSharedId    = rAttribs.getInteger( XML_si, -1 );
349*cdf0e10cSrcweir 
350*cdf0e10cSrcweir     if( maFmlaData.mnFormulaType == XML_dataTable )
351*cdf0e10cSrcweir     {
352*cdf0e10cSrcweir         maTableData.maRef1        = rAttribs.getString( XML_r1, OUString() );
353*cdf0e10cSrcweir         maTableData.maRef2        = rAttribs.getString( XML_r2, OUString() );
354*cdf0e10cSrcweir         maTableData.mb2dTable     = rAttribs.getBool( XML_dt2D, false );
355*cdf0e10cSrcweir         maTableData.mbRowTable    = rAttribs.getBool( XML_dtr, false );
356*cdf0e10cSrcweir         maTableData.mbRef1Deleted = rAttribs.getBool( XML_del1, false );
357*cdf0e10cSrcweir         maTableData.mbRef2Deleted = rAttribs.getBool( XML_del2, false );
358*cdf0e10cSrcweir     }
359*cdf0e10cSrcweir 
360*cdf0e10cSrcweir     // clear token array, will be regenerated from element text
361*cdf0e10cSrcweir     maTokens = ApiTokenSequence();
362*cdf0e10cSrcweir }
363*cdf0e10cSrcweir 
364*cdf0e10cSrcweir void SheetDataContext::importRow( SequenceInputStream& rStrm )
365*cdf0e10cSrcweir {
366*cdf0e10cSrcweir     RowModel aModel;
367*cdf0e10cSrcweir     sal_Int32 nSpanCount;
368*cdf0e10cSrcweir     sal_uInt16 nHeight, nFlags1;
369*cdf0e10cSrcweir     sal_uInt8 nFlags2;
370*cdf0e10cSrcweir     rStrm >> maCurrPos.mnRow >> aModel.mnXfId >> nHeight >> nFlags1 >> nFlags2 >> nSpanCount;
371*cdf0e10cSrcweir     maCurrPos.mnCol = 0;
372*cdf0e10cSrcweir 
373*cdf0e10cSrcweir     // row index is 0-based in BIFF12, but RowModel expects 1-based
374*cdf0e10cSrcweir     aModel.mnRow          = maCurrPos.mnRow + 1;
375*cdf0e10cSrcweir     // row height is in twips in BIFF12, convert to points
376*cdf0e10cSrcweir     aModel.mfHeight       = nHeight / 20.0;
377*cdf0e10cSrcweir     aModel.mnLevel        = extractValue< sal_Int32 >( nFlags1, 8, 3 );
378*cdf0e10cSrcweir     aModel.mbCustomHeight = getFlag( nFlags1, BIFF12_ROW_CUSTOMHEIGHT );
379*cdf0e10cSrcweir     aModel.mbCustomFormat = getFlag( nFlags1, BIFF12_ROW_CUSTOMFORMAT );
380*cdf0e10cSrcweir     aModel.mbShowPhonetic = getFlag( nFlags2, BIFF12_ROW_SHOWPHONETIC );
381*cdf0e10cSrcweir     aModel.mbHidden       = getFlag( nFlags1, BIFF12_ROW_HIDDEN );
382*cdf0e10cSrcweir     aModel.mbCollapsed    = getFlag( nFlags1, BIFF12_ROW_COLLAPSED );
383*cdf0e10cSrcweir     aModel.mbThickTop     = getFlag( nFlags1, BIFF12_ROW_THICKTOP );
384*cdf0e10cSrcweir     aModel.mbThickBottom  = getFlag( nFlags1, BIFF12_ROW_THICKBOTTOM );
385*cdf0e10cSrcweir 
386*cdf0e10cSrcweir     // read the column spans
387*cdf0e10cSrcweir     sal_Int32 nMaxCol = mrAddressConv.getMaxApiAddress().Column;
388*cdf0e10cSrcweir     for( sal_Int32 nSpanIdx = 0; (nSpanIdx < nSpanCount) && !rStrm.isEof(); ++nSpanIdx )
389*cdf0e10cSrcweir     {
390*cdf0e10cSrcweir         sal_Int32 nFirstCol, nLastCol;
391*cdf0e10cSrcweir         rStrm >> nFirstCol >> nLastCol;
392*cdf0e10cSrcweir         aModel.insertColSpan( ValueRange( nFirstCol, ::std::min( nLastCol, nMaxCol ) ) );
393*cdf0e10cSrcweir     }
394*cdf0e10cSrcweir 
395*cdf0e10cSrcweir     // set row properties in the current sheet
396*cdf0e10cSrcweir     setRowModel( aModel );
397*cdf0e10cSrcweir }
398*cdf0e10cSrcweir 
399*cdf0e10cSrcweir bool SheetDataContext::readCellHeader( SequenceInputStream& rStrm, CellType eCellType )
400*cdf0e10cSrcweir {
401*cdf0e10cSrcweir     switch( eCellType )
402*cdf0e10cSrcweir     {
403*cdf0e10cSrcweir         case CELLTYPE_VALUE:
404*cdf0e10cSrcweir         case CELLTYPE_FORMULA:  rStrm >> maCurrPos.mnCol;   break;
405*cdf0e10cSrcweir         case CELLTYPE_MULTI:    ++maCurrPos.mnCol;          break;
406*cdf0e10cSrcweir     }
407*cdf0e10cSrcweir 
408*cdf0e10cSrcweir     sal_uInt32 nXfId;
409*cdf0e10cSrcweir     rStrm >> nXfId;
410*cdf0e10cSrcweir 
411*cdf0e10cSrcweir     bool bValidAddr = mrAddressConv.convertToCellAddress( maCellData.maCellAddr, maCurrPos, mnSheet, true );
412*cdf0e10cSrcweir     maCellData.mnXfId = extractValue< sal_Int32 >( nXfId, 0, 24 );
413*cdf0e10cSrcweir     maCellData.mbShowPhonetic = getFlag( nXfId, BIFF12_CELL_SHOWPHONETIC );
414*cdf0e10cSrcweir 
415*cdf0e10cSrcweir     // update used area of the sheet
416*cdf0e10cSrcweir     if( bValidAddr )
417*cdf0e10cSrcweir         extendUsedArea( maCellData.maCellAddr );
418*cdf0e10cSrcweir     return bValidAddr;
419*cdf0e10cSrcweir }
420*cdf0e10cSrcweir 
421*cdf0e10cSrcweir ApiTokenSequence SheetDataContext::readCellFormula( SequenceInputStream& rStrm )
422*cdf0e10cSrcweir {
423*cdf0e10cSrcweir     rStrm.skip( 2 );
424*cdf0e10cSrcweir     return mrFormulaParser.importFormula( maCellData.maCellAddr, FORMULATYPE_CELL, rStrm );
425*cdf0e10cSrcweir }
426*cdf0e10cSrcweir 
427*cdf0e10cSrcweir bool SheetDataContext::readFormulaRef( SequenceInputStream& rStrm )
428*cdf0e10cSrcweir {
429*cdf0e10cSrcweir     BinRange aRange;
430*cdf0e10cSrcweir     rStrm >> aRange;
431*cdf0e10cSrcweir     return mrAddressConv.convertToCellRange( maFmlaData.maFormulaRef, aRange, mnSheet, true, true );
432*cdf0e10cSrcweir }
433*cdf0e10cSrcweir 
434*cdf0e10cSrcweir void SheetDataContext::importCellBool( SequenceInputStream& rStrm, CellType eCellType )
435*cdf0e10cSrcweir {
436*cdf0e10cSrcweir     if( readCellHeader( rStrm, eCellType ) )
437*cdf0e10cSrcweir     {
438*cdf0e10cSrcweir         maCellData.mnCellType = XML_b;
439*cdf0e10cSrcweir         bool bValue = rStrm.readuInt8() != 0;
440*cdf0e10cSrcweir         if( eCellType == CELLTYPE_FORMULA )
441*cdf0e10cSrcweir             mrSheetData.setFormulaCell( maCellData, readCellFormula( rStrm ) );
442*cdf0e10cSrcweir         else
443*cdf0e10cSrcweir             mrSheetData.setBooleanCell( maCellData, bValue );
444*cdf0e10cSrcweir     }
445*cdf0e10cSrcweir }
446*cdf0e10cSrcweir 
447*cdf0e10cSrcweir void SheetDataContext::importCellBlank( SequenceInputStream& rStrm, CellType eCellType )
448*cdf0e10cSrcweir {
449*cdf0e10cSrcweir     OSL_ENSURE( eCellType != CELLTYPE_FORMULA, "SheetDataContext::importCellBlank - no formula cells supported" );
450*cdf0e10cSrcweir     if( readCellHeader( rStrm, eCellType ) )
451*cdf0e10cSrcweir         mrSheetData.setBlankCell( maCellData );
452*cdf0e10cSrcweir }
453*cdf0e10cSrcweir 
454*cdf0e10cSrcweir void SheetDataContext::importCellDouble( SequenceInputStream& rStrm, CellType eCellType )
455*cdf0e10cSrcweir {
456*cdf0e10cSrcweir     if( readCellHeader( rStrm, eCellType ) )
457*cdf0e10cSrcweir     {
458*cdf0e10cSrcweir         maCellData.mnCellType = XML_n;
459*cdf0e10cSrcweir         double fValue = rStrm.readDouble();
460*cdf0e10cSrcweir         if( eCellType == CELLTYPE_FORMULA )
461*cdf0e10cSrcweir             mrSheetData.setFormulaCell( maCellData, readCellFormula( rStrm ) );
462*cdf0e10cSrcweir         else
463*cdf0e10cSrcweir             mrSheetData.setValueCell( maCellData, fValue );
464*cdf0e10cSrcweir     }
465*cdf0e10cSrcweir }
466*cdf0e10cSrcweir 
467*cdf0e10cSrcweir void SheetDataContext::importCellError( SequenceInputStream& rStrm, CellType eCellType )
468*cdf0e10cSrcweir {
469*cdf0e10cSrcweir     if( readCellHeader( rStrm, eCellType ) )
470*cdf0e10cSrcweir     {
471*cdf0e10cSrcweir         maCellData.mnCellType = XML_e;
472*cdf0e10cSrcweir         sal_uInt8 nErrorCode = rStrm.readuInt8();
473*cdf0e10cSrcweir         if( eCellType == CELLTYPE_FORMULA )
474*cdf0e10cSrcweir             mrSheetData.setFormulaCell( maCellData, readCellFormula( rStrm ) );
475*cdf0e10cSrcweir         else
476*cdf0e10cSrcweir             mrSheetData.setErrorCell( maCellData, nErrorCode );
477*cdf0e10cSrcweir     }
478*cdf0e10cSrcweir }
479*cdf0e10cSrcweir 
480*cdf0e10cSrcweir void SheetDataContext::importCellRk( SequenceInputStream& rStrm, CellType eCellType )
481*cdf0e10cSrcweir {
482*cdf0e10cSrcweir     OSL_ENSURE( eCellType != CELLTYPE_FORMULA, "SheetDataContext::importCellRk - no formula cells supported" );
483*cdf0e10cSrcweir     if( readCellHeader( rStrm, eCellType ) )
484*cdf0e10cSrcweir     {
485*cdf0e10cSrcweir         maCellData.mnCellType = XML_n;
486*cdf0e10cSrcweir         mrSheetData.setValueCell( maCellData, BiffHelper::calcDoubleFromRk( rStrm.readInt32() ) );
487*cdf0e10cSrcweir     }
488*cdf0e10cSrcweir }
489*cdf0e10cSrcweir 
490*cdf0e10cSrcweir void SheetDataContext::importCellRString( SequenceInputStream& rStrm, CellType eCellType )
491*cdf0e10cSrcweir {
492*cdf0e10cSrcweir     OSL_ENSURE( eCellType != CELLTYPE_FORMULA, "SheetDataContext::importCellRString - no formula cells supported" );
493*cdf0e10cSrcweir     if( readCellHeader( rStrm, eCellType ) )
494*cdf0e10cSrcweir     {
495*cdf0e10cSrcweir         maCellData.mnCellType = XML_inlineStr;
496*cdf0e10cSrcweir         RichStringRef xString( new RichString( *this ) );
497*cdf0e10cSrcweir         xString->importString( rStrm, true );
498*cdf0e10cSrcweir         xString->finalizeImport();
499*cdf0e10cSrcweir         mrSheetData.setStringCell( maCellData, xString );
500*cdf0e10cSrcweir     }
501*cdf0e10cSrcweir }
502*cdf0e10cSrcweir 
503*cdf0e10cSrcweir void SheetDataContext::importCellSi( SequenceInputStream& rStrm, CellType eCellType )
504*cdf0e10cSrcweir {
505*cdf0e10cSrcweir     OSL_ENSURE( eCellType != CELLTYPE_FORMULA, "SheetDataContext::importCellSi - no formula cells supported" );
506*cdf0e10cSrcweir     if( readCellHeader( rStrm, eCellType ) )
507*cdf0e10cSrcweir     {
508*cdf0e10cSrcweir         maCellData.mnCellType = XML_s;
509*cdf0e10cSrcweir         mrSheetData.setStringCell( maCellData, rStrm.readInt32() );
510*cdf0e10cSrcweir     }
511*cdf0e10cSrcweir }
512*cdf0e10cSrcweir 
513*cdf0e10cSrcweir void SheetDataContext::importCellString( SequenceInputStream& rStrm, CellType eCellType )
514*cdf0e10cSrcweir {
515*cdf0e10cSrcweir     if( readCellHeader( rStrm, eCellType ) )
516*cdf0e10cSrcweir     {
517*cdf0e10cSrcweir         maCellData.mnCellType = XML_inlineStr;
518*cdf0e10cSrcweir         // always import the string, stream will point to formula afterwards, if existing
519*cdf0e10cSrcweir         RichStringRef xString( new RichString( *this ) );
520*cdf0e10cSrcweir         xString->importString( rStrm, false );
521*cdf0e10cSrcweir         xString->finalizeImport();
522*cdf0e10cSrcweir         if( eCellType == CELLTYPE_FORMULA )
523*cdf0e10cSrcweir             mrSheetData.setFormulaCell( maCellData, readCellFormula( rStrm ) );
524*cdf0e10cSrcweir         else
525*cdf0e10cSrcweir             mrSheetData.setStringCell( maCellData, xString );
526*cdf0e10cSrcweir     }
527*cdf0e10cSrcweir }
528*cdf0e10cSrcweir 
529*cdf0e10cSrcweir void SheetDataContext::importArray( SequenceInputStream& rStrm )
530*cdf0e10cSrcweir {
531*cdf0e10cSrcweir     if( readFormulaRef( rStrm ) && maFmlaData.isValidArrayRef( maCellData.maCellAddr ) )
532*cdf0e10cSrcweir     {
533*cdf0e10cSrcweir         rStrm.skip( 1 );
534*cdf0e10cSrcweir         ApiTokenSequence aTokens = mrFormulaParser.importFormula( maCellData.maCellAddr, FORMULATYPE_ARRAY, rStrm );
535*cdf0e10cSrcweir         mrSheetData.createArrayFormula( maFmlaData.maFormulaRef, aTokens );
536*cdf0e10cSrcweir     }
537*cdf0e10cSrcweir }
538*cdf0e10cSrcweir 
539*cdf0e10cSrcweir void SheetDataContext::importDataTable( SequenceInputStream& rStrm )
540*cdf0e10cSrcweir {
541*cdf0e10cSrcweir     if( readFormulaRef( rStrm ) )
542*cdf0e10cSrcweir     {
543*cdf0e10cSrcweir         BinAddress aRef1, aRef2;
544*cdf0e10cSrcweir         sal_uInt8 nFlags;
545*cdf0e10cSrcweir         rStrm >> aRef1 >> aRef2 >> nFlags;
546*cdf0e10cSrcweir         maTableData.maRef1        = FormulaProcessorBase::generateAddress2dString( aRef1, false );
547*cdf0e10cSrcweir         maTableData.maRef2        = FormulaProcessorBase::generateAddress2dString( aRef2, false );
548*cdf0e10cSrcweir         maTableData.mbRowTable    = getFlag( nFlags, BIFF12_DATATABLE_ROW );
549*cdf0e10cSrcweir         maTableData.mb2dTable     = getFlag( nFlags, BIFF12_DATATABLE_2D );
550*cdf0e10cSrcweir         maTableData.mbRef1Deleted = getFlag( nFlags, BIFF12_DATATABLE_REF1DEL );
551*cdf0e10cSrcweir         maTableData.mbRef2Deleted = getFlag( nFlags, BIFF12_DATATABLE_REF2DEL );
552*cdf0e10cSrcweir         mrSheetData.createTableOperation( maFmlaData.maFormulaRef, maTableData );
553*cdf0e10cSrcweir     }
554*cdf0e10cSrcweir }
555*cdf0e10cSrcweir 
556*cdf0e10cSrcweir void SheetDataContext::importSharedFmla( SequenceInputStream& rStrm )
557*cdf0e10cSrcweir {
558*cdf0e10cSrcweir     if( readFormulaRef( rStrm ) && maFmlaData.isValidSharedRef( maCellData.maCellAddr ) )
559*cdf0e10cSrcweir     {
560*cdf0e10cSrcweir         ApiTokenSequence aTokens = mrFormulaParser.importFormula( maCellData.maCellAddr, FORMULATYPE_SHAREDFORMULA, rStrm );
561*cdf0e10cSrcweir         mrSheetData.createSharedFormula( maCellData.maCellAddr, aTokens );
562*cdf0e10cSrcweir     }
563*cdf0e10cSrcweir }
564*cdf0e10cSrcweir 
565*cdf0e10cSrcweir // ============================================================================
566*cdf0e10cSrcweir 
567*cdf0e10cSrcweir BiffSheetDataContext::BiffSheetDataContext( const WorksheetHelper& rHelper ) :
568*cdf0e10cSrcweir     BiffWorksheetContextBase( rHelper ),
569*cdf0e10cSrcweir     SheetDataContextBase( rHelper ),
570*cdf0e10cSrcweir     mnBiff2XfId( 0 )
571*cdf0e10cSrcweir {
572*cdf0e10cSrcweir     switch( getBiff() )
573*cdf0e10cSrcweir     {
574*cdf0e10cSrcweir         case BIFF2:
575*cdf0e10cSrcweir             mnFormulaSkipSize = 9;  // double formula result, 1 byte flags
576*cdf0e10cSrcweir             mnArraySkipSize = 1;    // recalc-always flag
577*cdf0e10cSrcweir         break;
578*cdf0e10cSrcweir         case BIFF3:
579*cdf0e10cSrcweir         case BIFF4:
580*cdf0e10cSrcweir             mnFormulaSkipSize = 10; // double formula result, 2 byte flags
581*cdf0e10cSrcweir             mnArraySkipSize = 2;    // 2 byte flags
582*cdf0e10cSrcweir         break;
583*cdf0e10cSrcweir         case BIFF5:
584*cdf0e10cSrcweir         case BIFF8:
585*cdf0e10cSrcweir             mnFormulaSkipSize = 14; // double formula result, 2 byte flags, 4 bytes nothing
586*cdf0e10cSrcweir             mnArraySkipSize = 6;    // 2 byte flags, 4 bytes nothing
587*cdf0e10cSrcweir         break;
588*cdf0e10cSrcweir         case BIFF_UNKNOWN:
589*cdf0e10cSrcweir         break;
590*cdf0e10cSrcweir     }
591*cdf0e10cSrcweir }
592*cdf0e10cSrcweir 
593*cdf0e10cSrcweir void BiffSheetDataContext::importRecord( BiffInputStream& rStrm )
594*cdf0e10cSrcweir {
595*cdf0e10cSrcweir     sal_uInt16 nRecId = rStrm.getRecId();
596*cdf0e10cSrcweir     switch( nRecId )
597*cdf0e10cSrcweir     {
598*cdf0e10cSrcweir         // records in all BIFF versions
599*cdf0e10cSrcweir         case BIFF2_ID_ARRAY:        // #i72713#
600*cdf0e10cSrcweir         case BIFF3_ID_ARRAY:        importArray( rStrm );   break;
601*cdf0e10cSrcweir         case BIFF2_ID_BLANK:
602*cdf0e10cSrcweir         case BIFF3_ID_BLANK:        importBlank( rStrm );   break;
603*cdf0e10cSrcweir         case BIFF2_ID_BOOLERR:
604*cdf0e10cSrcweir         case BIFF3_ID_BOOLERR:      importBoolErr( rStrm ); break;
605*cdf0e10cSrcweir         case BIFF2_ID_INTEGER:      importInteger( rStrm ); break;
606*cdf0e10cSrcweir         case BIFF_ID_IXFE:          rStrm >> mnBiff2XfId;   break;
607*cdf0e10cSrcweir         case BIFF2_ID_LABEL:
608*cdf0e10cSrcweir         case BIFF3_ID_LABEL:        importLabel( rStrm );   break;
609*cdf0e10cSrcweir         case BIFF2_ID_NUMBER:
610*cdf0e10cSrcweir         case BIFF3_ID_NUMBER:       importNumber( rStrm );  break;
611*cdf0e10cSrcweir         case BIFF_ID_RK:            importRk( rStrm );      break;
612*cdf0e10cSrcweir 
613*cdf0e10cSrcweir         // BIFF specific records
614*cdf0e10cSrcweir         default: switch( getBiff() )
615*cdf0e10cSrcweir         {
616*cdf0e10cSrcweir             case BIFF2: switch( nRecId )
617*cdf0e10cSrcweir             {
618*cdf0e10cSrcweir                 case BIFF2_ID_DATATABLE:    importDataTable( rStrm );   break;
619*cdf0e10cSrcweir                 case BIFF2_ID_DATATABLE2:   importDataTable( rStrm );   break;
620*cdf0e10cSrcweir                 case BIFF2_ID_FORMULA:      importFormula( rStrm );     break;
621*cdf0e10cSrcweir                 case BIFF2_ID_ROW:          importRow( rStrm );         break;
622*cdf0e10cSrcweir             }
623*cdf0e10cSrcweir             break;
624*cdf0e10cSrcweir 
625*cdf0e10cSrcweir             case BIFF3: switch( nRecId )
626*cdf0e10cSrcweir             {
627*cdf0e10cSrcweir                 case BIFF3_ID_DATATABLE:    importDataTable( rStrm );   break;
628*cdf0e10cSrcweir                 case BIFF3_ID_FORMULA:      importFormula( rStrm );     break;
629*cdf0e10cSrcweir                 case BIFF3_ID_ROW:          importRow( rStrm );         break;
630*cdf0e10cSrcweir             }
631*cdf0e10cSrcweir             break;
632*cdf0e10cSrcweir 
633*cdf0e10cSrcweir             case BIFF4: switch( nRecId )
634*cdf0e10cSrcweir             {
635*cdf0e10cSrcweir                 case BIFF3_ID_DATATABLE:    importDataTable( rStrm );   break;
636*cdf0e10cSrcweir                 case BIFF4_ID_FORMULA:      importFormula( rStrm );     break;
637*cdf0e10cSrcweir                 case BIFF3_ID_ROW:          importRow( rStrm );         break;
638*cdf0e10cSrcweir             }
639*cdf0e10cSrcweir             break;
640*cdf0e10cSrcweir 
641*cdf0e10cSrcweir             case BIFF5: switch( nRecId )
642*cdf0e10cSrcweir             {
643*cdf0e10cSrcweir                 case BIFF3_ID_DATATABLE:    importDataTable( rStrm );   break;
644*cdf0e10cSrcweir                 case BIFF3_ID_FORMULA:
645*cdf0e10cSrcweir                 case BIFF4_ID_FORMULA:
646*cdf0e10cSrcweir                 case BIFF5_ID_FORMULA:      importFormula( rStrm );     break;
647*cdf0e10cSrcweir                 case BIFF_ID_MULTBLANK:     importMultBlank( rStrm );   break;
648*cdf0e10cSrcweir                 case BIFF_ID_MULTRK:        importMultRk( rStrm );      break;
649*cdf0e10cSrcweir                 case BIFF3_ID_ROW:          importRow( rStrm );         break;
650*cdf0e10cSrcweir                 case BIFF_ID_RSTRING:       importLabel( rStrm );       break;
651*cdf0e10cSrcweir                 case BIFF_ID_SHAREDFMLA:    importSharedFmla( rStrm );  break;
652*cdf0e10cSrcweir             }
653*cdf0e10cSrcweir             break;
654*cdf0e10cSrcweir 
655*cdf0e10cSrcweir             case BIFF8: switch( nRecId )
656*cdf0e10cSrcweir             {
657*cdf0e10cSrcweir                 case BIFF3_ID_DATATABLE:    importDataTable( rStrm );   break;
658*cdf0e10cSrcweir                 case BIFF3_ID_FORMULA:
659*cdf0e10cSrcweir                 case BIFF4_ID_FORMULA:
660*cdf0e10cSrcweir                 case BIFF5_ID_FORMULA:      importFormula( rStrm );     break;
661*cdf0e10cSrcweir                 case BIFF_ID_LABELSST:      importLabelSst( rStrm );    break;
662*cdf0e10cSrcweir                 case BIFF_ID_MULTBLANK:     importMultBlank( rStrm );   break;
663*cdf0e10cSrcweir                 case BIFF_ID_MULTRK:        importMultRk( rStrm );      break;
664*cdf0e10cSrcweir                 case BIFF3_ID_ROW:          importRow( rStrm );         break;
665*cdf0e10cSrcweir                 case BIFF_ID_RSTRING:       importLabel( rStrm );       break;
666*cdf0e10cSrcweir                 case BIFF_ID_SHAREDFMLA:    importSharedFmla( rStrm );  break;
667*cdf0e10cSrcweir             }
668*cdf0e10cSrcweir             break;
669*cdf0e10cSrcweir 
670*cdf0e10cSrcweir             case BIFF_UNKNOWN:
671*cdf0e10cSrcweir             break;
672*cdf0e10cSrcweir         }
673*cdf0e10cSrcweir     }
674*cdf0e10cSrcweir }
675*cdf0e10cSrcweir 
676*cdf0e10cSrcweir // private --------------------------------------------------------------------
677*cdf0e10cSrcweir 
678*cdf0e10cSrcweir void BiffSheetDataContext::importRow( BiffInputStream& rStrm )
679*cdf0e10cSrcweir {
680*cdf0e10cSrcweir     RowModel aModel;
681*cdf0e10cSrcweir     sal_uInt16 nRow, nFirstUsedCol, nFirstFreeCol, nHeight;
682*cdf0e10cSrcweir     rStrm >> nRow >> nFirstUsedCol >> nFirstFreeCol >> nHeight;
683*cdf0e10cSrcweir     if( getBiff() == BIFF2 )
684*cdf0e10cSrcweir     {
685*cdf0e10cSrcweir         rStrm.skip( 2 );
686*cdf0e10cSrcweir         aModel.mbCustomFormat = rStrm.readuInt8() == BIFF2_ROW_CUSTOMFORMAT;
687*cdf0e10cSrcweir         if( aModel.mbCustomFormat )
688*cdf0e10cSrcweir         {
689*cdf0e10cSrcweir             rStrm.skip( 5 );
690*cdf0e10cSrcweir             aModel.mnXfId = rStrm.readuInt16();
691*cdf0e10cSrcweir         }
692*cdf0e10cSrcweir     }
693*cdf0e10cSrcweir     else
694*cdf0e10cSrcweir     {
695*cdf0e10cSrcweir         rStrm.skip( 4 );
696*cdf0e10cSrcweir         sal_uInt32 nFlags = rStrm.readuInt32();
697*cdf0e10cSrcweir         aModel.mnXfId         = extractValue< sal_Int32 >( nFlags, 16, 12 );
698*cdf0e10cSrcweir         aModel.mnLevel        = extractValue< sal_Int32 >( nFlags, 0, 3 );
699*cdf0e10cSrcweir         aModel.mbCustomFormat = getFlag( nFlags, BIFF_ROW_CUSTOMFORMAT );
700*cdf0e10cSrcweir         aModel.mbCustomHeight = getFlag( nFlags, BIFF_ROW_CUSTOMHEIGHT );
701*cdf0e10cSrcweir         aModel.mbShowPhonetic = getFlag( nFlags, BIFF_ROW_SHOWPHONETIC );
702*cdf0e10cSrcweir         aModel.mbHidden       = getFlag( nFlags, BIFF_ROW_HIDDEN );
703*cdf0e10cSrcweir         aModel.mbCollapsed    = getFlag( nFlags, BIFF_ROW_COLLAPSED );
704*cdf0e10cSrcweir         aModel.mbThickTop     = getFlag( nFlags, BIFF_ROW_THICKTOP );
705*cdf0e10cSrcweir         aModel.mbThickBottom  = getFlag( nFlags, BIFF_ROW_THICKBOTTOM );
706*cdf0e10cSrcweir     }
707*cdf0e10cSrcweir 
708*cdf0e10cSrcweir     // row index is 0-based in BIFF, but RowModel expects 1-based
709*cdf0e10cSrcweir     aModel.mnRow = static_cast< sal_Int32 >( nRow ) + 1;
710*cdf0e10cSrcweir     // row height is in twips in BIFF, convert to points
711*cdf0e10cSrcweir     aModel.mfHeight = (nHeight & BIFF_ROW_HEIGHTMASK) / 20.0;
712*cdf0e10cSrcweir     // set column spans
713*cdf0e10cSrcweir     if( nFirstUsedCol < nFirstFreeCol )
714*cdf0e10cSrcweir     {
715*cdf0e10cSrcweir         sal_Int32 nLastCol = ::std::min< sal_Int32 >( nFirstFreeCol - 1, mrAddressConv.getMaxApiAddress().Column );
716*cdf0e10cSrcweir         aModel.insertColSpan( ValueRange( nFirstUsedCol, nLastCol ) );
717*cdf0e10cSrcweir     }
718*cdf0e10cSrcweir 
719*cdf0e10cSrcweir     // set row properties in the current sheet
720*cdf0e10cSrcweir     setRowModel( aModel );
721*cdf0e10cSrcweir }
722*cdf0e10cSrcweir 
723*cdf0e10cSrcweir bool BiffSheetDataContext::readCellXfId( BiffInputStream& rStrm, const BinAddress& rAddr, bool bBiff2 )
724*cdf0e10cSrcweir {
725*cdf0e10cSrcweir     bool bValidAddr = mrAddressConv.convertToCellAddress( maCellData.maCellAddr, rAddr, mnSheet, true );
726*cdf0e10cSrcweir     if( bValidAddr )
727*cdf0e10cSrcweir     {
728*cdf0e10cSrcweir         // update used area of the sheet
729*cdf0e10cSrcweir         extendUsedArea( maCellData.maCellAddr );
730*cdf0e10cSrcweir 
731*cdf0e10cSrcweir         // load the XF identifier according to current BIFF version
732*cdf0e10cSrcweir         if( bBiff2 )
733*cdf0e10cSrcweir         {
734*cdf0e10cSrcweir             /*  #i71453# On first call, check if the file contains XF records
735*cdf0e10cSrcweir                 (by trying to access the first XF with index 0). If there are
736*cdf0e10cSrcweir                 no XFs, the explicit formatting information contained in each
737*cdf0e10cSrcweir                 cell record will be used instead. */
738*cdf0e10cSrcweir             if( !mobBiff2HasXfs )
739*cdf0e10cSrcweir                 mobBiff2HasXfs = getStyles().getCellXf( 0 ).get() != 0;
740*cdf0e10cSrcweir             // read formatting information (includes the XF identifier)
741*cdf0e10cSrcweir             sal_uInt8 nFlags1, nFlags2, nFlags3;
742*cdf0e10cSrcweir             rStrm >> nFlags1 >> nFlags2 >> nFlags3;
743*cdf0e10cSrcweir             /*  If the file contains XFs, extract and set the XF identifier,
744*cdf0e10cSrcweir                 otherwise get the explicit formatting. */
745*cdf0e10cSrcweir             if( mobBiff2HasXfs.get() )
746*cdf0e10cSrcweir             {
747*cdf0e10cSrcweir                 maCellData.mnXfId = extractValue< sal_Int32 >( nFlags1, 0, 6 );
748*cdf0e10cSrcweir                 /*  If the identifier is equal to 63, then the real identifier
749*cdf0e10cSrcweir                     is contained in the preceding IXFE record (stored in the
750*cdf0e10cSrcweir                     class member mnBiff2XfId). */
751*cdf0e10cSrcweir                 if( maCellData.mnXfId == BIFF2_CELL_USEIXFE )
752*cdf0e10cSrcweir                     maCellData.mnXfId = mnBiff2XfId;
753*cdf0e10cSrcweir             }
754*cdf0e10cSrcweir             else
755*cdf0e10cSrcweir             {
756*cdf0e10cSrcweir                 /*  Let the Xf class do the API conversion. Keeping the member
757*cdf0e10cSrcweir                     maCellData.mnXfId untouched will prevent to trigger the
758*cdf0e10cSrcweir                     usual XF formatting conversion later on. */
759*cdf0e10cSrcweir                 PropertySet aPropSet( getCell( maCellData.maCellAddr ) );
760*cdf0e10cSrcweir                 Xf::writeBiff2CellFormatToPropertySet( *this, aPropSet, nFlags1, nFlags2, nFlags3 );
761*cdf0e10cSrcweir             }
762*cdf0e10cSrcweir         }
763*cdf0e10cSrcweir         else
764*cdf0e10cSrcweir         {
765*cdf0e10cSrcweir             // BIFF3-BIFF8: 16-bit XF identifier
766*cdf0e10cSrcweir             maCellData.mnXfId = rStrm.readuInt16();
767*cdf0e10cSrcweir         }
768*cdf0e10cSrcweir     }
769*cdf0e10cSrcweir     return bValidAddr;
770*cdf0e10cSrcweir }
771*cdf0e10cSrcweir 
772*cdf0e10cSrcweir bool BiffSheetDataContext::readCellHeader( BiffInputStream& rStrm, bool bBiff2 )
773*cdf0e10cSrcweir {
774*cdf0e10cSrcweir     BinAddress aAddr;
775*cdf0e10cSrcweir     rStrm >> aAddr;
776*cdf0e10cSrcweir     return readCellXfId( rStrm, aAddr, bBiff2 );
777*cdf0e10cSrcweir }
778*cdf0e10cSrcweir 
779*cdf0e10cSrcweir bool BiffSheetDataContext::readFormulaRef( BiffInputStream& rStrm )
780*cdf0e10cSrcweir {
781*cdf0e10cSrcweir     BinRange aRange;
782*cdf0e10cSrcweir     aRange.read( rStrm, false );    // columns always 8-bit
783*cdf0e10cSrcweir     return mrAddressConv.convertToCellRange( maFmlaData.maFormulaRef, aRange, mnSheet, true, true );
784*cdf0e10cSrcweir }
785*cdf0e10cSrcweir 
786*cdf0e10cSrcweir void BiffSheetDataContext::importBlank( BiffInputStream& rStrm )
787*cdf0e10cSrcweir {
788*cdf0e10cSrcweir     if( readCellHeader( rStrm, rStrm.getRecId() == BIFF2_ID_BLANK ) )
789*cdf0e10cSrcweir         mrSheetData.setBlankCell( maCellData );
790*cdf0e10cSrcweir }
791*cdf0e10cSrcweir 
792*cdf0e10cSrcweir void BiffSheetDataContext::importBoolErr( BiffInputStream& rStrm )
793*cdf0e10cSrcweir {
794*cdf0e10cSrcweir     if( readCellHeader( rStrm, rStrm.getRecId() == BIFF2_ID_BOOLERR ) )
795*cdf0e10cSrcweir     {
796*cdf0e10cSrcweir         sal_uInt8 nValue, nType;
797*cdf0e10cSrcweir         rStrm >> nValue >> nType;
798*cdf0e10cSrcweir         switch( nType )
799*cdf0e10cSrcweir         {
800*cdf0e10cSrcweir             case BIFF_BOOLERR_BOOL:
801*cdf0e10cSrcweir                 maCellData.mnCellType = XML_b;
802*cdf0e10cSrcweir                 mrSheetData.setBooleanCell( maCellData, nValue != 0 );
803*cdf0e10cSrcweir             break;
804*cdf0e10cSrcweir             case BIFF_BOOLERR_ERROR:
805*cdf0e10cSrcweir                 maCellData.mnCellType = XML_e;
806*cdf0e10cSrcweir                 mrSheetData.setErrorCell( maCellData, nValue );
807*cdf0e10cSrcweir             break;
808*cdf0e10cSrcweir             default:
809*cdf0e10cSrcweir                 OSL_ENSURE( false, "BiffSheetDataContext::importBoolErr - unknown cell type" );
810*cdf0e10cSrcweir                 maCellData.mnCellType = XML_TOKEN_INVALID;
811*cdf0e10cSrcweir                 mrSheetData.setBlankCell( maCellData );
812*cdf0e10cSrcweir         }
813*cdf0e10cSrcweir     }
814*cdf0e10cSrcweir }
815*cdf0e10cSrcweir 
816*cdf0e10cSrcweir void BiffSheetDataContext::importFormula( BiffInputStream& rStrm )
817*cdf0e10cSrcweir {
818*cdf0e10cSrcweir     if( readCellHeader( rStrm, getBiff() == BIFF2 ) )
819*cdf0e10cSrcweir     {
820*cdf0e10cSrcweir         maCellData.mnCellType = XML_n;
821*cdf0e10cSrcweir         rStrm.skip( mnFormulaSkipSize );
822*cdf0e10cSrcweir         ApiTokenSequence aTokens = mrFormulaParser.importFormula( maCellData.maCellAddr, FORMULATYPE_CELL, rStrm );
823*cdf0e10cSrcweir         mrSheetData.setFormulaCell( maCellData, aTokens );
824*cdf0e10cSrcweir     }
825*cdf0e10cSrcweir }
826*cdf0e10cSrcweir 
827*cdf0e10cSrcweir void BiffSheetDataContext::importInteger( BiffInputStream& rStrm )
828*cdf0e10cSrcweir {
829*cdf0e10cSrcweir     if( readCellHeader( rStrm, true ) )
830*cdf0e10cSrcweir     {
831*cdf0e10cSrcweir         maCellData.mnCellType = XML_n;
832*cdf0e10cSrcweir         mrSheetData.setValueCell( maCellData, rStrm.readuInt16() );
833*cdf0e10cSrcweir     }
834*cdf0e10cSrcweir }
835*cdf0e10cSrcweir 
836*cdf0e10cSrcweir void BiffSheetDataContext::importLabel( BiffInputStream& rStrm )
837*cdf0e10cSrcweir {
838*cdf0e10cSrcweir     /*  the deep secrets of BIFF type and record identifier...
839*cdf0e10cSrcweir         record id   BIFF    ->  XF type     String type
840*cdf0e10cSrcweir         0x0004      2-7     ->  3 byte      8-bit length, byte string
841*cdf0e10cSrcweir         0x0004      8       ->  3 byte      16-bit length, unicode string
842*cdf0e10cSrcweir         0x0204      2-7     ->  2 byte      16-bit length, byte string
843*cdf0e10cSrcweir         0x0204      8       ->  2 byte      16-bit length, unicode string
844*cdf0e10cSrcweir      */
845*cdf0e10cSrcweir     bool bBiff2Xf = rStrm.getRecId() == BIFF2_ID_LABEL;
846*cdf0e10cSrcweir     if( readCellHeader( rStrm, bBiff2Xf ) )
847*cdf0e10cSrcweir     {
848*cdf0e10cSrcweir         maCellData.mnCellType = XML_inlineStr;
849*cdf0e10cSrcweir         if( getBiff() == BIFF8 )
850*cdf0e10cSrcweir         {
851*cdf0e10cSrcweir             // string may contain rich-text formatting
852*cdf0e10cSrcweir             RichStringRef xString( new RichString( *this ) );
853*cdf0e10cSrcweir             xString->importUniString( rStrm );
854*cdf0e10cSrcweir             xString->finalizeImport();
855*cdf0e10cSrcweir             mrSheetData.setStringCell( maCellData, xString );
856*cdf0e10cSrcweir         }
857*cdf0e10cSrcweir         else
858*cdf0e10cSrcweir         {
859*cdf0e10cSrcweir             // #i63105# use text encoding from FONT record
860*cdf0e10cSrcweir             rtl_TextEncoding eTextEnc = getTextEncoding();
861*cdf0e10cSrcweir             if( const Font* pFont = getStyles().getFontFromCellXf( maCellData.mnXfId ).get() )
862*cdf0e10cSrcweir                 eTextEnc = pFont->getFontEncoding();
863*cdf0e10cSrcweir             // RSTRING record contains rich-text formatting
864*cdf0e10cSrcweir             if( rStrm.getRecId() == BIFF_ID_RSTRING )
865*cdf0e10cSrcweir             {
866*cdf0e10cSrcweir                 BiffStringFlags nFlags = BIFF_STR_EXTRAFONTS;
867*cdf0e10cSrcweir                 // BIFF2 record identifier: 8-bit string length (see above)
868*cdf0e10cSrcweir                 setFlag( nFlags, BIFF_STR_8BITLENGTH, bBiff2Xf );
869*cdf0e10cSrcweir                 RichStringRef xString( new RichString( *this ) );
870*cdf0e10cSrcweir                 xString->importByteString( rStrm, eTextEnc, nFlags );
871*cdf0e10cSrcweir                 xString->finalizeImport();
872*cdf0e10cSrcweir                 mrSheetData.setStringCell( maCellData, xString );
873*cdf0e10cSrcweir             }
874*cdf0e10cSrcweir             else
875*cdf0e10cSrcweir             {
876*cdf0e10cSrcweir                 // BIFF2 record identifier: 8-bit string length (see above)
877*cdf0e10cSrcweir                 OUString aText = rStrm.readByteStringUC( !bBiff2Xf, eTextEnc );
878*cdf0e10cSrcweir                 mrSheetData.setStringCell( maCellData, aText );
879*cdf0e10cSrcweir             }
880*cdf0e10cSrcweir         }
881*cdf0e10cSrcweir     }
882*cdf0e10cSrcweir }
883*cdf0e10cSrcweir 
884*cdf0e10cSrcweir void BiffSheetDataContext::importLabelSst( BiffInputStream& rStrm )
885*cdf0e10cSrcweir {
886*cdf0e10cSrcweir     if( readCellHeader( rStrm, false ) )
887*cdf0e10cSrcweir     {
888*cdf0e10cSrcweir         maCellData.mnCellType = XML_s;
889*cdf0e10cSrcweir         mrSheetData.setStringCell( maCellData, rStrm.readInt32() );
890*cdf0e10cSrcweir     }
891*cdf0e10cSrcweir }
892*cdf0e10cSrcweir 
893*cdf0e10cSrcweir void BiffSheetDataContext::importMultBlank( BiffInputStream& rStrm )
894*cdf0e10cSrcweir {
895*cdf0e10cSrcweir     BinAddress aAddr;
896*cdf0e10cSrcweir     bool bValidAddr = true;
897*cdf0e10cSrcweir     for( rStrm >> aAddr; bValidAddr && (rStrm.getRemaining() > 2); ++aAddr.mnCol )
898*cdf0e10cSrcweir         if( (bValidAddr = readCellXfId( rStrm, aAddr, false )) == true )
899*cdf0e10cSrcweir             mrSheetData.setBlankCell( maCellData );
900*cdf0e10cSrcweir }
901*cdf0e10cSrcweir 
902*cdf0e10cSrcweir void BiffSheetDataContext::importMultRk( BiffInputStream& rStrm )
903*cdf0e10cSrcweir {
904*cdf0e10cSrcweir     BinAddress aAddr;
905*cdf0e10cSrcweir     bool bValidAddr = true;
906*cdf0e10cSrcweir     for( rStrm >> aAddr; bValidAddr && (rStrm.getRemaining() > 2); ++aAddr.mnCol )
907*cdf0e10cSrcweir     {
908*cdf0e10cSrcweir         if( (bValidAddr = readCellXfId( rStrm, aAddr, false )) == true )
909*cdf0e10cSrcweir         {
910*cdf0e10cSrcweir             maCellData.mnCellType = XML_n;
911*cdf0e10cSrcweir             sal_Int32 nRkValue = rStrm.readInt32();
912*cdf0e10cSrcweir             mrSheetData.setValueCell( maCellData, BiffHelper::calcDoubleFromRk( nRkValue ) );
913*cdf0e10cSrcweir         }
914*cdf0e10cSrcweir     }
915*cdf0e10cSrcweir }
916*cdf0e10cSrcweir 
917*cdf0e10cSrcweir void BiffSheetDataContext::importNumber( BiffInputStream& rStrm )
918*cdf0e10cSrcweir {
919*cdf0e10cSrcweir     if( readCellHeader( rStrm, rStrm.getRecId() == BIFF2_ID_NUMBER ) )
920*cdf0e10cSrcweir     {
921*cdf0e10cSrcweir         maCellData.mnCellType = XML_n;
922*cdf0e10cSrcweir         mrSheetData.setValueCell( maCellData, rStrm.readDouble() );
923*cdf0e10cSrcweir     }
924*cdf0e10cSrcweir }
925*cdf0e10cSrcweir 
926*cdf0e10cSrcweir void BiffSheetDataContext::importRk( BiffInputStream& rStrm )
927*cdf0e10cSrcweir {
928*cdf0e10cSrcweir     if( readCellHeader( rStrm, false ) )
929*cdf0e10cSrcweir     {
930*cdf0e10cSrcweir         maCellData.mnCellType = XML_n;
931*cdf0e10cSrcweir         mrSheetData.setValueCell( maCellData, BiffHelper::calcDoubleFromRk( rStrm.readInt32() ) );
932*cdf0e10cSrcweir     }
933*cdf0e10cSrcweir }
934*cdf0e10cSrcweir 
935*cdf0e10cSrcweir void BiffSheetDataContext::importArray( BiffInputStream& rStrm )
936*cdf0e10cSrcweir {
937*cdf0e10cSrcweir     if( readFormulaRef( rStrm ) && maFmlaData.isValidArrayRef( maCellData.maCellAddr ) )
938*cdf0e10cSrcweir     {
939*cdf0e10cSrcweir         rStrm.skip( mnArraySkipSize );
940*cdf0e10cSrcweir         ApiTokenSequence aTokens = mrFormulaParser.importFormula( maCellData.maCellAddr, FORMULATYPE_ARRAY, rStrm );
941*cdf0e10cSrcweir         mrSheetData.createArrayFormula( maFmlaData.maFormulaRef, aTokens );
942*cdf0e10cSrcweir     }
943*cdf0e10cSrcweir }
944*cdf0e10cSrcweir 
945*cdf0e10cSrcweir void BiffSheetDataContext::importDataTable( BiffInputStream& rStrm )
946*cdf0e10cSrcweir {
947*cdf0e10cSrcweir     if( readFormulaRef( rStrm ) )
948*cdf0e10cSrcweir     {
949*cdf0e10cSrcweir         DataTableModel aModel;
950*cdf0e10cSrcweir         BinAddress aRef1, aRef2;
951*cdf0e10cSrcweir         switch( rStrm.getRecId() )
952*cdf0e10cSrcweir         {
953*cdf0e10cSrcweir             case BIFF2_ID_DATATABLE:
954*cdf0e10cSrcweir                 rStrm.skip( 1 );
955*cdf0e10cSrcweir                 aModel.mbRowTable = rStrm.readuInt8() != 0;
956*cdf0e10cSrcweir                 aModel.mb2dTable = false;
957*cdf0e10cSrcweir                 rStrm >> aRef1;
958*cdf0e10cSrcweir             break;
959*cdf0e10cSrcweir             case BIFF2_ID_DATATABLE2:
960*cdf0e10cSrcweir                 rStrm.skip( 2 );
961*cdf0e10cSrcweir                 aModel.mb2dTable = true;
962*cdf0e10cSrcweir                 rStrm >> aRef1 >> aRef2;
963*cdf0e10cSrcweir             break;
964*cdf0e10cSrcweir             case BIFF3_ID_DATATABLE:
965*cdf0e10cSrcweir             {
966*cdf0e10cSrcweir                 sal_uInt16 nFlags;
967*cdf0e10cSrcweir                 rStrm >> nFlags >> aRef1 >> aRef2;
968*cdf0e10cSrcweir                 aModel.mbRowTable = getFlag( nFlags, BIFF_DATATABLE_ROW );
969*cdf0e10cSrcweir                 aModel.mb2dTable = getFlag( nFlags, BIFF_DATATABLE_2D );
970*cdf0e10cSrcweir                 aModel.mbRef1Deleted = getFlag( nFlags, BIFF_DATATABLE_REF1DEL );
971*cdf0e10cSrcweir                 aModel.mbRef2Deleted = getFlag( nFlags, BIFF_DATATABLE_REF2DEL );
972*cdf0e10cSrcweir             }
973*cdf0e10cSrcweir             break;
974*cdf0e10cSrcweir             default:
975*cdf0e10cSrcweir                 OSL_ENSURE( false, "BiffSheetDataContext::importDataTable - unknown record id" );
976*cdf0e10cSrcweir         }
977*cdf0e10cSrcweir         aModel.maRef1 = FormulaProcessorBase::generateAddress2dString( aRef1, false );
978*cdf0e10cSrcweir         aModel.maRef2 = FormulaProcessorBase::generateAddress2dString( aRef2, false );
979*cdf0e10cSrcweir         mrSheetData.createTableOperation( maFmlaData.maFormulaRef, aModel );
980*cdf0e10cSrcweir     }
981*cdf0e10cSrcweir }
982*cdf0e10cSrcweir 
983*cdf0e10cSrcweir void BiffSheetDataContext::importSharedFmla( BiffInputStream& rStrm )
984*cdf0e10cSrcweir {
985*cdf0e10cSrcweir     if( readFormulaRef( rStrm ) && maFmlaData.isValidSharedRef( maCellData.maCellAddr ) )
986*cdf0e10cSrcweir     {
987*cdf0e10cSrcweir         rStrm.skip( 2 );    // flags
988*cdf0e10cSrcweir         ApiTokenSequence aTokens = mrFormulaParser.importFormula( maCellData.maCellAddr, FORMULATYPE_SHAREDFORMULA, rStrm );
989*cdf0e10cSrcweir         mrSheetData.createSharedFormula( maCellData.maCellAddr, aTokens );
990*cdf0e10cSrcweir     }
991*cdf0e10cSrcweir }
992*cdf0e10cSrcweir 
993*cdf0e10cSrcweir // ============================================================================
994*cdf0e10cSrcweir 
995*cdf0e10cSrcweir } // namespace xls
996*cdf0e10cSrcweir } // namespace oox
997