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