Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <stdlib.h>
21 :
22 : #include "document.hxx"
23 : #include "scerrors.hxx"
24 : #include "fprogressbar.hxx"
25 : #include "xltracer.hxx"
26 : #include "xltable.hxx"
27 : #include "xihelper.hxx"
28 : #include "xipage.hxx"
29 : #include "xiview.hxx"
30 : #include "xilink.hxx"
31 : #include "xiname.hxx"
32 : #include "xicontent.hxx"
33 : #include "xiescher.hxx"
34 : #include "xipivot.hxx"
35 : #include "XclImpChangeTrack.hxx"
36 : #include "documentimport.hxx"
37 :
38 : #include "root.hxx"
39 : #include "imp_op.hxx"
40 : #include "excimp8.hxx"
41 :
42 : #include <boost/scoped_ptr.hpp>
43 :
44 3 : FltError ImportExcel::Read()
45 : {
46 3 : XclImpPageSettings& rPageSett = GetPageSettings();
47 3 : XclImpTabViewSettings& rTabViewSett = GetTabViewSettings();
48 3 : XclImpPalette& rPal = GetPalette();
49 3 : XclImpFontBuffer& rFontBfr = GetFontBuffer();
50 3 : XclImpNumFmtBuffer& rNumFmtBfr = GetNumFmtBuffer();
51 3 : XclImpXFBuffer& rXFBfr = GetXFBuffer();
52 3 : XclImpNameManager& rNameMgr = GetNameManager();
53 3 : XclImpObjectManager& rObjMgr = GetObjectManager();
54 : (void)rObjMgr;
55 : // call to GetCurrSheetDrawing() cannot be cached (changes in new sheets)
56 :
57 : enum Zustand {
58 : Z_BiffNull, // not a valid Biff-Format
59 : Z_Biff2, // Biff2: only one table
60 :
61 : Z_Biff3, // Biff3: only one table
62 :
63 : Z_Biff4, // Biff4: only one table
64 : Z_Biff4W, // Biff4 Workbook: Globals
65 : Z_Biff4T, // Biff4 Workbook: a table itself
66 : Z_Biff4E, // Biff4 Workbook: between tables
67 :
68 : Z_Biff5WPre,// Biff5: Prefetch Workbook
69 : Z_Biff5W, // Biff5: Globals
70 : Z_Biff5TPre,// Biff5: Prefetch for Shrfmla/Array Formula
71 : Z_Biff5T, // Biff5: a table itself
72 : Z_Biff5E, // Biff5: between tables
73 : Z_Biffn0, // all Biffs: skip table till next EOF
74 : Z_Ende };
75 :
76 3 : Zustand eAkt = Z_BiffNull, ePrev = Z_BiffNull;
77 :
78 3 : FltError eLastErr = eERR_OK;
79 : sal_uInt16 nOpcode;
80 3 : sal_uInt16 nBofLevel = 0;
81 :
82 : OSL_ENSURE( &aIn != NULL, "-ImportExcel::Read(): No Stream - what happened?!" );
83 :
84 : boost::scoped_ptr< ScfSimpleProgressBar > pProgress( new ScfSimpleProgressBar(
85 3 : aIn.GetSvStreamSize(), GetDocShell(), STR_LOAD_DOC ) );
86 :
87 : /* #i104057# Need to track a base position for progress bar calculation,
88 : because sheet substreams may not be in order of sheets. */
89 3 : sal_Size nProgressBasePos = 0;
90 3 : sal_Size nProgressBaseSize = 0;
91 :
92 5200 : for (; eAkt != Z_Ende; mnLastRecId = nOpcode)
93 : {
94 5200 : if( eAkt == Z_Biff5E )
95 : {
96 9 : sal_uInt16 nScTab = GetCurrScTab();
97 9 : if( nScTab < maSheetOffsets.size() )
98 : {
99 6 : nProgressBaseSize += (aIn.GetSvStreamPos() - nProgressBasePos);
100 6 : nProgressBasePos = maSheetOffsets[ nScTab ];
101 6 : aIn.StartNextRecord( nProgressBasePos );
102 : }
103 : else
104 3 : eAkt = Z_Ende;
105 : }
106 : else
107 5191 : aIn.StartNextRecord();
108 :
109 5200 : nOpcode = aIn.GetRecId();
110 :
111 5200 : if( !aIn.IsValid() )
112 : {
113 : // finalize table if EOF is missing
114 0 : switch( eAkt )
115 : {
116 : case Z_Biff2:
117 : case Z_Biff3:
118 : case Z_Biff4:
119 : case Z_Biff4T:
120 : case Z_Biff5TPre:
121 : case Z_Biff5T:
122 0 : rNumFmtBfr.CreateScFormats();
123 0 : Eof();
124 0 : break;
125 : default:;
126 : }
127 0 : eAkt = Z_Ende;
128 0 : break;
129 : }
130 :
131 5200 : if( eAkt == Z_Ende )
132 3 : break;
133 :
134 5197 : if( eAkt != Z_Biff5TPre && eAkt != Z_Biff5WPre )
135 2486 : pProgress->ProgressAbs( nProgressBaseSize + aIn.GetSvStreamPos() - nProgressBasePos );
136 :
137 5197 : switch( eAkt )
138 : {
139 :
140 : case Z_BiffNull: // ------------------------------- Z_BiffNull -
141 : {
142 3 : switch( nOpcode )
143 : {
144 : case EXC_ID2_BOF:
145 : case EXC_ID3_BOF:
146 : case EXC_ID4_BOF:
147 : case EXC_ID5_BOF:
148 : {
149 : // #i23425# don't rely on the record ID, but on the detected BIFF version
150 3 : switch( GetBiff() )
151 : {
152 : case EXC_BIFF2:
153 0 : Bof2();
154 0 : if( pExcRoot->eDateiTyp == Biff2 )
155 : {
156 0 : eAkt = Z_Biff2;
157 0 : NewTable();
158 : }
159 0 : break;
160 : case EXC_BIFF3:
161 0 : Bof3();
162 0 : if( pExcRoot->eDateiTyp == Biff3 )
163 : {
164 0 : eAkt = Z_Biff3;
165 0 : NewTable();
166 : }
167 0 : break;
168 : case EXC_BIFF4:
169 0 : Bof4();
170 0 : if( pExcRoot->eDateiTyp == Biff4 )
171 : {
172 0 : eAkt = Z_Biff4;
173 0 : NewTable();
174 : }
175 0 : else if( pExcRoot->eDateiTyp == Biff4W )
176 0 : eAkt = Z_Biff4W;
177 0 : break;
178 : case EXC_BIFF5:
179 3 : Bof5();
180 3 : if( pExcRoot->eDateiTyp == Biff5W )
181 : {
182 3 : eAkt = Z_Biff5WPre;
183 :
184 3 : nBdshtTab = 0;
185 :
186 3 : aIn.StoreGlobalPosition(); // store position
187 : }
188 0 : else if( pExcRoot->eDateiTyp == Biff5 )
189 : {
190 : // #i62752# possible to have BIFF5 sheet without globals
191 0 : NewTable();
192 0 : eAkt = Z_Biff5TPre; // Shrfmla Prefetch, Row-Prefetch
193 0 : nBofLevel = 0;
194 0 : aIn.StoreGlobalPosition(); // store position
195 : }
196 3 : break;
197 : default:
198 : DBG_ERROR_BIFF();
199 : }
200 : }
201 3 : break;
202 : }
203 : }
204 3 : break;
205 :
206 : case Z_Biff2: // ---------------------------------- Z_Biff2 -
207 : {
208 0 : switch( nOpcode )
209 : {
210 : case EXC_ID2_DIMENSIONS:
211 0 : case EXC_ID3_DIMENSIONS: ReadDimensions(); break;
212 : case EXC_ID2_BLANK:
213 0 : case EXC_ID3_BLANK: ReadBlank(); break;
214 0 : case EXC_ID2_INTEGER: ReadInteger(); break;
215 : case EXC_ID2_NUMBER:
216 0 : case EXC_ID3_NUMBER: ReadNumber(); break;
217 : case EXC_ID2_LABEL:
218 0 : case EXC_ID3_LABEL: ReadLabel(); break;
219 : case EXC_ID2_BOOLERR:
220 0 : case EXC_ID3_BOOLERR: ReadBoolErr(); break;
221 0 : case EXC_ID_RK: ReadRk(); break;
222 :
223 0 : case 0x06: Formula25(); break; // FORMULA [ 2 5]
224 0 : case 0x08: Row25(); break; // ROW [ 2 5]
225 : case 0x0A: // EOF [ 2345]
226 0 : rNumFmtBfr.CreateScFormats();
227 0 : rNameMgr.ConvertAllTokens();
228 0 : Eof();
229 0 : eAkt = Z_Ende;
230 0 : break;
231 : case 0x14:
232 0 : case 0x15: rPageSett.ReadHeaderFooter( maStrm ); break;
233 0 : case 0x17: Externsheet(); break; // EXTERNSHEET [ 2345]
234 0 : case 0x18: rNameMgr.ReadName( maStrm ); break;
235 0 : case 0x1C: GetCurrSheetDrawing().ReadNote( maStrm );break;
236 0 : case 0x1D: rTabViewSett.ReadSelection( maStrm ); break;
237 0 : case 0x1E: rNumFmtBfr.ReadFormat( maStrm ); break;
238 0 : case 0x20: Columndefault(); break; // COLUMNDEFAULT[ 2 ]
239 0 : case 0x21: Array25(); break; // ARRAY [ 2 5]
240 0 : case 0x23: Externname25(); break; // EXTERNNAME [ 2 5]
241 0 : case 0x24: Colwidth(); break; // COLWIDTH [ 2 ]
242 0 : case 0x25: Defrowheight2(); break; // DEFAULTROWHEI[ 2 ]
243 : case 0x26:
244 : case 0x27:
245 : case 0x28:
246 0 : case 0x29: rPageSett.ReadMargin( maStrm ); break;
247 0 : case 0x2A: rPageSett.ReadPrintHeaders( maStrm ); break;
248 0 : case 0x2B: rPageSett.ReadPrintGridLines( maStrm ); break;
249 : case 0x2F: // FILEPASS [ 2345]
250 0 : eLastErr = XclImpDecryptHelper::ReadFilepass( maStrm );
251 0 : if( eLastErr != ERRCODE_NONE )
252 0 : eAkt = Z_Ende;
253 0 : break;
254 0 : case EXC_ID2_FONT: rFontBfr.ReadFont( maStrm ); break;
255 0 : case EXC_ID_EFONT: rFontBfr.ReadEfont( maStrm ); break;
256 0 : case 0x3E: rTabViewSett.ReadWindow2( maStrm, false );break;
257 0 : case 0x41: rTabViewSett.ReadPane( maStrm ); break;
258 0 : case 0x42: Codepage(); break; // CODEPAGE [ 2345]
259 0 : case 0x43: rXFBfr.ReadXF( maStrm ); break;
260 0 : case 0x44: Ixfe(); break; // IXFE [ 2 ]
261 : }
262 : }
263 0 : break;
264 :
265 : case Z_Biff3: // ---------------------------------- Z_Biff3 -
266 : {
267 0 : switch( nOpcode )
268 : {
269 : // skip chart substream
270 : case EXC_ID2_BOF:
271 : case EXC_ID3_BOF:
272 : case EXC_ID4_BOF:
273 0 : case EXC_ID5_BOF: XclTools::SkipSubStream( maStrm ); break;
274 :
275 : case EXC_ID2_DIMENSIONS:
276 0 : case EXC_ID3_DIMENSIONS: ReadDimensions(); break;
277 : case EXC_ID2_BLANK:
278 0 : case EXC_ID3_BLANK: ReadBlank(); break;
279 0 : case EXC_ID2_INTEGER: ReadInteger(); break;
280 : case EXC_ID2_NUMBER:
281 0 : case EXC_ID3_NUMBER: ReadNumber(); break;
282 : case EXC_ID2_LABEL:
283 0 : case EXC_ID3_LABEL: ReadLabel(); break;
284 : case EXC_ID2_BOOLERR:
285 0 : case EXC_ID3_BOOLERR: ReadBoolErr(); break;
286 0 : case EXC_ID_RK: ReadRk(); break;
287 :
288 : case 0x0A: // EOF [ 2345]
289 0 : rNumFmtBfr.CreateScFormats();
290 0 : rNameMgr.ConvertAllTokens();
291 0 : Eof();
292 0 : eAkt = Z_Ende;
293 0 : break;
294 : case 0x14:
295 0 : case 0x15: rPageSett.ReadHeaderFooter( maStrm ); break;
296 0 : case 0x17: Externsheet(); break; // EXTERNSHEET [ 2345]
297 : case 0x1A:
298 0 : case 0x1B: rPageSett.ReadPageBreaks( maStrm ); break;
299 0 : case 0x1C: GetCurrSheetDrawing().ReadNote( maStrm );break;
300 0 : case 0x1D: rTabViewSett.ReadSelection( maStrm ); break;
301 0 : case 0x1E: rNumFmtBfr.ReadFormat( maStrm ); break;
302 0 : case 0x22: Rec1904(); break; // 1904 [ 2345]
303 : case 0x26:
304 : case 0x27:
305 : case 0x28:
306 0 : case 0x29: rPageSett.ReadMargin( maStrm ); break;
307 0 : case 0x2A: rPageSett.ReadPrintHeaders( maStrm ); break;
308 0 : case 0x2B: rPageSett.ReadPrintGridLines( maStrm ); break;
309 : case 0x2F: // FILEPASS [ 2345]
310 0 : eLastErr = XclImpDecryptHelper::ReadFilepass( maStrm );
311 0 : if( eLastErr != ERRCODE_NONE )
312 0 : eAkt = Z_Ende;
313 0 : break;
314 0 : case EXC_ID_FILESHARING: ReadFileSharing(); break;
315 0 : case 0x41: rTabViewSett.ReadPane( maStrm ); break;
316 0 : case 0x42: Codepage(); break; // CODEPAGE [ 2345]
317 0 : case 0x56: break; // BUILTINFMTCNT[ 34 ]
318 0 : case 0x5D: GetCurrSheetDrawing().ReadObj( maStrm );break;
319 0 : case 0x7D: Colinfo(); break; // COLINFO [ 345]
320 0 : case 0x8C: Country(); break; // COUNTRY [ 345]
321 0 : case 0x92: rPal.ReadPalette( maStrm ); break;
322 0 : case 0x0206: Formula3(); break; // FORMULA [ 3 ]
323 0 : case 0x0208: Row34(); break; // ROW [ 34 ]
324 0 : case 0x0218: rNameMgr.ReadName( maStrm ); break;
325 0 : case 0x0221: Array34(); break; // ARRAY [ 34 ]
326 0 : case 0x0223: break; // EXTERNNAME [ 34 ]
327 0 : case 0x0225: Defrowheight345();break;//DEFAULTROWHEI[ 345]
328 0 : case 0x0231: rFontBfr.ReadFont( maStrm ); break;
329 0 : case 0x023E: rTabViewSett.ReadWindow2( maStrm, false );break;
330 0 : case 0x0243: rXFBfr.ReadXF( maStrm ); break;
331 0 : case 0x0293: rXFBfr.ReadStyle( maStrm ); break;
332 : }
333 : }
334 0 : break;
335 :
336 : case Z_Biff4: // ---------------------------------- Z_Biff4 -
337 : {
338 0 : switch( nOpcode )
339 : {
340 : // skip chart substream
341 : case EXC_ID2_BOF:
342 : case EXC_ID3_BOF:
343 : case EXC_ID4_BOF:
344 0 : case EXC_ID5_BOF: XclTools::SkipSubStream( maStrm ); break;
345 :
346 : case EXC_ID2_DIMENSIONS:
347 0 : case EXC_ID3_DIMENSIONS: ReadDimensions(); break;
348 : case EXC_ID2_BLANK:
349 0 : case EXC_ID3_BLANK: ReadBlank(); break;
350 0 : case EXC_ID2_INTEGER: ReadInteger(); break;
351 : case EXC_ID2_NUMBER:
352 0 : case EXC_ID3_NUMBER: ReadNumber(); break;
353 : case EXC_ID2_LABEL:
354 0 : case EXC_ID3_LABEL: ReadLabel(); break;
355 : case EXC_ID2_BOOLERR:
356 0 : case EXC_ID3_BOOLERR: ReadBoolErr(); break;
357 0 : case EXC_ID_RK: ReadRk(); break;
358 :
359 : case 0x0A: // EOF [ 2345]
360 0 : rNumFmtBfr.CreateScFormats();
361 0 : rNameMgr.ConvertAllTokens();
362 0 : Eof();
363 0 : eAkt = Z_Ende;
364 0 : break;
365 0 : case 0x12: SheetProtect(); break; // SHEET PROTECTION
366 : case 0x14:
367 0 : case 0x15: rPageSett.ReadHeaderFooter( maStrm ); break;
368 0 : case 0x17: Externsheet(); break; // EXTERNSHEET [ 2345]
369 : case 0x1A:
370 0 : case 0x1B: rPageSett.ReadPageBreaks( maStrm ); break;
371 0 : case 0x1C: GetCurrSheetDrawing().ReadNote( maStrm );break;
372 0 : case 0x1D: rTabViewSett.ReadSelection( maStrm ); break;
373 0 : case 0x22: Rec1904(); break; // 1904 [ 2345]
374 : case 0x26:
375 : case 0x27:
376 : case 0x28:
377 0 : case 0x29: rPageSett.ReadMargin( maStrm ); break;
378 0 : case 0x2A: rPageSett.ReadPrintHeaders( maStrm ); break;
379 0 : case 0x2B: rPageSett.ReadPrintGridLines( maStrm ); break;
380 : case 0x2F: // FILEPASS [ 2345]
381 0 : eLastErr = XclImpDecryptHelper::ReadFilepass( maStrm );
382 0 : if( eLastErr != ERRCODE_NONE )
383 0 : eAkt = Z_Ende;
384 0 : break;
385 0 : case EXC_ID_FILESHARING: ReadFileSharing(); break;
386 0 : case 0x41: rTabViewSett.ReadPane( maStrm ); break;
387 0 : case 0x42: Codepage(); break; // CODEPAGE [ 2345]
388 0 : case 0x55: DefColWidth(); break;
389 0 : case 0x56: break; // BUILTINFMTCNT[ 34 ]
390 0 : case 0x5D: GetCurrSheetDrawing().ReadObj( maStrm );break;
391 0 : case 0x7D: Colinfo(); break; // COLINFO [ 345]
392 0 : case 0x8C: Country(); break; // COUNTRY [ 345]
393 0 : case 0x92: rPal.ReadPalette( maStrm ); break;
394 0 : case 0x99: Standardwidth(); break; // STANDARDWIDTH[ 45]
395 0 : case 0xA1: rPageSett.ReadSetup( maStrm ); break;
396 0 : case 0x0208: Row34(); break; // ROW [ 34 ]
397 0 : case 0x0218: rNameMgr.ReadName( maStrm ); break;
398 0 : case 0x0221: Array34(); break; // ARRAY [ 34 ]
399 0 : case 0x0223: break; // EXTERNNAME [ 34 ]
400 0 : case 0x0225: Defrowheight345();break;//DEFAULTROWHEI[ 345]
401 0 : case 0x0231: rFontBfr.ReadFont( maStrm ); break;
402 0 : case 0x023E: rTabViewSett.ReadWindow2( maStrm, false );break;
403 0 : case 0x0406: Formula4(); break; // FORMULA [ 4 ]
404 0 : case 0x041E: rNumFmtBfr.ReadFormat( maStrm ); break;
405 0 : case 0x0443: rXFBfr.ReadXF( maStrm ); break;
406 0 : case 0x0293: rXFBfr.ReadStyle( maStrm ); break;
407 : }
408 : }
409 0 : break;
410 :
411 : case Z_Biff4W: // --------------------------------- Z_Biff4W -
412 : {
413 0 : switch( nOpcode )
414 : {
415 : case 0x0A: // EOF [ 2345]
416 0 : rNameMgr.ConvertAllTokens();
417 0 : eAkt = Z_Ende;
418 0 : break;
419 0 : case 0x12: DocProtect(); break; // PROTECT [ 5]
420 : case 0x2F: // FILEPASS [ 2345]
421 0 : eLastErr = XclImpDecryptHelper::ReadFilepass( maStrm );
422 0 : if( eLastErr != ERRCODE_NONE )
423 0 : eAkt = Z_Ende;
424 0 : break;
425 0 : case EXC_ID_FILESHARING: ReadFileSharing(); break;
426 0 : case 0x17: Externsheet(); break; // EXTERNSHEET [ 2345]
427 0 : case 0x42: Codepage(); break; // CODEPAGE [ 2345]
428 0 : case 0x55: DefColWidth(); break;
429 0 : case 0x56: break; // BUILTINFMTCNT[ 34 ]
430 0 : case 0x8C: Country(); break; // COUNTRY [ 345]
431 0 : case 0x8F: break; // BUNDLEHEADER [ 4 ]
432 0 : case 0x92: rPal.ReadPalette( maStrm ); break;
433 0 : case 0x99: Standardwidth(); break; // STANDARDWIDTH[ 45]
434 0 : case 0x0218: rNameMgr.ReadName( maStrm ); break;
435 0 : case 0x0223: break; // EXTERNNAME [ 34 ]
436 0 : case 0x0225: Defrowheight345();break;//DEFAULTROWHEI[ 345]
437 0 : case 0x0231: rFontBfr.ReadFont( maStrm ); break;
438 : case 0x0409: // BOF [ 4 ]
439 0 : Bof4();
440 0 : if( pExcRoot->eDateiTyp == Biff4 )
441 : {
442 0 : eAkt = Z_Biff4T;
443 0 : NewTable();
444 : }
445 : else
446 0 : eAkt = Z_Ende;
447 0 : break;
448 0 : case 0x041E: rNumFmtBfr.ReadFormat( maStrm ); break;
449 0 : case 0x0443: rXFBfr.ReadXF( maStrm ); break;
450 0 : case 0x0293: rXFBfr.ReadStyle( maStrm ); break;
451 : }
452 :
453 : }
454 0 : break;
455 :
456 : case Z_Biff4T: // --------------------------------- Z_Biff4T -
457 : {
458 0 : switch( nOpcode )
459 : {
460 : // skip chart substream
461 : case EXC_ID2_BOF:
462 : case EXC_ID3_BOF:
463 : case EXC_ID4_BOF:
464 0 : case EXC_ID5_BOF: XclTools::SkipSubStream( maStrm ); break;
465 :
466 : case EXC_ID2_DIMENSIONS:
467 0 : case EXC_ID3_DIMENSIONS: ReadDimensions(); break;
468 : case EXC_ID2_BLANK:
469 0 : case EXC_ID3_BLANK: ReadBlank(); break;
470 0 : case EXC_ID2_INTEGER: ReadInteger(); break;
471 : case EXC_ID2_NUMBER:
472 0 : case EXC_ID3_NUMBER: ReadNumber(); break;
473 : case EXC_ID2_LABEL:
474 0 : case EXC_ID3_LABEL: ReadLabel(); break;
475 : case EXC_ID2_BOOLERR:
476 0 : case EXC_ID3_BOOLERR: ReadBoolErr(); break;
477 0 : case EXC_ID_RK: ReadRk(); break;
478 :
479 : case 0x0A: // EOF [ 2345]
480 0 : rNameMgr.ConvertAllTokens();
481 0 : Eof();
482 0 : eAkt = Z_Biff4E;
483 0 : break;
484 0 : case 0x12: SheetProtect(); break; // SHEET PROTECTION
485 : case 0x14:
486 0 : case 0x15: rPageSett.ReadHeaderFooter( maStrm ); break;
487 : case 0x1A:
488 0 : case 0x1B: rPageSett.ReadPageBreaks( maStrm ); break;
489 0 : case 0x1C: GetCurrSheetDrawing().ReadNote( maStrm );break;
490 0 : case 0x1D: rTabViewSett.ReadSelection( maStrm ); break;
491 : case 0x2F: // FILEPASS [ 2345]
492 0 : eLastErr = XclImpDecryptHelper::ReadFilepass( maStrm );
493 0 : if( eLastErr != ERRCODE_NONE )
494 0 : eAkt = Z_Ende;
495 0 : break;
496 0 : case 0x41: rTabViewSett.ReadPane( maStrm ); break;
497 0 : case 0x42: Codepage(); break; // CODEPAGE [ 2345]
498 0 : case 0x55: DefColWidth(); break;
499 0 : case 0x56: break; // BUILTINFMTCNT[ 34 ]
500 0 : case 0x5D: GetCurrSheetDrawing().ReadObj( maStrm );break;
501 0 : case 0x7D: Colinfo(); break; // COLINFO [ 345]
502 0 : case 0x8C: Country(); break; // COUNTRY [ 345]
503 0 : case 0x8F: break; // BUNDLEHEADER [ 4 ]
504 0 : case 0x92: rPal.ReadPalette( maStrm ); break;
505 0 : case 0x99: Standardwidth(); break; // STANDARDWIDTH[ 45]
506 0 : case 0xA1: rPageSett.ReadSetup( maStrm ); break;
507 0 : case 0x0208: Row34(); break; // ROW [ 34 ]
508 0 : case 0x0218: rNameMgr.ReadName( maStrm ); break;
509 0 : case 0x0221: Array34(); break;
510 0 : case 0x0225: Defrowheight345();break;//DEFAULTROWHEI[ 345]
511 0 : case 0x0231: rFontBfr.ReadFont( maStrm ); break;
512 0 : case 0x023E: rTabViewSett.ReadWindow2( maStrm, false );break;
513 0 : case 0x0406: Formula4(); break;
514 0 : case 0x041E: rNumFmtBfr.ReadFormat( maStrm ); break;
515 0 : case 0x0443: rXFBfr.ReadXF( maStrm ); break;
516 0 : case 0x0293: rXFBfr.ReadStyle( maStrm ); break;
517 : }
518 :
519 : }
520 0 : break;
521 :
522 : case Z_Biff4E: // --------------------------------- Z_Biff4E -
523 : {
524 0 : switch( nOpcode )
525 : {
526 : case 0x0A: // EOF [ 2345]
527 0 : eAkt = Z_Ende;
528 0 : break;
529 0 : case 0x8F: break; // BUNDLEHEADER [ 4 ]
530 : case 0x0409: // BOF [ 4 ]
531 0 : Bof4();
532 0 : NewTable();
533 0 : if( pExcRoot->eDateiTyp == Biff4 )
534 : {
535 0 : eAkt = Z_Biff4T;
536 : }
537 : else
538 : {
539 0 : ePrev = eAkt;
540 0 : eAkt = Z_Biffn0;
541 : }
542 0 : break;
543 : }
544 :
545 : }
546 0 : break;
547 : case Z_Biff5WPre: // ------------------------------ Z_Biff5WPre -
548 : {
549 327 : switch( nOpcode )
550 : {
551 : case 0x0A: // EOF [ 2345]
552 3 : eAkt = Z_Biff5W;
553 3 : aIn.SeekGlobalPosition(); // und zurueck an alte Position
554 3 : break;
555 3 : case 0x12: DocProtect(); break; // PROTECT [ 5]
556 : case 0x2F: // FILEPASS [ 2345]
557 0 : eLastErr = XclImpDecryptHelper::ReadFilepass( maStrm );
558 0 : if( eLastErr != ERRCODE_NONE )
559 0 : eAkt = Z_Ende;
560 0 : break;
561 0 : case EXC_ID_FILESHARING: ReadFileSharing(); break;
562 3 : case 0x3D: Window1(); break;
563 3 : case 0x42: Codepage(); break; // CODEPAGE [ 2345]
564 6 : case 0x85: Boundsheet(); break; // BOUNDSHEET [ 5]
565 0 : case 0x8C: Country(); break; // COUNTRY [ 345]
566 : // PALETTE follows XFs, but already needed while reading the XFs
567 1 : case 0x92: rPal.ReadPalette( maStrm ); break;
568 : }
569 : }
570 327 : break;
571 : case Z_Biff5W: // --------------------------------- Z_Biff5W -
572 : {
573 327 : switch( nOpcode )
574 : {
575 : case 0x0A: // EOF [ 2345]
576 3 : rNumFmtBfr.CreateScFormats();
577 3 : rXFBfr.CreateUserStyles();
578 3 : rNameMgr.ConvertAllTokens();
579 3 : eAkt = Z_Biff5E;
580 3 : break;
581 1 : case 0x18: rNameMgr.ReadName( maStrm ); break;
582 0 : case 0x1E: rNumFmtBfr.ReadFormat( maStrm ); break;
583 3 : case 0x22: Rec1904(); break; // 1904 [ 2345]
584 35 : case 0x31: rFontBfr.ReadFont( maStrm ); break;
585 0 : case 0x56: break; // BUILTINFMTCNT[ 34 ]
586 3 : case 0x8D: Hideobj(); break; // HIDEOBJ [ 345]
587 0 : case 0xDE: Olesize(); break;
588 101 : case 0xE0: rXFBfr.ReadXF( maStrm ); break;
589 54 : case 0x0293: rXFBfr.ReadStyle( maStrm ); break;
590 24 : case 0x041E: rNumFmtBfr.ReadFormat( maStrm ); break;
591 : }
592 :
593 : }
594 327 : break;
595 :
596 : case Z_Biff5TPre: // ------------------------------- Z_Biff5Pre -
597 : {
598 2384 : if( nOpcode == 0x0809 )
599 2 : nBofLevel++;
600 2382 : else if( (nOpcode == 0x000A) && nBofLevel )
601 2 : nBofLevel--;
602 2380 : else if( !nBofLevel ) // don't read chart records
603 : {
604 2150 : switch( nOpcode )
605 : {
606 : case EXC_ID2_DIMENSIONS:
607 6 : case EXC_ID3_DIMENSIONS: ReadDimensions(); break;
608 0 : case 0x08: Row25(); break; // ROW [ 2 5]
609 : case 0x0A: // EOF [ 2345]
610 6 : eAkt = Z_Biff5T;
611 6 : aIn.SeekGlobalPosition(); // und zurueck an alte Position
612 6 : break;
613 0 : case 0x12: SheetProtect(); break; // SHEET PROTECTION
614 : case 0x1A:
615 0 : case 0x1B: rPageSett.ReadPageBreaks( maStrm ); break;
616 6 : case 0x1D: rTabViewSett.ReadSelection( maStrm ); break;
617 2 : case 0x17: Externsheet(); break; // EXTERNSHEET [ 2345]
618 0 : case 0x21: Array25(); break; // ARRAY [ 2 5]
619 0 : case 0x23: Externname25(); break; // EXTERNNAME [ 2 5]
620 0 : case 0x41: rTabViewSett.ReadPane( maStrm ); break;
621 0 : case 0x42: Codepage(); break; // CODEPAGE [ 2345]
622 6 : case 0x55: DefColWidth(); break;
623 6 : case 0x7D: Colinfo(); break; // COLINFO [ 345]
624 6 : case 0x81: Wsbool(); break; // WSBOOL [ 2345]
625 6 : case 0x8C: Country(); break; // COUNTRY [ 345]
626 0 : case 0x99: Standardwidth(); break; // STANDARDWIDTH[ 45]
627 380 : case 0x0208: Row34(); break; // ROW [ 34 ]
628 0 : case 0x0221: Array34(); break; // ARRAY [ 34 ]
629 0 : case 0x0223: break; // EXTERNNAME [ 34 ]
630 6 : case 0x0225: Defrowheight345();break;//DEFAULTROWHEI[ 345]
631 6 : case 0x023E: rTabViewSett.ReadWindow2( maStrm, false );break;
632 : }
633 : }
634 : }
635 2384 : break;
636 :
637 : case Z_Biff5T: // --------------------------------- Z_Biff5T -
638 : {
639 2150 : switch( nOpcode )
640 : {
641 : case EXC_ID2_BLANK:
642 0 : case EXC_ID3_BLANK: ReadBlank(); break;
643 0 : case EXC_ID2_INTEGER: ReadInteger(); break;
644 : case EXC_ID2_NUMBER:
645 60 : case EXC_ID3_NUMBER: ReadNumber(); break;
646 : case EXC_ID2_LABEL:
647 746 : case EXC_ID3_LABEL: ReadLabel(); break;
648 : case EXC_ID2_BOOLERR:
649 0 : case EXC_ID3_BOOLERR: ReadBoolErr(); break;
650 60 : case EXC_ID_RK: ReadRk(); break;
651 :
652 : case EXC_ID2_FORMULA:
653 : case EXC_ID3_FORMULA:
654 373 : case EXC_ID4_FORMULA: Formula25(); break;
655 32 : case EXC_ID_SHRFMLA: Shrfmla(); break;
656 6 : case 0x0A: Eof(); eAkt = Z_Biff5E; break;
657 : case 0x14:
658 12 : case 0x15: rPageSett.ReadHeaderFooter( maStrm ); break;
659 2 : case 0x17: Externsheet(); break; // EXTERNSHEET [ 2345]
660 0 : case 0x1C: GetCurrSheetDrawing().ReadNote( maStrm );break;
661 6 : case 0x1D: rTabViewSett.ReadSelection( maStrm ); break;
662 0 : case 0x23: Externname25(); break; // EXTERNNAME [ 2 5]
663 : case 0x26:
664 : case 0x27:
665 : case 0x28:
666 8 : case 0x29: rPageSett.ReadMargin( maStrm ); break;
667 6 : case 0x2A: rPageSett.ReadPrintHeaders( maStrm ); break;
668 6 : case 0x2B: rPageSett.ReadPrintGridLines( maStrm ); break;
669 : case 0x2F: // FILEPASS [ 2345]
670 0 : eLastErr = XclImpDecryptHelper::ReadFilepass( maStrm );
671 0 : if( eLastErr != ERRCODE_NONE )
672 0 : eAkt = Z_Ende;
673 0 : break;
674 2 : case 0x5D: GetCurrSheetDrawing().ReadObj( maStrm );break;
675 : case 0x83:
676 12 : case 0x84: rPageSett.ReadCenter( maStrm ); break;
677 0 : case 0xA0: rTabViewSett.ReadScl( maStrm ); break;
678 6 : case 0xA1: rPageSett.ReadSetup( maStrm ); break;
679 318 : case 0xBD: Mulrk(); break; // MULRK [ 5]
680 0 : case 0xBE: Mulblank(); break; // MULBLANK [ 5]
681 0 : case 0xD6: Rstring(); break; // RSTRING [ 5]
682 0 : case 0x00E5: Cellmerging(); break; // #i62300#
683 0 : case 0x0236: TableOp(); break; // TABLE [ 5]
684 : case 0x0809: // BOF [ 5]
685 0 : XclTools::SkipSubStream( maStrm );
686 0 : break;
687 : }
688 :
689 : }
690 2150 : break;
691 :
692 : case Z_Biff5E: // --------------------------------- Z_Biff5E -
693 : {
694 6 : switch( nOpcode )
695 : {
696 : case 0x0809: // BOF [ 5]
697 6 : Bof5();
698 6 : NewTable();
699 6 : switch( pExcRoot->eDateiTyp )
700 : {
701 : case Biff5:
702 : case Biff5M4:
703 6 : eAkt = Z_Biff5TPre; // Shrfmla Prefetch, Row-Prefetch
704 6 : nBofLevel = 0;
705 6 : aIn.StoreGlobalPosition(); // store position
706 6 : break;
707 : case Biff5C: // chart sheet
708 0 : GetCurrSheetDrawing().ReadTabChart( maStrm );
709 0 : Eof();
710 0 : GetTracer().TraceChartOnlySheet();
711 0 : break;
712 : case Biff5V:
713 : default:
714 0 : pD->SetVisible( GetCurrScTab(), false );
715 0 : ePrev = eAkt;
716 0 : eAkt = Z_Biffn0;
717 : }
718 : OSL_ENSURE( pExcRoot->eDateiTyp != Biff5W,
719 : "+ImportExcel::Read(): Doppel-Whopper-Workbook!" );
720 :
721 6 : break;
722 : }
723 :
724 : }
725 6 : break;
726 : case Z_Biffn0: // --------------------------------- Z_Biffn0 -
727 : {
728 0 : switch( nOpcode )
729 : {
730 : case 0x0A: // EOF [ 2345]
731 0 : eAkt = ePrev;
732 0 : IncCurrScTab();
733 0 : break;
734 : }
735 :
736 : }
737 0 : break;
738 :
739 : case Z_Ende: // ----------------------------------- Z_Ende -
740 : OSL_FAIL( "*ImportExcel::Read(): Not possible state!" );
741 0 : break;
742 : default: OSL_FAIL( "-ImportExcel::Read(): state forgotten!" );
743 : }
744 : }
745 :
746 3 : if( eLastErr == eERR_OK )
747 : {
748 3 : pProgress.reset();
749 :
750 3 : GetDocImport().finalize();
751 3 : AdjustRowHeight();
752 3 : PostDocLoad();
753 :
754 3 : pD->CalcAfterLoad(false);
755 :
756 3 : const XclImpAddressConverter& rAddrConv = GetAddressConverter();
757 3 : if( rAddrConv.IsTabTruncated() )
758 0 : eLastErr = SCWARN_IMPORT_SHEET_OVERFLOW;
759 3 : else if( bTabTruncated || rAddrConv.IsRowTruncated() )
760 0 : eLastErr = SCWARN_IMPORT_ROW_OVERFLOW;
761 3 : else if( rAddrConv.IsColTruncated() )
762 0 : eLastErr = SCWARN_IMPORT_COLUMN_OVERFLOW;
763 : }
764 :
765 3 : return eLastErr;
766 : }
767 :
768 81 : FltError ImportExcel8::Read()
769 : {
770 : #ifdef EXC_INCL_DUMPER
771 : {
772 : Biff8RecDumper aDumper( GetRoot(), sal_True );
773 : if( aDumper.Dump( aIn ) )
774 : return ERRCODE_ABORT;
775 : }
776 : #endif
777 : // read the entire BIFF8 stream
778 : // don't look too close - this stuff seriously needs to be reworked
779 :
780 81 : XclImpPageSettings& rPageSett = GetPageSettings();
781 81 : XclImpTabViewSettings& rTabViewSett = GetTabViewSettings();
782 81 : XclImpPalette& rPal = GetPalette();
783 81 : XclImpFontBuffer& rFontBfr = GetFontBuffer();
784 81 : XclImpNumFmtBuffer& rNumFmtBfr = GetNumFmtBuffer();
785 81 : XclImpXFBuffer& rXFBfr = GetXFBuffer();
786 81 : XclImpSst& rSst = GetSst();
787 81 : XclImpTabInfo& rTabInfo = GetTabInfo();
788 81 : XclImpNameManager& rNameMgr = GetNameManager();
789 81 : XclImpLinkManager& rLinkMgr = GetLinkManager();
790 81 : XclImpObjectManager& rObjMgr = GetObjectManager();
791 : // call to GetCurrSheetDrawing() cannot be cached (changes in new sheets)
792 81 : XclImpCondFormatManager& rCondFmtMgr = GetCondFormatManager();
793 81 : XclImpValidationManager& rValidMgr = GetValidationManager();
794 81 : XclImpPivotTableManager& rPTableMgr = GetPivotTableManager();
795 81 : XclImpWebQueryBuffer& rWQBfr = GetWebQueryBuffer();
796 :
797 81 : bool bInUserView = false; // true = In USERSVIEW(BEGIN|END) record block.
798 :
799 : enum XclImpReadState
800 : {
801 : EXC_STATE_BEFORE_GLOBALS, /// Before workbook globals (wait for initial BOF).
802 : EXC_STATE_GLOBALS_PRE, /// Prefetch for workbook globals.
803 : EXC_STATE_GLOBALS, /// Workbook globals.
804 : EXC_STATE_BEFORE_SHEET, /// Before worksheet (wait for new worksheet BOF).
805 : EXC_STATE_SHEET_PRE, /// Prefetch for worksheet.
806 : EXC_STATE_SHEET, /// Worksheet.
807 : EXC_STATE_END /// Stop reading.
808 : };
809 :
810 81 : XclImpReadState eAkt = EXC_STATE_BEFORE_GLOBALS;
811 :
812 81 : FltError eLastErr = eERR_OK;
813 :
814 : boost::scoped_ptr< ScfSimpleProgressBar > pProgress( new ScfSimpleProgressBar(
815 81 : aIn.GetSvStreamSize(), GetDocShell(), STR_LOAD_DOC ) );
816 :
817 : /* #i104057# Need to track a base position for progress bar calculation,
818 : because sheet substreams may not be in order of sheets. */
819 81 : sal_Size nProgressBasePos = 0;
820 81 : sal_Size nProgressBaseSize = 0;
821 :
822 81 : bool bSheetHasCodeName = false;
823 :
824 162 : std::vector<OUString> aCodeNames;
825 162 : std::vector < SCTAB > nTabsWithNoCodeName;
826 :
827 81 : sal_uInt16 nRecId = 0;
828 :
829 1154432 : for (; eAkt != EXC_STATE_END; mnLastRecId = nRecId)
830 : {
831 1154432 : if( eAkt == EXC_STATE_BEFORE_SHEET )
832 : {
833 297 : sal_uInt16 nScTab = GetCurrScTab();
834 297 : if( nScTab < maSheetOffsets.size() )
835 : {
836 218 : nProgressBaseSize += (maStrm.GetSvStreamPos() - nProgressBasePos);
837 218 : nProgressBasePos = maSheetOffsets[ nScTab ];
838 :
839 : // i#115255 fdo#40304 BOUNDSHEET doesn't point to a valid
840 : // BOF record position. Scan the records manually (from
841 : // the BOUNDSHEET position) until we find a BOF. Some 3rd
842 : // party Russian programs generate invalid xls docs with
843 : // this kind of silliness.
844 218 : if (aIn.PeekRecId(nProgressBasePos) == EXC_ID5_BOF)
845 : // BOUNDSHEET points to a valid BOF record. Good.
846 218 : aIn.StartNextRecord(nProgressBasePos);
847 : else
848 : {
849 0 : bool bValid = true;
850 0 : while (bValid && aIn.GetRecId() != EXC_ID5_BOF)
851 0 : bValid = aIn.StartNextRecord();
852 :
853 0 : if (!bValid)
854 : // Safeguard ourselves from potential infinite loop.
855 0 : eAkt = EXC_STATE_END;
856 : }
857 :
858 : // import only 256 sheets
859 218 : if( nScTab > GetScMaxPos().Tab() )
860 : {
861 0 : if( maStrm.GetRecId() != EXC_ID_EOF )
862 0 : XclTools::SkipSubStream( maStrm );
863 : // #i29930# show warning box
864 0 : GetAddressConverter().CheckScTab( nScTab, true );
865 0 : eAkt = EXC_STATE_END;
866 : }
867 : else
868 : {
869 : // #i109800# SHEET record may point to any record inside the
870 : // sheet substream
871 218 : bool bIsBof = maStrm.GetRecId() == EXC_ID5_BOF;
872 218 : if( bIsBof )
873 218 : Bof5(); // read the BOF record
874 : else
875 0 : pExcRoot->eDateiTyp = Biff8; // on missing BOF, assume a standard worksheet
876 218 : NewTable();
877 218 : switch( pExcRoot->eDateiTyp )
878 : {
879 : case Biff8: // worksheet
880 : case Biff8M4: // macro sheet
881 218 : eAkt = EXC_STATE_SHEET_PRE; // Shrfmla Prefetch, Row-Prefetch
882 : // go to next record
883 218 : if( bIsBof ) maStrm.StartNextRecord();
884 218 : maStrm.StoreGlobalPosition();
885 218 : break;
886 : case Biff8C: // chart sheet
887 0 : GetCurrSheetDrawing().ReadTabChart( maStrm );
888 0 : Eof();
889 0 : GetTracer().TraceChartOnlySheet();
890 0 : break;
891 : case Biff8W: // workbook
892 : OSL_FAIL( "ImportExcel8::Read - double workbook globals" );
893 : // run through
894 : case Biff8V: // VB module
895 : default:
896 : // TODO: do not create a sheet in the Calc document
897 0 : pD->SetVisible( nScTab, false );
898 0 : XclTools::SkipSubStream( maStrm );
899 0 : IncCurrScTab();
900 : }
901 : }
902 : }
903 : else
904 79 : eAkt = EXC_STATE_END;
905 : }
906 : else
907 1154135 : aIn.StartNextRecord();
908 :
909 1154432 : if( !aIn.IsValid() )
910 : {
911 : // #i63591# finalize table if EOF is missing
912 3 : switch( eAkt )
913 : {
914 : case EXC_STATE_SHEET_PRE:
915 1 : eAkt = EXC_STATE_SHEET;
916 1 : aIn.SeekGlobalPosition();
917 1 : continue; // next iteration in while loop
918 : case EXC_STATE_SHEET:
919 1 : Eof();
920 1 : eAkt = EXC_STATE_END;
921 1 : break;
922 : default:
923 1 : eAkt = EXC_STATE_END;
924 : }
925 : }
926 :
927 1154431 : if( eAkt == EXC_STATE_END )
928 81 : break;
929 :
930 1154350 : if( eAkt != EXC_STATE_SHEET_PRE && eAkt != EXC_STATE_GLOBALS_PRE )
931 576777 : pProgress->ProgressAbs( nProgressBaseSize + aIn.GetSvStreamPos() - nProgressBasePos );
932 :
933 1154350 : nRecId = aIn.GetRecId();
934 :
935 : /* #i39464# Ignore records between USERSVIEWBEGIN and USERSVIEWEND
936 : completely (user specific view settings). Otherwise view settings
937 : and filters are loaded multiple times, which at least causes
938 : problems in auto-filters. */
939 1154350 : switch( nRecId )
940 : {
941 : case EXC_ID_USERSVIEWBEGIN:
942 : OSL_ENSURE( !bInUserView, "ImportExcel8::Read - nested user view settings" );
943 18 : bInUserView = true;
944 18 : break;
945 : case EXC_ID_USERSVIEWEND:
946 : OSL_ENSURE( bInUserView, "ImportExcel8::Read - not in user view settings" );
947 18 : bInUserView = false;
948 18 : break;
949 : }
950 :
951 1154350 : if( !bInUserView ) switch( eAkt )
952 : {
953 :
954 : // before workbook globals: wait for initial workbook globals BOF
955 : case EXC_STATE_BEFORE_GLOBALS:
956 : {
957 86 : if( nRecId == EXC_ID5_BOF )
958 : {
959 : OSL_ENSURE( GetBiff() == EXC_BIFF8, "ImportExcel8::Read - wrong BIFF version" );
960 81 : Bof5();
961 81 : if( pExcRoot->eDateiTyp == Biff8W )
962 : {
963 80 : eAkt = EXC_STATE_GLOBALS_PRE;
964 80 : maStrm.StoreGlobalPosition();
965 80 : nBdshtTab = 0;
966 : }
967 1 : else if( pExcRoot->eDateiTyp == Biff8 )
968 : {
969 : // #i62752# possible to have BIFF8 sheet without globals
970 0 : NewTable();
971 0 : eAkt = EXC_STATE_SHEET_PRE; // Shrfmla Prefetch, Row-Prefetch
972 0 : bSheetHasCodeName = false; // reset
973 0 : aIn.StoreGlobalPosition();
974 : }
975 : }
976 : }
977 86 : break;
978 :
979 : // prefetch for workbook globals
980 : case EXC_STATE_GLOBALS_PRE:
981 : {
982 12065 : switch( nRecId )
983 : {
984 : case EXC_ID_EOF:
985 : case EXC_ID_EXTSST:
986 : /* #i56376# evil hack: if EOF for globals is missing,
987 : simulate it. This hack works only for the bugdoc
988 : given in the issue, where the sheet substreams
989 : start directly after the EXTSST record. A future
990 : implementation should be more robust against
991 : missing EOFs. */
992 222 : if( (nRecId == EXC_ID_EOF) ||
993 62 : ((nRecId == EXC_ID_EXTSST) && (maStrm.GetNextRecId() == EXC_ID5_BOF)) )
994 : {
995 80 : eAkt = EXC_STATE_GLOBALS;
996 80 : aIn.SeekGlobalPosition();
997 : }
998 142 : break;
999 49 : case 0x12: DocProtect(); break; // PROTECT [ 5678]
1000 49 : case 0x13: DocPasssword(); break;
1001 49 : case 0x19: WinProtection(); break;
1002 : case 0x2F: // FILEPASS [ 2345 ]
1003 0 : eLastErr = XclImpDecryptHelper::ReadFilepass( maStrm );
1004 0 : if( eLastErr != ERRCODE_NONE )
1005 0 : eAkt = EXC_STATE_END;
1006 0 : break;
1007 0 : case EXC_ID_FILESHARING: ReadFileSharing(); break;
1008 79 : case 0x3D: Window1(); break;
1009 79 : case 0x42: Codepage(); break; // CODEPAGE [ 2345 ]
1010 219 : case 0x85: Boundsheet(); break; // BOUNDSHEET [ 5 ]
1011 78 : case 0x8C: Country(); break; // COUNTRY [ 345 ]
1012 :
1013 : // PALETTE follows XFs, but already needed while reading the XFs
1014 5 : case EXC_ID_PALETTE: rPal.ReadPalette( maStrm ); break;
1015 : }
1016 : }
1017 12065 : break;
1018 :
1019 : // workbook globals
1020 : case EXC_STATE_GLOBALS:
1021 : {
1022 11693 : switch( nRecId )
1023 : {
1024 : case EXC_ID_EOF:
1025 : case EXC_ID_EXTSST:
1026 : /* #i56376# evil hack: if EOF for globals is missing,
1027 : simulate it. This hack works only for the bugdoc
1028 : given in the issue, where the sheet substreams
1029 : start directly after the EXTSST record. A future
1030 : implementation should be more robust against
1031 : missing EOFs. */
1032 222 : if( (nRecId == EXC_ID_EOF) ||
1033 62 : ((nRecId == EXC_ID_EXTSST) && (maStrm.GetNextRecId() == EXC_ID5_BOF)) )
1034 : {
1035 80 : rNumFmtBfr.CreateScFormats();
1036 80 : rXFBfr.CreateUserStyles();
1037 80 : rPTableMgr.ReadPivotCaches( maStrm );
1038 80 : rNameMgr.ConvertAllTokens();
1039 80 : eAkt = EXC_STATE_BEFORE_SHEET;
1040 : }
1041 142 : break;
1042 77 : case 0x0E: Precision(); break; // PRECISION
1043 78 : case 0x22: Rec1904(); break; // 1904 [ 2345 ]
1044 0 : case 0x56: break; // BUILTINFMTCNT[ 34 ]
1045 78 : case 0x8D: Hideobj(); break; // HIDEOBJ [ 345 ]
1046 30 : case 0xD3: SetHasBasic(); break;
1047 1 : case 0xDE: Olesize(); break;
1048 :
1049 31 : case EXC_ID_CODENAME: ReadCodeName( aIn, true ); break;
1050 77 : case EXC_ID_USESELFS: ReadUsesElfs(); break;
1051 :
1052 817 : case EXC_ID2_FONT: rFontBfr.ReadFont( maStrm ); break;
1053 831 : case EXC_ID4_FORMAT: rNumFmtBfr.ReadFormat( maStrm ); break;
1054 3721 : case EXC_ID5_XF: rXFBfr.ReadXF( maStrm ); break;
1055 1264 : case EXC_ID_STYLE: rXFBfr.ReadStyle( maStrm ); break;
1056 :
1057 63 : case EXC_ID_SST: rSst.ReadSst( maStrm ); break;
1058 78 : case EXC_ID_TABID: rTabInfo.ReadTabid( maStrm ); break;
1059 164 : case EXC_ID_NAME: rNameMgr.ReadName( maStrm ); break;
1060 :
1061 47 : case EXC_ID_EXTERNSHEET: rLinkMgr.ReadExternsheet( maStrm ); break;
1062 49 : case EXC_ID_SUPBOOK: rLinkMgr.ReadSupbook( maStrm ); break;
1063 2 : case EXC_ID_XCT: rLinkMgr.ReadXct( maStrm ); break;
1064 2 : case EXC_ID_CRN: rLinkMgr.ReadCrn( maStrm ); break;
1065 0 : case EXC_ID_EXTERNNAME: rLinkMgr.ReadExternname( maStrm, pFormConv ); break;
1066 :
1067 58 : case EXC_ID_MSODRAWINGGROUP:rObjMgr.ReadMsoDrawingGroup( maStrm ); break;
1068 :
1069 2 : case EXC_ID_SXIDSTM: rPTableMgr.ReadSxidstm( maStrm ); break;
1070 2 : case EXC_ID_SXVS: rPTableMgr.ReadSxvs( maStrm ); break;
1071 2 : case EXC_ID_DCONREF: rPTableMgr.ReadDconref( maStrm ); break;
1072 0 : case EXC_ID_DCONNAME: rPTableMgr.ReadDConName( maStrm ); break;
1073 : }
1074 :
1075 : }
1076 11693 : break;
1077 :
1078 : // prefetch for worksheet
1079 : case EXC_STATE_SHEET_PRE:
1080 : {
1081 565481 : switch( nRecId )
1082 : {
1083 : // skip chart substream
1084 : case EXC_ID2_BOF:
1085 : case EXC_ID3_BOF:
1086 : case EXC_ID4_BOF:
1087 45 : case EXC_ID5_BOF: XclTools::SkipSubStream( maStrm ); break;
1088 :
1089 216 : case EXC_ID_WINDOW2: rTabViewSett.ReadWindow2( maStrm, false );break;
1090 3 : case EXC_ID_SCL: rTabViewSett.ReadScl( maStrm ); break;
1091 16 : case EXC_ID_PANE: rTabViewSett.ReadPane( maStrm ); break;
1092 230 : case EXC_ID_SELECTION: rTabViewSett.ReadSelection( maStrm ); break;
1093 :
1094 : case EXC_ID2_DIMENSIONS:
1095 218 : case EXC_ID3_DIMENSIONS: ReadDimensions(); break;
1096 :
1097 93 : case EXC_ID_CODENAME: ReadCodeName( aIn, false ); bSheetHasCodeName = true; break;
1098 :
1099 : case 0x0A: // EOF [ 2345 ]
1100 : {
1101 217 : eAkt = EXC_STATE_SHEET;
1102 217 : OUString sName;
1103 217 : GetDoc().GetName( GetCurrScTab(), sName );
1104 217 : if ( !bSheetHasCodeName )
1105 : {
1106 124 : nTabsWithNoCodeName.push_back( GetCurrScTab() );
1107 : OSL_TRACE("No Codename for %d", GetCurrScTab() );
1108 : }
1109 : else
1110 : {
1111 93 : OUString sCodeName;
1112 93 : GetDoc().GetCodeName( GetCurrScTab(), sCodeName );
1113 : OSL_TRACE("Have CodeName %s for SheetName %s",
1114 : OUStringToOString( sCodeName, RTL_TEXTENCODING_UTF8 ).getStr(), OUStringToOString( sName, RTL_TEXTENCODING_UTF8 ).getStr() );
1115 93 : aCodeNames.push_back( sCodeName );
1116 : }
1117 :
1118 217 : bSheetHasCodeName = false; // reset
1119 :
1120 217 : aIn.SeekGlobalPosition(); // and back to old position
1121 217 : break;
1122 : }
1123 13 : case 0x12: SheetProtect(); break;
1124 1 : case 0x13: SheetPassword(); break;
1125 0 : case 0x42: Codepage(); break; // CODEPAGE [ 2345 ]
1126 216 : case 0x55: DefColWidth(); break;
1127 410 : case 0x7D: Colinfo(); break; // COLINFO [ 345 ]
1128 217 : case 0x81: Wsbool(); break; // WSBOOL [ 2345 ]
1129 0 : case 0x8C: Country(); break; // COUNTRY [ 345 ]
1130 1 : case 0x99: Standardwidth(); break; // STANDARDWIDTH[ 45 ]
1131 5 : case 0x9B: FilterMode(); break; // FILTERMODE
1132 8 : case EXC_ID_AUTOFILTERINFO: AutoFilterInfo(); break;// AUTOFILTERINFO
1133 5 : case EXC_ID_AUTOFILTER: AutoFilter(); break; // AUTOFILTER
1134 266966 : case 0x0208: Row34(); break; // ROW [ 34 ]
1135 : case EXC_ID2_ARRAY:
1136 8 : case EXC_ID3_ARRAY: Array34(); break; // ARRAY [ 34 ]
1137 217 : case 0x0225: Defrowheight345();break;//DEFAULTROWHEI[ 345 ]
1138 116 : case 0x0867: FeatHdr(); break; // FEATHDR
1139 7 : case 0x0868: Feat(); break; // FEAT
1140 : }
1141 : }
1142 565481 : break;
1143 :
1144 : // worksheet
1145 : case EXC_STATE_SHEET:
1146 : {
1147 564971 : switch( nRecId )
1148 : {
1149 : // skip unknown substreams
1150 : case EXC_ID2_BOF:
1151 : case EXC_ID3_BOF:
1152 : case EXC_ID4_BOF:
1153 0 : case EXC_ID5_BOF: XclTools::SkipSubStream( maStrm ); break;
1154 :
1155 217 : case EXC_ID_EOF: Eof(); eAkt = EXC_STATE_BEFORE_SHEET; break;
1156 :
1157 : case EXC_ID2_BLANK:
1158 196561 : case EXC_ID3_BLANK: ReadBlank(); break;
1159 0 : case EXC_ID2_INTEGER: ReadInteger(); break;
1160 : case EXC_ID2_NUMBER:
1161 1957 : case EXC_ID3_NUMBER: ReadNumber(); break;
1162 : case EXC_ID2_LABEL:
1163 4 : case EXC_ID3_LABEL: ReadLabel(); break;
1164 : case EXC_ID2_BOOLERR:
1165 1 : case EXC_ID3_BOOLERR: ReadBoolErr(); break;
1166 2230 : case EXC_ID_RK: ReadRk(); break;
1167 :
1168 : case EXC_ID2_FORMULA:
1169 : case EXC_ID3_FORMULA:
1170 3257 : case EXC_ID4_FORMULA: Formula25(); break;
1171 90 : case EXC_ID_SHRFMLA: Shrfmla(); break;
1172 168 : case 0x000C: Calccount(); break; // CALCCOUNT
1173 216 : case 0x0010: Delta(); break; // DELTA
1174 216 : case 0x0011: Iteration(); break; // ITERATION
1175 : case 0x007E:
1176 0 : case 0x00AE: Scenman(); break; // SCENMAN
1177 0 : case 0x00AF: Scenario(); break; // SCENARIO
1178 2165 : case 0x00BD: Mulrk(); break; // MULRK [ 5 ]
1179 2468 : case 0x00BE: Mulblank(); break; // MULBLANK [ 5 ]
1180 0 : case 0x00D6: Rstring(); break; // RSTRING [ 5 ]
1181 40 : case 0x00E5: Cellmerging(); break; // CELLMERGING
1182 76546 : case 0x00FD: Labelsst(); break; // LABELSST [ 8 ]
1183 2 : case 0x0236: TableOp(); break; // TABLE
1184 :
1185 : case EXC_ID_HORPAGEBREAKS:
1186 2 : case EXC_ID_VERPAGEBREAKS: rPageSett.ReadPageBreaks( maStrm ); break;
1187 : case EXC_ID_HEADER:
1188 435 : case EXC_ID_FOOTER: rPageSett.ReadHeaderFooter( maStrm ); break;
1189 : case EXC_ID_LEFTMARGIN:
1190 : case EXC_ID_RIGHTMARGIN:
1191 : case EXC_ID_TOPMARGIN:
1192 396 : case EXC_ID_BOTTOMMARGIN: rPageSett.ReadMargin( maStrm ); break;
1193 216 : case EXC_ID_PRINTHEADERS: rPageSett.ReadPrintHeaders( maStrm ); break;
1194 217 : case EXC_ID_PRINTGRIDLINES: rPageSett.ReadPrintGridLines( maStrm ); break;
1195 : case EXC_ID_HCENTER:
1196 436 : case EXC_ID_VCENTER: rPageSett.ReadCenter( maStrm ); break;
1197 218 : case EXC_ID_SETUP: rPageSett.ReadSetup( maStrm ); break;
1198 0 : case EXC_ID8_IMGDATA: rPageSett.ReadImgData( maStrm ); break;
1199 :
1200 116 : case EXC_ID_MSODRAWING: GetCurrSheetDrawing().ReadMsoDrawing( maStrm ); break;
1201 : // #i61786# weird documents: OBJ without MSODRAWING -> read in BIFF5 format
1202 0 : case EXC_ID_OBJ: GetCurrSheetDrawing().ReadObj( maStrm ); break;
1203 4 : case EXC_ID_NOTE: GetCurrSheetDrawing().ReadNote( maStrm ); break;
1204 :
1205 8 : case EXC_ID_HLINK: XclImpHyperlink::ReadHlink( maStrm ); break;
1206 0 : case EXC_ID_LABELRANGES: XclImpLabelranges::ReadLabelranges( maStrm ); break;
1207 :
1208 2 : case EXC_ID_CONDFMT: rCondFmtMgr.ReadCondfmt( maStrm ); break;
1209 2 : case EXC_ID_CF: rCondFmtMgr.ReadCF( maStrm ); break;
1210 :
1211 5 : case EXC_ID_DVAL: XclImpValidationManager::ReadDval( maStrm ); break;
1212 3 : case EXC_ID_DV: rValidMgr.ReadDV( maStrm ); break;
1213 :
1214 0 : case EXC_ID_QSI: rWQBfr.ReadQsi( maStrm ); break;
1215 0 : case EXC_ID_WQSTRING: rWQBfr.ReadWqstring( maStrm ); break;
1216 0 : case EXC_ID_PQRY: rWQBfr.ReadParamqry( maStrm ); break;
1217 0 : case EXC_ID_WQSETT: rWQBfr.ReadWqsettings( maStrm ); break;
1218 0 : case EXC_ID_WQTABLES: rWQBfr.ReadWqtables( maStrm ); break;
1219 :
1220 2 : case EXC_ID_SXVIEW: rPTableMgr.ReadSxview( maStrm ); break;
1221 5 : case EXC_ID_SXVD: rPTableMgr.ReadSxvd( maStrm ); break;
1222 15 : case EXC_ID_SXVI: rPTableMgr.ReadSxvi( maStrm ); break;
1223 2 : case EXC_ID_SXIVD: rPTableMgr.ReadSxivd( maStrm ); break;
1224 0 : case EXC_ID_SXPI: rPTableMgr.ReadSxpi( maStrm ); break;
1225 1 : case EXC_ID_SXDI: rPTableMgr.ReadSxdi( maStrm ); break;
1226 5 : case EXC_ID_SXVDEX: rPTableMgr.ReadSxvdex( maStrm ); break;
1227 2 : case EXC_ID_SXEX: rPTableMgr.ReadSxex( maStrm ); break;
1228 2 : case EXC_ID_SHEETEXT: rTabViewSett.ReadTabBgColor( maStrm, rPal ); break;
1229 2 : case EXC_ID_SXVIEWEX9: rPTableMgr.ReadSxViewEx9( maStrm ); break;
1230 : }
1231 : }
1232 564971 : break;
1233 :
1234 : default:;
1235 : }
1236 : }
1237 :
1238 81 : if( eLastErr == eERR_OK )
1239 : {
1240 : // In some strange circumstances a the codename might be missing
1241 : // # Create any missing Sheet CodeNames
1242 81 : std::vector < SCTAB >::iterator it_end = nTabsWithNoCodeName.end();
1243 205 : for ( std::vector < SCTAB >::iterator it = nTabsWithNoCodeName.begin(); it != it_end; ++it )
1244 : {
1245 124 : SCTAB nTab = 1;
1246 : OSL_TRACE("Trying to find suitable codename for %d", *it );
1247 : while ( true )
1248 : {
1249 347 : OUStringBuffer aBuf;
1250 347 : aBuf.appendAscii("Sheet");
1251 347 : aBuf.append(static_cast<sal_Int32>(nTab++));
1252 570 : OUString sTmpName = aBuf.makeStringAndClear();
1253 347 : std::vector<OUString>::iterator codeName_It = aCodeNames.begin();
1254 347 : std::vector<OUString>::iterator codeName_It_end = aCodeNames.end();
1255 : // search for codename
1256 1223 : for ( ; codeName_It != codeName_It_end; ++codeName_It )
1257 : {
1258 1099 : if ( *codeName_It == sTmpName )
1259 223 : break;
1260 : }
1261 :
1262 347 : if ( codeName_It == codeName_It_end ) // generated codename not found
1263 : {
1264 : OSL_TRACE("Using generated codename %s", OUStringToOString( sTmpName, RTL_TEXTENCODING_UTF8 ).getStr() );
1265 : // Set new codename
1266 124 : GetDoc().SetCodeName( *it, sTmpName );
1267 : // Record newly used codename
1268 124 : aCodeNames.push_back(sTmpName);
1269 : // Record those we have created so they can be created in
1270 : // basic
1271 124 : maAutoGeneratedCodeNames.push_back( sTmpName );
1272 124 : break;
1273 : }
1274 223 : }
1275 223 : }
1276 : // #i45843# Convert pivot tables before calculation, so they are available
1277 : // for the GETPIVOTDATA function.
1278 81 : if( GetBiff() == EXC_BIFF8 )
1279 81 : GetPivotTableManager().ConvertPivotTables();
1280 :
1281 81 : ScDocumentImport& rDoc = GetDocImport();
1282 81 : rDoc.finalize();
1283 81 : pProgress.reset();
1284 : #if 0
1285 : // Excel documents look much better without this call; better in the
1286 : // sense that the row heights are identical to the original heights in
1287 : // Excel.
1288 : if (pD->IsAdjustHeightEnabled())
1289 : AdjustRowHeight();
1290 : #endif
1291 81 : PostDocLoad();
1292 :
1293 81 : pD->CalcAfterLoad(false);
1294 :
1295 : // import change tracking data
1296 81 : XclImpChangeTrack aImpChTr( GetRoot(), maStrm );
1297 81 : aImpChTr.Apply();
1298 :
1299 81 : const XclImpAddressConverter& rAddrConv = GetAddressConverter();
1300 81 : if( rAddrConv.IsTabTruncated() )
1301 0 : eLastErr = SCWARN_IMPORT_SHEET_OVERFLOW;
1302 81 : else if( bTabTruncated || rAddrConv.IsRowTruncated() )
1303 0 : eLastErr = SCWARN_IMPORT_ROW_OVERFLOW;
1304 81 : else if( rAddrConv.IsColTruncated() )
1305 1 : eLastErr = SCWARN_IMPORT_COLUMN_OVERFLOW;
1306 :
1307 81 : if( GetBiff() == EXC_BIFF8 )
1308 81 : GetPivotTableManager().MaybeRefreshPivotTables();
1309 : }
1310 :
1311 162 : return eLastErr;
1312 30 : }
1313 :
1314 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|