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 "excform.hxx"
21 : #include <osl/endian.h>
22 :
23 : #include "cell.hxx"
24 : #include "document.hxx"
25 : #include "rangenam.hxx"
26 : #include "global.hxx"
27 : #include "formula/errorcodes.hxx"
28 :
29 : #include "imp_op.hxx"
30 : #include "root.hxx"
31 : #include "xltracer.hxx"
32 : #include "xihelper.hxx"
33 : #include "xilink.hxx"
34 : #include "xiname.hxx"
35 :
36 : using ::std::vector;
37 :
38 : const sal_uInt16 ExcelToSc::nRowMask = 0x3FFF;
39 : const sal_uInt16 ExcelToSc::nLastInd = 399;
40 :
41 :
42 2429 : void ImportExcel::Formula25()
43 : {
44 2429 : XclAddress aXclPos;
45 2429 : sal_uInt16 nXF = 0, nFormLen;
46 : double fCurVal;
47 : sal_uInt8 nFlag0;
48 : sal_Bool bShrFmla;
49 :
50 2429 : aIn >> aXclPos;
51 :
52 2429 : if( GetBiff() == EXC_BIFF2 )
53 : {// BIFF2
54 : sal_uInt8 nDummy;
55 :
56 0 : aIn.Ignore( 3 );
57 :
58 0 : aIn >> fCurVal;
59 0 : aIn.Ignore( 1 );
60 0 : aIn >> nDummy;
61 0 : nFormLen = nDummy;
62 0 : bShrFmla = false;
63 : }
64 : else
65 : {// BIFF5
66 2429 : aIn >> nXF >> fCurVal >> nFlag0;
67 2429 : aIn.Ignore( 5 );
68 :
69 2429 : aIn >> nFormLen;
70 :
71 2429 : bShrFmla = nFlag0 & 0x08; // shared or not shared
72 : }
73 :
74 2429 : Formula( aXclPos, nXF, nFormLen, fCurVal, bShrFmla );
75 2429 : }
76 :
77 :
78 0 : void ImportExcel::Formula3()
79 : {
80 0 : Formula4();
81 0 : }
82 :
83 :
84 0 : void ImportExcel::Formula4()
85 : {
86 0 : XclAddress aXclPos;
87 : sal_uInt16 nXF, nFormLen;
88 : double fCurVal;
89 : sal_uInt8 nFlag0;
90 :
91 0 : aIn >> aXclPos >> nXF >> fCurVal >> nFlag0;
92 0 : aIn.Ignore( 1 );
93 0 : aIn >> nFormLen;
94 :
95 0 : Formula( aXclPos, nXF, nFormLen, fCurVal, false );
96 0 : }
97 :
98 :
99 2429 : void ImportExcel::Formula(
100 : const XclAddress& rXclPos, sal_uInt16 nXF, sal_uInt16 nFormLen, double fCurVal, bool bShrFmla)
101 : {
102 2429 : ConvErr eErr = ConvOK;
103 :
104 2429 : ScAddress aScPos( ScAddress::UNINITIALIZED );
105 2429 : if( GetAddressConverter().ConvertAddress( aScPos, rXclPos, GetCurrScTab(), true ) )
106 : {
107 : // Formula will be read next, length in nFormLen
108 2429 : const ScTokenArray* pResult = NULL;
109 2429 : bool bConvert = false;
110 :
111 2429 : pFormConv->Reset( aScPos );
112 :
113 2429 : if( bShrFmla )
114 328 : bConvert = !pFormConv->GetShrFmla( pResult, maStrm, nFormLen );
115 : else
116 2101 : bConvert = true;
117 :
118 2429 : if( bConvert )
119 2349 : eErr = pFormConv->Convert( pResult, maStrm, nFormLen, true, FT_CellFormula);
120 :
121 2429 : ScFormulaCell* pCell = NULL;
122 :
123 2429 : if (pResult)
124 : {
125 2413 : pCell = new ScFormulaCell( pD, aScPos, pResult );
126 2413 : pD->PutCell( aScPos.Col(), aScPos.Row(), aScPos.Tab(), pCell, true );
127 : }
128 : else
129 : {
130 : CellType eCellType;
131 : ScBaseCell* pBaseCell;
132 16 : pD->GetCellType( aScPos.Col(), aScPos.Row(), aScPos.Tab(), eCellType );
133 16 : if( eCellType == CELLTYPE_FORMULA )
134 : {
135 16 : pD->GetCell( aScPos.Col(), aScPos.Row(), aScPos.Tab(), pBaseCell );
136 16 : pCell = ( ScFormulaCell* ) pBaseCell;
137 16 : if( pCell )
138 16 : pCell->AddRecalcMode( RECALCMODE_ONLOAD_ONCE );
139 : }
140 : }
141 :
142 2429 : if (pCell)
143 : {
144 2429 : if( eErr != ConvOK )
145 1 : ExcelToSc::SetError( *pCell, eErr );
146 :
147 2429 : if (!rtl::math::isNan(fCurVal))
148 2425 : pCell->SetResultDouble(fCurVal);
149 : }
150 :
151 2429 : GetXFRangeBuffer().SetXF( aScPos, nXF );
152 : }
153 2429 : }
154 :
155 :
156 :
157 :
158 40 : ExcelToSc::ExcelToSc( const XclImpRoot& rRoot ) :
159 : ExcelConverterBase( 512 ),
160 : XclImpRoot( rRoot ),
161 : maFuncProv( rRoot ),
162 40 : meBiff( rRoot.GetBiff() )
163 : {
164 40 : }
165 :
166 60 : ExcelToSc::~ExcelToSc()
167 : {
168 60 : }
169 :
170 0 : void ExcelToSc::GetDummy( const ScTokenArray*& pErgebnis )
171 : {
172 0 : aPool.Store( CREATE_STRING( "Dummy()" ) );
173 0 : aPool >> aStack;
174 0 : pErgebnis = aPool[ aStack.Get() ];
175 0 : }
176 :
177 :
178 : // if bAllowArrays is false stream seeks to first byte after <nFormulaLen>
179 : // otherwise it will seek to the first byte after the additional content (eg
180 : // inline arrays) following <nFormulaLen>
181 0 : ConvErr ExcelToSc::Convert( const ScTokenArray*& pErgebnis, XclImpStream& aIn, sal_Size nFormulaLen, bool bAllowArrays, const FORMULA_TYPE eFT )
182 : {
183 0 : RootData& rR = GetOldRoot();
184 : sal_uInt8 nOp, nLen, nByte;
185 : sal_uInt16 nUINT16;
186 : sal_Int16 nINT16;
187 : double fDouble;
188 0 : String aString;
189 0 : sal_Bool bError = false;
190 0 : sal_Bool bArrayFormula = false;
191 0 : TokenId nMerk0;
192 0 : const sal_Bool bRangeName = eFT == FT_RangeName;
193 0 : const sal_Bool bSharedFormula = eFT == FT_SharedFormula;
194 0 : const sal_Bool bConditional = eFT == FT_CondFormat;
195 0 : const sal_Bool bRNorSF = bRangeName || bSharedFormula || bConditional;
196 :
197 : ScSingleRefData aSRD;
198 : ScComplexRefData aCRD;
199 0 : ExtensionTypeVec aExtensions;
200 :
201 0 : bExternName = false;
202 :
203 0 : if( eStatus != ConvOK )
204 : {
205 0 : aIn.Ignore( nFormulaLen );
206 0 : return eStatus;
207 : }
208 :
209 0 : if( nFormulaLen == 0 )
210 : {
211 0 : aPool.Store( CREATE_STRING( "-/-" ) );
212 0 : aPool >> aStack;
213 0 : pErgebnis = aPool[ aStack.Get() ];
214 0 : return ConvOK;
215 : }
216 :
217 0 : sal_Size nEndPos = aIn.GetRecPos() + nFormulaLen;
218 :
219 0 : while( (aIn.GetRecPos() < nEndPos) && !bError )
220 : {
221 0 : aIn >> nOp;
222 :
223 : // always reset flags
224 0 : aSRD.InitFlags();
225 0 : aCRD.InitFlags();
226 :
227 0 : switch( nOp ) // book page:
228 : { // SDK4 SDK5
229 : case 0x01: // Array Formula [325 ]
230 : // Array Formula or Shared Formula [ 277]
231 : case 0x02: // Data Table [325 277]
232 0 : nUINT16 = 3;
233 :
234 0 : if( meBiff != EXC_BIFF2 )
235 0 : nUINT16++;
236 :
237 0 : aIn.Ignore( nUINT16 );
238 :
239 0 : bArrayFormula = sal_True;
240 0 : break;
241 : case 0x03: // Addition [312 264]
242 0 : aStack >> nMerk0;
243 0 : aPool << aStack << ocAdd << nMerk0;
244 0 : aPool >> aStack;
245 0 : break;
246 : case 0x04: // Subtraction [313 264]
247 : // SECOND-TOP minus TOP
248 0 : aStack >> nMerk0;
249 0 : aPool << aStack << ocSub << nMerk0;
250 0 : aPool >> aStack;
251 0 : break;
252 : case 0x05: // Multiplication [313 264]
253 0 : aStack >> nMerk0;
254 0 : aPool << aStack << ocMul << nMerk0;
255 0 : aPool >> aStack;
256 0 : break;
257 : case 0x06: // Division [313 264]
258 : // divide TOP by SECOND-TOP
259 0 : aStack >> nMerk0;
260 0 : aPool << aStack << ocDiv << nMerk0;
261 0 : aPool >> aStack;
262 0 : break;
263 : case 0x07: // Exponentiation [313 265]
264 : // raise SECOND-TOP to power of TOP
265 0 : aStack >> nMerk0;
266 0 : aPool << aStack << ocPow << nMerk0;
267 0 : aPool >> aStack;
268 0 : break;
269 : case 0x08: // Concatenation [313 265]
270 : // append TOP to SECOND-TOP
271 0 : aStack >> nMerk0;
272 0 : aPool << aStack << ocAmpersand << nMerk0;
273 0 : aPool >> aStack;
274 0 : break;
275 : case 0x09: // Less Than [313 265]
276 : // SECOND-TOP < TOP
277 0 : aStack >> nMerk0;
278 0 : aPool << aStack << ocLess << nMerk0;
279 0 : aPool >> aStack;
280 0 : break;
281 : case 0x0A: // Less Than or Equal [313 265]
282 : // SECOND-TOP <= TOP
283 0 : aStack >> nMerk0;
284 0 : aPool << aStack << ocLessEqual << nMerk0;
285 0 : aPool >> aStack;
286 0 : break;
287 : case 0x0B: // Equal [313 265]
288 : // SECOND-TOP == TOP
289 0 : aStack >> nMerk0;
290 0 : aPool << aStack << ocEqual << nMerk0;
291 0 : aPool >> aStack;
292 0 : break;
293 : case 0x0C: // Greater Than or Equal [313 265]
294 : // SECOND-TOP >= TOP
295 0 : aStack >> nMerk0;
296 0 : aPool << aStack << ocGreaterEqual << nMerk0;
297 0 : aPool >> aStack;
298 0 : break;
299 : case 0x0D: // Greater Than [313 265]
300 : // SECOND-TOP > TOP
301 0 : aStack >> nMerk0;
302 0 : aPool << aStack << ocGreater << nMerk0;
303 0 : aPool >> aStack;
304 0 : break;
305 : case 0x0E: // Not Equal [313 265]
306 : // SECOND-TOP != TOP
307 0 : aStack >> nMerk0;
308 0 : aPool << aStack << ocNotEqual << nMerk0;
309 0 : aPool >> aStack;
310 0 : break;
311 : case 0x0F: // Intersection [314 265]
312 0 : aStack >> nMerk0;
313 0 : aPool << aStack << ocIntersect << nMerk0;
314 0 : aPool >> aStack;
315 0 : break;
316 : case 0x10: // Union [314 265]
317 : // ocSep instead of 'ocUnion'
318 0 : aStack >> nMerk0;
319 0 : aPool << aStack << ocSep << nMerk0;
320 : // doesn't fit exactly, but is more Excel-like
321 0 : aPool >> aStack;
322 0 : break;
323 : case 0x11: // Range [314 265]
324 0 : aStack >> nMerk0;
325 0 : aPool << aStack << ocRange << nMerk0;
326 0 : aPool >> aStack;
327 0 : break;
328 : case 0x12: // Unary Plus [312 264]
329 0 : aPool << ocAdd << aStack;
330 0 : aPool >> aStack;
331 0 : break;
332 : case 0x13: // Unary Minus [312 264]
333 0 : aPool << ocNegSub << aStack;
334 0 : aPool >> aStack;
335 0 : break;
336 : case 0x14: // Percent Sign [312 264]
337 0 : aPool << aStack << ocPercentSign;
338 0 : aPool >> aStack;
339 0 : break;
340 : case 0x15: // Parenthesis [326 278]
341 0 : aPool << ocOpen << aStack << ocClose;
342 0 : aPool >> aStack;
343 0 : break;
344 : case 0x16: // Missing Argument [314 266]
345 0 : aPool << ocMissing;
346 0 : aPool >> aStack;
347 0 : GetTracer().TraceFormulaMissingArg();
348 0 : break;
349 : case 0x17: // String Constant [314 266]
350 0 : aIn >> nLen;
351 0 : aString = aIn.ReadRawByteString( nLen );
352 :
353 0 : aStack << aPool.Store( aString );
354 0 : break;
355 : case 0x19: // Special Attribute [327 279]
356 : {
357 : sal_uInt16 nData, nFakt;
358 : sal_uInt8 nOpt;
359 :
360 0 : aIn >> nOpt;
361 :
362 0 : if( meBiff == EXC_BIFF2 )
363 : {
364 0 : nData = aIn.ReaduInt8();
365 0 : nFakt = 1;
366 : }
367 : else
368 : {
369 0 : aIn >> nData;
370 0 : nFakt = 2;
371 : }
372 :
373 0 : if( nOpt & 0x04 )
374 : {// nFakt -> skip bytes or words AttrChoose
375 0 : nData++;
376 0 : aIn.Ignore( nData * nFakt );
377 : }
378 0 : else if( nOpt & 0x10 ) // AttrSum
379 0 : DoMulArgs( ocSum, 1 );
380 : }
381 0 : break;
382 : case 0x1A: // External Reference [330 ]
383 0 : switch( meBiff )
384 : {
385 0 : case EXC_BIFF2: aIn.Ignore( 7 ); break;
386 : case EXC_BIFF3:
387 0 : case EXC_BIFF4: aIn.Ignore( 10 ); break;
388 : case EXC_BIFF5:
389 : DBG_WARNING( "-ExcelToSc::Convert(): 0x1A does not exist in Biff5!" );
390 : default:
391 : DBG_WARNING( "-ExcelToSc::Convert(): A little oblivious?" );
392 : }
393 0 : break;
394 : case 0x1B: // End External Reference [330 ]
395 0 : switch( meBiff )
396 : {
397 0 : case EXC_BIFF2: aIn.Ignore( 3 ); break;
398 : case EXC_BIFF3:
399 0 : case EXC_BIFF4: aIn.Ignore( 4 ); break;
400 : case EXC_BIFF5:
401 : DBG_WARNING( "-ExcelToSc::Convert(): 0x1B does not exist in Biff5!" );
402 : default:
403 : DBG_WARNING( "-ExcelToSc::Convert(): A little oblivious?" );
404 : }
405 0 : break;
406 : case 0x1C: // Error Value [314 266]
407 : {
408 0 : aIn >> nByte;
409 : DefTokenId eOc;
410 0 : switch( nByte )
411 : {
412 : case EXC_ERR_NULL:
413 : case EXC_ERR_DIV0:
414 : case EXC_ERR_VALUE:
415 : case EXC_ERR_REF:
416 : case EXC_ERR_NAME:
417 0 : case EXC_ERR_NUM: eOc = ocStop; break;
418 0 : case EXC_ERR_NA: eOc = ocNotAvail; break;
419 0 : default: eOc = ocNoName;
420 : }
421 0 : aPool << eOc;
422 0 : if( eOc != ocStop )
423 0 : aPool << ocOpen << ocClose;
424 0 : aPool >> aStack;
425 : }
426 0 : break;
427 : case 0x1D: // Boolean [315 266]
428 0 : aIn >> nByte;
429 0 : if( nByte == 0 )
430 0 : aPool << ocFalse << ocOpen << ocClose;
431 : else
432 0 : aPool << ocTrue << ocOpen << ocClose;
433 0 : aPool >> aStack;
434 0 : break;
435 : case 0x1E: // Integer [315 266]
436 0 : aIn >> nUINT16;
437 0 : aStack << aPool.Store( ( double ) nUINT16 );
438 0 : break;
439 : case 0x1F: // Number [315 266]
440 0 : aIn >> fDouble;
441 0 : aStack << aPool.Store( fDouble );
442 0 : break;
443 : case 0x40:
444 : case 0x60:
445 : case 0x20: // Array Constant [317 268]
446 0 : aIn >> nByte >> nUINT16;
447 0 : aIn.Ignore( (meBiff == EXC_BIFF2) ? 3 : 4 );
448 0 : if( bAllowArrays )
449 : {
450 0 : aStack << aPool.StoreMatrix();
451 0 : aExtensions.push_back( EXTENSION_ARRAY );
452 : }
453 : else
454 : {
455 0 : aPool << ocBad;
456 0 : aPool >> aStack;
457 : }
458 0 : break;
459 : case 0x41:
460 : case 0x61:
461 : case 0x21: // Function, Fixed Number of Arguments [333 282]
462 : {
463 : sal_uInt16 nXclFunc;
464 0 : if( meBiff <= EXC_BIFF3 )
465 0 : nXclFunc = aIn.ReaduInt8();
466 : else
467 0 : aIn >> nXclFunc;
468 0 : if( const XclFunctionInfo* pFuncInfo = maFuncProv.GetFuncInfoFromXclFunc( nXclFunc ) )
469 0 : DoMulArgs( pFuncInfo->meOpCode, pFuncInfo->mnMaxParamCount );
470 : else
471 0 : DoMulArgs( ocNoName, 0 );
472 : }
473 0 : break;
474 : case 0x42:
475 : case 0x62:
476 : case 0x22: // Function, Variable Number of Arg. [333 283]
477 : {
478 : sal_uInt16 nXclFunc;
479 : sal_uInt8 nParamCount;
480 0 : aIn >> nParamCount;
481 0 : nParamCount &= 0x7F;
482 0 : if( meBiff <= EXC_BIFF3 )
483 0 : nXclFunc = aIn.ReaduInt8();
484 : else
485 0 : aIn >> nXclFunc;
486 0 : if( const XclFunctionInfo* pFuncInfo = maFuncProv.GetFuncInfoFromXclFunc( nXclFunc ) )
487 0 : DoMulArgs( pFuncInfo->meOpCode, nParamCount );
488 : else
489 0 : DoMulArgs( ocNoName, 0 );
490 : }
491 0 : break;
492 : case 0x43:
493 : case 0x63:
494 : case 0x23: // Name [318 269]
495 : {
496 0 : aIn >> nUINT16;
497 0 : switch( meBiff )
498 : {
499 0 : case EXC_BIFF2: aIn.Ignore( 5 ); break;
500 : case EXC_BIFF3:
501 0 : case EXC_BIFF4: aIn.Ignore( 8 ); break;
502 0 : case EXC_BIFF5: aIn.Ignore( 12 ); break;
503 : default:
504 : OSL_FAIL(
505 : "-ExcelToSc::Convert(): A little oblivious?" );
506 : }
507 0 : const XclImpName* pName = GetNameManager().GetName( nUINT16 );
508 0 : if(pName && !pName->GetScRangeData())
509 0 : aStack << aPool.Store( ocMacro, pName->GetXclName() );
510 : else
511 0 : aStack << aPool.StoreName(nUINT16, true);
512 : }
513 0 : break;
514 : case 0x44:
515 : case 0x64:
516 : case 0x24: // Cell Reference [319 270]
517 : case 0x4A:
518 : case 0x6A:
519 : case 0x2A: // Deleted Cell Reference [323 273]
520 0 : aIn >> nUINT16 >> nByte;
521 0 : aSRD.nCol = static_cast<SCsCOL>(nByte);
522 0 : aSRD.nRow = nUINT16 & 0x3FFF;
523 0 : aSRD.nRelTab = 0;
524 0 : aSRD.SetTabRel( sal_True );
525 0 : aSRD.SetFlag3D( bRangeName );
526 :
527 0 : ExcRelToScRel( nUINT16, nByte, aSRD, bRangeName );
528 :
529 0 : switch ( nOp )
530 : {
531 : case 0x4A:
532 : case 0x6A:
533 : case 0x2A: // Deleted Cell Reference [323 273]
534 : // no information which part is deleted, set both
535 0 : aSRD.SetColDeleted( sal_True );
536 0 : aSRD.SetRowDeleted( sal_True );
537 : }
538 :
539 0 : aStack << aPool.Store( aSRD );
540 0 : break;
541 : case 0x45:
542 : case 0x65:
543 : case 0x25: // Area Reference [320 270]
544 : case 0x4B:
545 : case 0x6B:
546 : case 0x2B: // Deleted Area Refernce [323 273]
547 : {
548 : sal_uInt16 nRowFirst, nRowLast;
549 : sal_uInt8 nColFirst, nColLast;
550 0 : ScSingleRefData& rSRef1 = aCRD.Ref1;
551 0 : ScSingleRefData& rSRef2 = aCRD.Ref2;
552 :
553 0 : aIn >> nRowFirst >> nRowLast >> nColFirst >> nColLast;
554 :
555 0 : rSRef1.nRelTab = rSRef2.nRelTab = 0;
556 0 : rSRef1.SetTabRel( sal_True );
557 0 : rSRef2.SetTabRel( sal_True );
558 0 : rSRef1.SetFlag3D( bRangeName );
559 0 : rSRef2.SetFlag3D( bRangeName );
560 :
561 0 : ExcRelToScRel( nRowFirst, nColFirst, aCRD.Ref1, bRangeName );
562 0 : ExcRelToScRel( nRowLast, nColLast, aCRD.Ref2, bRangeName );
563 :
564 0 : if( IsComplColRange( nColFirst, nColLast ) )
565 0 : SetComplCol( aCRD );
566 0 : else if( IsComplRowRange( nRowFirst, nRowLast ) )
567 0 : SetComplRow( aCRD );
568 :
569 0 : switch ( nOp )
570 : {
571 : case 0x4B:
572 : case 0x6B:
573 : case 0x2B: // Deleted Area Refernce [323 273]
574 : // no information which part is deleted, set all
575 0 : rSRef1.SetColDeleted( sal_True );
576 0 : rSRef1.SetRowDeleted( sal_True );
577 0 : rSRef2.SetColDeleted( sal_True );
578 0 : rSRef2.SetRowDeleted( sal_True );
579 : }
580 :
581 0 : aStack << aPool.Store( aCRD );
582 : }
583 0 : break;
584 : case 0x46:
585 : case 0x66:
586 : case 0x26: // Constant Reference Subexpression [321 271]
587 0 : aExtensions.push_back( EXTENSION_MEMAREA );
588 : // fall through
589 :
590 : case 0x47:
591 : case 0x67:
592 : case 0x27: // Erroneous Constant Reference Subexpr. [322 272]
593 : case 0x48:
594 : case 0x68:
595 : case 0x28: // Incomplete Constant Reference Subexpr.[331 281]
596 0 : aIn.Ignore( (meBiff == EXC_BIFF2) ? 4 : 6 );
597 0 : break;
598 : case 0x4C:
599 : case 0x6C:
600 : case 0x2C: // Cell Reference Within a Name [323 ]
601 : // Cell Reference Within a Shared Formula[ 273]
602 : {
603 0 : aIn >> nUINT16 >> nByte; // >> Attribute, Row >> Col
604 :
605 0 : aSRD.nRelTab = 0;
606 0 : aSRD.SetTabRel( sal_True );
607 0 : aSRD.SetFlag3D( bRangeName );
608 :
609 0 : ExcRelToScRel( nUINT16, nByte, aSRD, bRNorSF );
610 :
611 0 : aStack << aPool.Store( aSRD );
612 : }
613 0 : break;
614 : case 0x4D:
615 : case 0x6D:
616 : case 0x2D: // Area Reference Within a Name [324 ]
617 : { // Area Reference Within a Shared Formula[ 274]
618 : sal_uInt16 nRowFirst, nRowLast;
619 : sal_uInt8 nColFirst, nColLast;
620 :
621 0 : aCRD.Ref1.nRelTab = aCRD.Ref2.nRelTab = 0;
622 0 : aCRD.Ref1.SetTabRel( sal_True );
623 0 : aCRD.Ref2.SetTabRel( sal_True );
624 0 : aCRD.Ref1.SetFlag3D( bRangeName );
625 0 : aCRD.Ref2.SetFlag3D( bRangeName );
626 :
627 0 : aIn >> nRowFirst >> nRowLast >> nColFirst >> nColLast;
628 :
629 0 : ExcRelToScRel( nRowFirst, nColFirst, aCRD.Ref1, bRNorSF );
630 0 : ExcRelToScRel( nRowLast, nColLast, aCRD.Ref2, bRNorSF );
631 :
632 0 : if( IsComplColRange( nColFirst, nColLast ) )
633 0 : SetComplCol( aCRD );
634 0 : else if( IsComplRowRange( nRowFirst, nRowLast ) )
635 0 : SetComplRow( aCRD );
636 :
637 0 : aStack << aPool.Store( aCRD );
638 : }
639 0 : break;
640 : case 0x49:
641 : case 0x69:
642 : case 0x29: // Variable Reference Subexpression [331 281]
643 : case 0x4E:
644 : case 0x6E:
645 : case 0x2E: // Reference Subexpression Within a Name [332 282]
646 : case 0x4F:
647 : case 0x6F:
648 : case 0x2F: // Incomplete Reference Subexpression... [332 282]
649 0 : aIn.Ignore( (meBiff == EXC_BIFF2) ? 1 : 2 );
650 0 : break;
651 : case 0x58:
652 : case 0x78:
653 : case 0x38: // Command-Equivalent Function [333 ]
654 0 : aString.AssignAscii( "COMM_EQU_FUNC" );
655 0 : aIn >> nByte;
656 0 : aString += String::CreateFromInt32( nByte );
657 0 : aIn >> nByte;
658 0 : aStack << aPool.Store( aString );
659 0 : DoMulArgs( ocPush, nByte + 1 );
660 0 : break;
661 : case 0x59:
662 : case 0x79:
663 : case 0x39: // Name or External Name [ 275]
664 0 : aIn >> nINT16;
665 0 : aIn.Ignore( 8 );
666 0 : aIn >> nUINT16;
667 0 : if( nINT16 >= 0 )
668 : {
669 0 : const ExtName* pExtName = rR.pExtNameBuff->GetNameByIndex( nINT16, nUINT16 );
670 0 : if( pExtName && pExtName->IsDDE() &&
671 0 : rR.pExtSheetBuff->IsLink( ( sal_uInt16 ) nINT16 ) )
672 : {
673 0 : String aAppl, aExtDoc;
674 0 : TokenId nPar1, nPar2;
675 :
676 0 : rR.pExtSheetBuff->GetLink( ( sal_uInt16 ) nINT16 , aAppl, aExtDoc );
677 0 : nPar1 = aPool.Store( aAppl );
678 0 : nPar2 = aPool.Store( aExtDoc );
679 0 : nMerk0 = aPool.Store( pExtName->aName );
680 0 : aPool << ocDde << ocOpen << nPar1 << ocSep << nPar2 << ocSep
681 0 : << nMerk0 << ocClose;
682 :
683 0 : GetDoc().CreateDdeLink( aAppl, aExtDoc, pExtName->aName, SC_DDE_DEFAULT, ScMatrixRef() );
684 : }
685 : else
686 0 : aPool << ocBad;
687 :
688 0 : aPool >> aStack;
689 : }
690 : else
691 0 : aStack << aPool.StoreName( nUINT16, true );
692 0 : aIn.Ignore( 12 );
693 0 : break;
694 : case 0x5A:
695 : case 0x7A:
696 : case 0x3A: // 3-D Cell Reference [ 275]
697 : case 0x5C:
698 : case 0x7C:
699 : case 0x3C: // Deleted 3-D Cell Reference [ 277]
700 : {
701 : sal_uInt16 nTabFirst, nTabLast, nRow;
702 : sal_Int16 nExtSheet;
703 : sal_uInt8 nCol;
704 :
705 0 : aIn >> nExtSheet;
706 0 : aIn.Ignore( 8 );
707 0 : aIn >> nTabFirst >> nTabLast >> nRow >> nCol;
708 :
709 0 : if( nExtSheet >= 0 )
710 : { // from external
711 0 : if( rR.pExtSheetBuff->GetScTabIndex( nExtSheet, nTabLast ) )
712 : {
713 0 : nTabFirst = nTabLast;
714 0 : nExtSheet = 0; // found
715 : }
716 : else
717 : {
718 0 : aPool << ocBad;
719 0 : aPool >> aStack;
720 0 : nExtSheet = 1; // don't create a SingleRef
721 : }
722 : }
723 :
724 0 : if( nExtSheet <= 0 )
725 : { // in current Workbook
726 0 : aSRD.nTab = static_cast<SCTAB>(nTabFirst);
727 0 : aSRD.SetFlag3D( sal_True );
728 0 : aSRD.SetTabRel( false );
729 :
730 0 : ExcRelToScRel( nRow, nCol, aSRD, bRangeName );
731 :
732 0 : switch ( nOp )
733 : {
734 : case 0x5C:
735 : case 0x7C:
736 : case 0x3C: // Deleted 3-D Cell Reference [ 277]
737 : // no information which part is deleted, set both
738 0 : aSRD.SetColDeleted( sal_True );
739 0 : aSRD.SetRowDeleted( sal_True );
740 : }
741 0 : if ( !ValidTab(static_cast<SCTAB>(nTabFirst)) )
742 0 : aSRD.SetTabDeleted( sal_True );
743 :
744 0 : if( nTabLast != nTabFirst )
745 : {
746 0 : aCRD.Ref1 = aCRD.Ref2 = aSRD;
747 0 : aCRD.Ref2.nTab = static_cast<SCTAB>(nTabLast);
748 0 : aCRD.Ref2.SetTabDeleted( !ValidTab(static_cast<SCTAB>(nTabLast)) );
749 0 : aStack << aPool.Store( aCRD );
750 : }
751 : else
752 0 : aStack << aPool.Store( aSRD );
753 : }
754 : }
755 :
756 0 : break;
757 : case 0x5B:
758 : case 0x7B:
759 : case 0x3B: // 3-D Area Reference [ 276]
760 : case 0x5D:
761 : case 0x7D:
762 : case 0x3D: // Deleted 3-D Area Reference [ 277]
763 : {
764 : sal_uInt16 nTabFirst, nTabLast, nRowFirst, nRowLast;
765 : sal_Int16 nExtSheet;
766 : sal_uInt8 nColFirst, nColLast;
767 :
768 0 : aIn >> nExtSheet;
769 0 : aIn.Ignore( 8 );
770 0 : aIn >> nTabFirst >> nTabLast >> nRowFirst >> nRowLast
771 0 : >> nColFirst >> nColLast;
772 :
773 0 : if( nExtSheet >= 0 )
774 : // von extern
775 : {
776 0 : if( rR.pExtSheetBuff->GetScTabIndex( nExtSheet, nTabLast ) )
777 : {
778 0 : nTabFirst = nTabLast;
779 0 : nExtSheet = 0; // found
780 : }
781 : else
782 : {
783 0 : aPool << ocBad;
784 0 : aPool >> aStack;
785 0 : nExtSheet = 1; // don't create a CompleteRef
786 : }
787 : }
788 :
789 0 : if( nExtSheet <= 0 )
790 : {// in current Workbook
791 : // first part of range
792 0 : ScSingleRefData& rR1 = aCRD.Ref1;
793 0 : ScSingleRefData& rR2 = aCRD.Ref2;
794 :
795 0 : rR1.nTab = static_cast<SCTAB>(nTabFirst);
796 0 : rR2.nTab = static_cast<SCTAB>(nTabLast);
797 0 : rR1.SetFlag3D( sal_True );
798 0 : rR1.SetTabRel( false );
799 0 : rR2.SetFlag3D( nTabFirst != nTabLast );
800 0 : rR2.SetTabRel( false );
801 :
802 0 : ExcRelToScRel( nRowFirst, nColFirst, aCRD.Ref1, bRangeName );
803 0 : ExcRelToScRel( nRowLast, nColLast, aCRD.Ref2, bRangeName );
804 :
805 0 : if( IsComplColRange( nColFirst, nColLast ) )
806 0 : SetComplCol( aCRD );
807 0 : else if( IsComplRowRange( nRowFirst, nRowLast ) )
808 0 : SetComplRow( aCRD );
809 :
810 0 : switch ( nOp )
811 : {
812 : case 0x5D:
813 : case 0x7D:
814 : case 0x3D: // Deleted 3-D Area Reference [ 277]
815 : // no information which part is deleted, set all
816 0 : rR1.SetColDeleted( sal_True );
817 0 : rR1.SetRowDeleted( sal_True );
818 0 : rR2.SetColDeleted( sal_True );
819 0 : rR2.SetRowDeleted( sal_True );
820 : }
821 0 : if ( !ValidTab(static_cast<SCTAB>(nTabFirst)) )
822 0 : rR1.SetTabDeleted( sal_True );
823 0 : if ( !ValidTab(static_cast<SCTAB>(nTabLast)) )
824 0 : rR2.SetTabDeleted( sal_True );
825 :
826 0 : aStack << aPool.Store( aCRD );
827 : }//END in current Workbook
828 : }
829 0 : break;
830 0 : default: bError = sal_True;
831 : }
832 0 : bError |= !aIn.IsValid();
833 : }
834 :
835 : ConvErr eRet;
836 :
837 0 : if( bError )
838 : {
839 0 : aPool << ocBad;
840 0 : aPool >> aStack;
841 0 : pErgebnis = aPool[ aStack.Get() ];
842 0 : eRet = ConvErrNi;
843 : }
844 0 : else if( aIn.GetRecPos() != nEndPos )
845 : {
846 0 : aPool << ocBad;
847 0 : aPool >> aStack;
848 0 : pErgebnis = aPool[ aStack.Get() ];
849 0 : eRet = ConvErrCount;
850 : }
851 0 : else if( bExternName )
852 : {
853 0 : pErgebnis = aPool[ aStack.Get() ];
854 0 : eRet = ConvErrExternal;
855 : }
856 0 : else if( bArrayFormula )
857 : {
858 0 : pErgebnis = NULL;
859 0 : eRet = ConvOK;
860 : }
861 : else
862 : {
863 0 : pErgebnis = aPool[ aStack.Get() ];
864 0 : eRet = ConvOK;
865 : }
866 :
867 0 : aIn.Seek( nEndPos );
868 :
869 0 : if( eRet == ConvOK )
870 0 : ReadExtensions( aExtensions, aIn );
871 :
872 0 : return eRet;
873 : }
874 :
875 :
876 : // stream seeks to first byte after <nFormulaLen>
877 0 : ConvErr ExcelToSc::Convert( _ScRangeListTabs& rRangeList, XclImpStream& aIn, sal_Size nFormulaLen,
878 : SCsTAB nTab, const FORMULA_TYPE eFT )
879 : {
880 0 : RootData& rR = GetOldRoot();
881 : sal_uInt8 nOp, nLen;
882 : sal_Size nIgnore;
883 : sal_uInt16 nUINT16;
884 : sal_uInt8 nByte;
885 0 : sal_Bool bError = false;
886 0 : const sal_Bool bRangeName = eFT == FT_RangeName;
887 0 : const sal_Bool bSharedFormula = eFT == FT_SharedFormula;
888 0 : const sal_Bool bRNorSF = bRangeName || bSharedFormula;
889 :
890 : ScSingleRefData aSRD;
891 : ScComplexRefData aCRD;
892 0 : aCRD.Ref1.nTab = aCRD.Ref2.nTab = aEingPos.Tab();
893 :
894 0 : bExternName = false;
895 :
896 0 : if( eStatus != ConvOK )
897 : {
898 0 : aIn.Ignore( nFormulaLen );
899 0 : return eStatus;
900 : }
901 :
902 0 : if( nFormulaLen == 0 )
903 0 : return ConvOK;
904 :
905 0 : sal_Size nEndPos = aIn.GetRecPos() + nFormulaLen;
906 :
907 0 : while( (aIn.GetRecPos() < nEndPos) && !bError )
908 : {
909 0 : aIn >> nOp;
910 0 : nIgnore = 0;
911 :
912 : // always reset flags
913 0 : aSRD.InitFlags();
914 0 : aCRD.InitFlags();
915 :
916 0 : switch( nOp ) // book page:
917 : { // SDK4 SDK5
918 : case 0x01: // Array Formula [325 ]
919 : // Array Formula or Shared Formula [ 277]
920 0 : nIgnore = (meBiff == EXC_BIFF2) ? 3 : 4;
921 0 : break;
922 : case 0x02: // Data Table [325 277]
923 0 : nIgnore = (meBiff == EXC_BIFF2) ? 3 : 4;
924 0 : break;
925 : case 0x03: // Addition [312 264]
926 : case 0x04: // Subtraction [313 264]
927 : case 0x05: // Multiplication [313 264]
928 : case 0x06: // Division [313 264]
929 : case 0x07: // Exponetiation [313 265]
930 : case 0x08: // Concatenation [313 265]
931 : case 0x09: // Less Than [313 265]
932 : case 0x0A: // Less Than or Equal [313 265]
933 : case 0x0B: // Equal [313 265]
934 : case 0x0C: // Greater Than or Equal [313 265]
935 : case 0x0D: // Greater Than [313 265]
936 : case 0x0E: // Not Equal [313 265]
937 : case 0x0F: // Intersection [314 265]
938 : case 0x10: // Union [314 265]
939 : case 0x11: // Range [314 265]
940 : case 0x12: // Unary Plus [312 264]
941 : case 0x13: // Unary Minus [312 264]
942 : case 0x14: // Percent Sign [312 264]
943 : case 0x15: // Parenthesis [326 278]
944 : case 0x16: // Missing Argument [314 266]
945 0 : break;
946 : case 0x17: // String Constant [314 266]
947 0 : aIn >> nLen;
948 0 : nIgnore = nLen;
949 0 : break;
950 : case 0x19: // Special Attribute [327 279]
951 : {
952 : sal_uInt16 nData, nFakt;
953 : sal_uInt8 nOpt;
954 :
955 0 : aIn >> nOpt;
956 :
957 0 : if( meBiff == EXC_BIFF2 )
958 : {
959 0 : nData = aIn.ReaduInt8();
960 0 : nFakt = 1;
961 : }
962 : else
963 : {
964 0 : aIn >> nData;
965 0 : nFakt = 2;
966 : }
967 :
968 0 : if( nOpt & 0x04 )
969 : {// nFakt -> skip bytes or words AttrChoose
970 0 : nData++;
971 0 : aIn.Ignore( nData * nFakt );
972 : }
973 : }
974 0 : break;
975 : case 0x1A: // External Reference [330 ]
976 0 : switch( meBiff )
977 : {
978 0 : case EXC_BIFF2: nIgnore = 7; break;
979 : case EXC_BIFF3:
980 0 : case EXC_BIFF4: nIgnore = 10; break;
981 : case EXC_BIFF5: DBG_WARNING( "-ExcelToSc::Convert(): 0x1A does not exist in Biff5!" );
982 : default: DBG_WARNING( "-ExcelToSc::Convert(): A little oblivious?" );
983 : }
984 0 : break;
985 : case 0x1B: // End External Reference [330 ]
986 0 : switch( meBiff )
987 : {
988 0 : case EXC_BIFF2: nIgnore = 3; break;
989 : case EXC_BIFF3:
990 0 : case EXC_BIFF4: nIgnore = 4; break;
991 : case EXC_BIFF5: DBG_WARNING( "-ExcelToSc::Convert(): 0x1B does not exist in Biff5!" );
992 : default: DBG_WARNING( "-ExcelToSc::Convert(): A little oblivious?" );
993 : }
994 0 : break;
995 : case 0x1C: // Error Value [314 266]
996 : case 0x1D: // Boolean [315 266]
997 0 : nIgnore = 1;
998 0 : break;
999 : case 0x1E: // Integer [315 266]
1000 0 : nIgnore = 2;
1001 0 : break;
1002 : case 0x1F: // Number [315 266]
1003 0 : nIgnore = 8;
1004 0 : break;
1005 : case 0x40:
1006 : case 0x60:
1007 : case 0x20: // Array Constant [317 268]
1008 0 : nIgnore = (meBiff == EXC_BIFF2) ? 6 : 7;
1009 0 : break;
1010 : case 0x41:
1011 : case 0x61:
1012 : case 0x21: // Function, Fixed Number of Arguments [333 282]
1013 0 : nIgnore = (meBiff <= EXC_BIFF3) ? 1 : 2;
1014 0 : break;
1015 : case 0x42:
1016 : case 0x62:
1017 : case 0x22: // Function, Variable Number of Arg. [333 283]
1018 0 : nIgnore = (meBiff <= EXC_BIFF3) ? 2 : 3;
1019 0 : break;
1020 : case 0x43:
1021 : case 0x63:
1022 : case 0x23: // Name [318 269]
1023 0 : switch( meBiff )
1024 : {
1025 0 : case EXC_BIFF2: nIgnore = 7; break;
1026 : case EXC_BIFF3:
1027 0 : case EXC_BIFF4: nIgnore = 10; break;
1028 0 : case EXC_BIFF5: nIgnore = 14; break;
1029 : default: OSL_FAIL( "-ExcelToSc::Convert(): A little oblivious?" );
1030 : }
1031 0 : break;
1032 : case 0x44:
1033 : case 0x64:
1034 : case 0x24: // Cell Reference [319 270]
1035 0 : aIn >> nUINT16 >> nByte;
1036 0 : aSRD.nCol = static_cast<SCsCOL>(nByte);
1037 0 : aSRD.nRow = nUINT16 & 0x3FFF;
1038 0 : aSRD.nRelTab = 0;
1039 0 : aSRD.SetTabRel( sal_True );
1040 0 : aSRD.SetFlag3D( bRangeName );
1041 :
1042 0 : ExcRelToScRel( nUINT16, nByte, aSRD, bRangeName );
1043 :
1044 0 : rRangeList.Append( aSRD, nTab );
1045 0 : break;
1046 : case 0x45:
1047 : case 0x65:
1048 : case 0x25: // Area Reference [320 270]
1049 : {
1050 : sal_uInt16 nRowFirst, nRowLast;
1051 : sal_uInt8 nColFirst, nColLast;
1052 0 : ScSingleRefData &rSRef1 = aCRD.Ref1;
1053 0 : ScSingleRefData &rSRef2 = aCRD.Ref2;
1054 :
1055 0 : aIn >> nRowFirst >> nRowLast >> nColFirst >> nColLast;
1056 :
1057 0 : rSRef1.nRelTab = rSRef2.nRelTab = 0;
1058 0 : rSRef1.SetTabRel( sal_True );
1059 0 : rSRef2.SetTabRel( sal_True );
1060 0 : rSRef1.SetFlag3D( bRangeName );
1061 0 : rSRef2.SetFlag3D( bRangeName );
1062 :
1063 0 : ExcRelToScRel( nRowFirst, nColFirst, aCRD.Ref1, bRangeName );
1064 0 : ExcRelToScRel( nRowLast, nColLast, aCRD.Ref2, bRangeName );
1065 :
1066 0 : if( IsComplColRange( nColFirst, nColLast ) )
1067 0 : SetComplCol( aCRD );
1068 0 : else if( IsComplRowRange( nRowFirst, nRowLast ) )
1069 0 : SetComplRow( aCRD );
1070 :
1071 0 : rRangeList.Append( aCRD, nTab );
1072 : }
1073 0 : break;
1074 : case 0x46:
1075 : case 0x66:
1076 : case 0x26: // Constant Reference Subexpression [321 271]
1077 : case 0x47:
1078 : case 0x67:
1079 : case 0x27: // Erroneous Constant Reference Subexpr. [322 272]
1080 : case 0x48:
1081 : case 0x68:
1082 : case 0x28: // Incomplete Constant Reference Subexpr.[331 281]
1083 0 : nIgnore = (meBiff == EXC_BIFF2) ? 4 : 6;
1084 0 : break;
1085 : case 0x4A:
1086 : case 0x6A:
1087 : case 0x2A: // Deleted Cell Reference [323 273]
1088 0 : nIgnore = 3;
1089 0 : break;
1090 : case 0x4B:
1091 : case 0x6B:
1092 : case 0x2B: // Deleted Area Refernce [323 273]
1093 0 : nIgnore = 6;
1094 0 : break;
1095 : case 0x4C:
1096 : case 0x6C:
1097 : case 0x2C: // Cell Reference Within a Name [323 ]
1098 : // Cell Reference Within a Shared Formula[ 273]
1099 : {
1100 0 : aIn >> nUINT16 >> nByte; // >> Attribute, Row >> Col
1101 :
1102 0 : aSRD.nRelTab = 0;
1103 0 : aSRD.SetTabRel( sal_True );
1104 0 : aSRD.SetFlag3D( bRangeName );
1105 :
1106 0 : ExcRelToScRel( nUINT16, nByte, aSRD, bRNorSF );
1107 :
1108 0 : rRangeList.Append( aSRD, nTab );
1109 : }
1110 0 : break;
1111 : case 0x4D:
1112 : case 0x6D:
1113 : case 0x2D: // Area Reference Within a Name [324 ]
1114 : { // Area Reference Within a Shared Formula[ 274]
1115 : sal_uInt16 nRowFirst, nRowLast;
1116 : sal_uInt8 nColFirst, nColLast;
1117 :
1118 0 : aCRD.Ref1.nRelTab = aCRD.Ref2.nRelTab = 0;
1119 0 : aCRD.Ref1.SetTabRel( sal_True );
1120 0 : aCRD.Ref2.SetTabRel( sal_True );
1121 0 : aCRD.Ref1.SetFlag3D( bRangeName );
1122 0 : aCRD.Ref2.SetFlag3D( bRangeName );
1123 :
1124 0 : aIn >> nRowFirst >> nRowLast >> nColFirst >> nColLast;
1125 :
1126 0 : ExcRelToScRel( nRowFirst, nColFirst, aCRD.Ref1, bRNorSF );
1127 0 : ExcRelToScRel( nRowLast, nColLast, aCRD.Ref2, bRNorSF );
1128 :
1129 0 : if( IsComplColRange( nColFirst, nColLast ) )
1130 0 : SetComplCol( aCRD );
1131 0 : else if( IsComplRowRange( nRowFirst, nRowLast ) )
1132 0 : SetComplRow( aCRD );
1133 :
1134 0 : rRangeList.Append( aCRD, nTab );
1135 : }
1136 0 : break;
1137 : case 0x49:
1138 : case 0x69:
1139 : case 0x29: // Variable Reference Subexpression [331 281]
1140 : case 0x4E:
1141 : case 0x6E:
1142 : case 0x2E: // Reference Subexpression Within a Name [332 282]
1143 : case 0x4F:
1144 : case 0x6F:
1145 : case 0x2F: // Incomplete Reference Subexpression... [332 282]
1146 0 : nIgnore = (meBiff == EXC_BIFF2) ? 1 : 2;
1147 0 : break;
1148 : case 0x58:
1149 : case 0x78:
1150 : case 0x38: // Command-Equivalent Function [333 ]
1151 0 : nIgnore = 2;
1152 0 : break;
1153 : case 0x59:
1154 : case 0x79:
1155 : case 0x39: // Name or External Name [ 275]
1156 0 : nIgnore = 24;
1157 0 : break;
1158 : case 0x5A:
1159 : case 0x7A:
1160 : case 0x3A: // 3-D Cell Reference [ 275]
1161 : {
1162 : sal_uInt16 nTabFirst, nTabLast, nRow;
1163 : sal_Int16 nExtSheet;
1164 : sal_uInt8 nCol;
1165 :
1166 0 : aIn >> nExtSheet;
1167 0 : aIn.Ignore( 8 );
1168 0 : aIn >> nTabFirst >> nTabLast >> nRow >> nCol;
1169 :
1170 0 : if( nExtSheet >= 0 )
1171 : // from external
1172 : {
1173 0 : if( rR.pExtSheetBuff->GetScTabIndex( nExtSheet, nTabLast ) )
1174 : {
1175 0 : nTabFirst = nTabLast;
1176 0 : nExtSheet = 0; // found
1177 : }
1178 : else
1179 : {
1180 0 : aPool << ocBad;
1181 0 : aPool >> aStack;
1182 0 : nExtSheet = 1; // don't create a SingleRef
1183 : }
1184 : }
1185 :
1186 0 : if( nExtSheet <= 0 )
1187 : {// in current Workbook
1188 0 : sal_Bool b3D = ( static_cast<SCTAB>(nTabFirst) != aEingPos.Tab() ) || bRangeName;
1189 0 : aSRD.nTab = static_cast<SCTAB>(nTabFirst);
1190 0 : aSRD.SetFlag3D( b3D );
1191 0 : aSRD.SetTabRel( false );
1192 :
1193 0 : ExcRelToScRel( nRow, nCol, aSRD, bRangeName );
1194 :
1195 0 : if( nTabLast != nTabFirst )
1196 : {
1197 0 : aCRD.Ref1 = aSRD;
1198 0 : aCRD.Ref2.nCol = aSRD.nCol;
1199 0 : aCRD.Ref2.nRow = aSRD.nRow;
1200 0 : aCRD.Ref2.nTab = static_cast<SCTAB>(nTabLast);
1201 0 : b3D = ( static_cast<SCTAB>(nTabLast) != aEingPos.Tab() );
1202 0 : aCRD.Ref2.SetFlag3D( b3D );
1203 0 : aCRD.Ref2.SetTabRel( false );
1204 0 : rRangeList.Append( aCRD, nTab );
1205 : }
1206 : else
1207 0 : rRangeList.Append( aSRD, nTab );
1208 : }
1209 : }
1210 :
1211 0 : break;
1212 : case 0x5B:
1213 : case 0x7B:
1214 : case 0x3B: // 3-D Area Reference [ 276]
1215 : {
1216 : sal_uInt16 nTabFirst, nTabLast, nRowFirst, nRowLast;
1217 : sal_Int16 nExtSheet;
1218 : sal_uInt8 nColFirst, nColLast;
1219 :
1220 0 : aIn >> nExtSheet;
1221 0 : aIn.Ignore( 8 );
1222 0 : aIn >> nTabFirst >> nTabLast >> nRowFirst >> nRowLast
1223 0 : >> nColFirst >> nColLast;
1224 :
1225 0 : if( nExtSheet >= 0 )
1226 : // from external
1227 : {
1228 0 : if( rR.pExtSheetBuff->GetScTabIndex( nExtSheet, nTabLast ) )
1229 : {
1230 0 : nTabFirst = nTabLast;
1231 0 : nExtSheet = 0; // found
1232 : }
1233 : else
1234 : {
1235 0 : aPool << ocBad;
1236 0 : aPool >> aStack;
1237 0 : nExtSheet = 1; // don't create a CompleteRef
1238 : }
1239 : }
1240 :
1241 0 : if( nExtSheet <= 0 )
1242 : {// in current Workbook
1243 : // first part of range
1244 0 : ScSingleRefData &rR1 = aCRD.Ref1;
1245 0 : ScSingleRefData &rR2 = aCRD.Ref2;
1246 :
1247 0 : rR1.nTab = static_cast<SCTAB>(nTabFirst);
1248 0 : rR2.nTab = static_cast<SCTAB>(nTabLast);
1249 0 : rR1.SetFlag3D( ( static_cast<SCTAB>(nTabFirst) != aEingPos.Tab() ) || bRangeName );
1250 0 : rR1.SetTabRel( false );
1251 0 : rR2.SetFlag3D( ( static_cast<SCTAB>(nTabLast) != aEingPos.Tab() ) || bRangeName );
1252 0 : rR2.SetTabRel( false );
1253 :
1254 0 : ExcRelToScRel( nRowFirst, nColFirst, aCRD.Ref1, bRangeName );
1255 0 : ExcRelToScRel( nRowLast, nColLast, aCRD.Ref2, bRangeName );
1256 :
1257 0 : if( IsComplColRange( nColFirst, nColLast ) )
1258 0 : SetComplCol( aCRD );
1259 0 : else if( IsComplRowRange( nRowFirst, nRowLast ) )
1260 0 : SetComplRow( aCRD );
1261 :
1262 0 : rRangeList.Append( aCRD, nTab );
1263 : }//END in current Workbook
1264 : }
1265 0 : break;
1266 : case 0x5C:
1267 : case 0x7C:
1268 : case 0x3C: // Deleted 3-D Cell Reference [ 277]
1269 0 : nIgnore = 17;
1270 0 : break;
1271 : case 0x5D:
1272 : case 0x7D:
1273 : case 0x3D: // Deleted 3-D Area Reference [ 277]
1274 0 : nIgnore = 20;
1275 0 : break;
1276 0 : default: bError = sal_True;
1277 : }
1278 0 : bError |= !aIn.IsValid();
1279 :
1280 0 : aIn.Ignore( nIgnore );
1281 : }
1282 :
1283 : ConvErr eRet;
1284 :
1285 0 : if( bError )
1286 0 : eRet = ConvErrNi;
1287 0 : else if( aIn.GetRecPos() != nEndPos )
1288 0 : eRet = ConvErrCount;
1289 0 : else if( bExternName )
1290 0 : eRet = ConvErrExternal;
1291 : else
1292 0 : eRet = ConvOK;
1293 :
1294 0 : aIn.Seek( nEndPos );
1295 0 : return eRet;
1296 : }
1297 :
1298 0 : ConvErr ExcelToSc::ConvertExternName( const ScTokenArray*& /*rpArray*/, XclImpStream& /*rStrm*/, sal_Size /*nFormulaLen*/,
1299 : const String& /*rUrl*/, const vector<String>& /*rTabNames*/ )
1300 : {
1301 : // not implemented ...
1302 0 : return ConvErrNi;
1303 : }
1304 :
1305 0 : sal_Bool ExcelToSc::GetAbsRefs( ScRangeList& rRangeList, XclImpStream& rStrm, sal_Size nLen )
1306 : {
1307 : OSL_ENSURE_BIFF( GetBiff() == EXC_BIFF5 );
1308 0 : if( GetBiff() != EXC_BIFF5 )
1309 0 : return false;
1310 :
1311 : sal_uInt8 nOp;
1312 : sal_uInt16 nRow1, nRow2;
1313 : sal_uInt8 nCol1, nCol2;
1314 : SCTAB nTab1, nTab2;
1315 : sal_uInt16 nTabFirst, nTabLast;
1316 : sal_Int16 nRefIdx;
1317 :
1318 : sal_Size nSeek;
1319 0 : sal_Size nEndPos = rStrm.GetRecPos() + nLen;
1320 :
1321 0 : while( rStrm.IsValid() && (rStrm.GetRecPos() < nEndPos) )
1322 : {
1323 0 : rStrm >> nOp;
1324 0 : nSeek = 0;
1325 :
1326 0 : switch( nOp )
1327 : {
1328 : case 0x44:
1329 : case 0x64:
1330 : case 0x24: // Cell Reference [319 270]
1331 : case 0x4C:
1332 : case 0x6C:
1333 : case 0x2C: // Cell Reference Within a Name [323 ]
1334 : // Cell Reference Within a Shared Formula[ 273]
1335 0 : rStrm >> nRow1 >> nCol1;
1336 :
1337 0 : nRow2 = nRow1;
1338 0 : nCol2 = nCol1;
1339 0 : nTab1 = nTab2 = GetCurrScTab();
1340 0 : goto _common;
1341 : case 0x45:
1342 : case 0x65:
1343 : case 0x25: // Area Reference [320 270]
1344 : case 0x4D:
1345 : case 0x6D:
1346 : case 0x2D: // Area Reference Within a Name [324 ]
1347 : // Area Reference Within a Shared Formula[ 274]
1348 0 : rStrm >> nRow1 >> nRow2 >> nCol1 >> nCol2;
1349 :
1350 0 : nTab1 = nTab2 = GetCurrScTab();
1351 0 : goto _common;
1352 : case 0x5A:
1353 : case 0x7A:
1354 : case 0x3A: // 3-D Cell Reference [ 275]
1355 0 : rStrm >> nRefIdx;
1356 0 : rStrm.Ignore( 8 );
1357 0 : rStrm >> nTabFirst >> nTabLast >> nRow1 >> nCol1;
1358 :
1359 0 : nRow2 = nRow1;
1360 0 : nCol2 = nCol1;
1361 :
1362 0 : goto _3d_common;
1363 : case 0x5B:
1364 : case 0x7B:
1365 : case 0x3B: // 3-D Area Reference [ 276]
1366 0 : rStrm >> nRefIdx;
1367 0 : rStrm.Ignore( 8 );
1368 0 : rStrm >> nTabFirst >> nTabLast >> nRow1 >> nRow2 >> nCol1 >> nCol2;
1369 :
1370 : _3d_common:
1371 0 : nTab1 = static_cast< SCTAB >( nTabFirst );
1372 0 : nTab2 = static_cast< SCTAB >( nTabLast );
1373 :
1374 : // skip references to deleted sheets
1375 0 : if( (nRefIdx >= 0) || !ValidTab( nTab1 ) || (nTab1 != nTab2) )
1376 0 : break;
1377 :
1378 0 : goto _common;
1379 : _common:
1380 : // do not check abs/rel flags, linked controls have set them!
1381 : {
1382 0 : ScRange aScRange;
1383 0 : nRow1 &= 0x3FFF;
1384 0 : nRow2 &= 0x3FFF;
1385 0 : if( GetAddressConverter().ConvertRange( aScRange, XclRange( nCol1, nRow1, nCol2, nRow2 ), nTab1, nTab2, true ) )
1386 0 : rRangeList.Append( aScRange );
1387 : }
1388 0 : break;
1389 :
1390 : case 0x03: // Addition [312 264]
1391 : case 0x04: // Subtraction [313 264]
1392 : case 0x05: // Multiplication [313 264]
1393 : case 0x06: // Division [313 264]
1394 : case 0x07: // Exponetiation [313 265]
1395 : case 0x08: // Concatenation [313 265]
1396 : case 0x09: // Less Than [313 265]
1397 : case 0x0A: // Less Than or Equal [313 265]
1398 : case 0x0B: // Equal [313 265]
1399 : case 0x0C: // Greater Than or Equal [313 265]
1400 : case 0x0D: // Greater Than [313 265]
1401 : case 0x0E: // Not Equal [313 265]
1402 : case 0x0F: // Intersection [314 265]
1403 : case 0x10: // Union [314 265]
1404 : case 0x11: // Range [314 265]
1405 : case 0x12: // Unary Plus [312 264]
1406 : case 0x13: // Unary Minus [312 264]
1407 : case 0x14: // Percent Sign [312 264]
1408 : case 0x15: // Parenthesis [326 278]
1409 : case 0x16: // Missing Argument [314 266]
1410 0 : break;
1411 : case 0x1C: // Error Value [314 266]
1412 : case 0x1D: // Boolean [315 266]
1413 0 : nSeek = 1;
1414 0 : break;
1415 : case 0x1E: // Integer [315 266]
1416 : case 0x41:
1417 : case 0x61:
1418 : case 0x21: // Function, Fixed Number of Arguments [333 282]
1419 : case 0x49:
1420 : case 0x69:
1421 : case 0x29: // Variable Reference Subexpression [331 281]
1422 : case 0x4E:
1423 : case 0x6E:
1424 : case 0x2E: // Reference Subexpression Within a Name [332 282]
1425 : case 0x4F:
1426 : case 0x6F:
1427 : case 0x2F: // Incomplete Reference Subexpression... [332 282]
1428 : case 0x58:
1429 : case 0x78:
1430 : case 0x38: // Command-Equivalent Function [333 ]
1431 0 : nSeek = 2;
1432 0 : break;
1433 : case 0x42:
1434 : case 0x62:
1435 : case 0x22: // Function, Variable Number of Arg. [333 283]
1436 : case 0x4A:
1437 : case 0x6A:
1438 : case 0x2A: // Deleted Cell Reference [323 273]
1439 0 : nSeek = 3;
1440 0 : break;
1441 : case 0x01: // Array Formula [325 ]
1442 : // Array Formula or Shared Formula [ 277]
1443 : case 0x02: // Data Table [325 277]
1444 0 : nSeek = 4;
1445 0 : break;
1446 : case 0x46:
1447 : case 0x66:
1448 : case 0x26: // Constant Reference Subexpression [321 271]
1449 : case 0x47:
1450 : case 0x67:
1451 : case 0x27: // Erroneous Constant Reference Subexpr. [322 272]
1452 : case 0x48:
1453 : case 0x68:
1454 : case 0x28: // Incomplete Constant Reference Subexpr.[331 281]
1455 : case 0x4B:
1456 : case 0x6B:
1457 : case 0x2B: // Deleted Area Refernce [323 273]
1458 0 : nSeek = 6;
1459 0 : break;
1460 : case 0x40:
1461 : case 0x60:
1462 : case 0x20: // Array Constant [317 268]
1463 0 : nSeek = 7;
1464 0 : break;
1465 : case 0x1F: // Number [315 266]
1466 0 : nSeek = 8;
1467 0 : break;
1468 : case 0x43:
1469 : case 0x63:
1470 : case 0x23: // Name [318 269]
1471 0 : nSeek = 14;
1472 0 : break;
1473 : case 0x5C:
1474 : case 0x7C:
1475 : case 0x3C: // Deleted 3-D Cell Reference [ 277]
1476 0 : nSeek = 17;
1477 0 : break;
1478 : case 0x5D:
1479 : case 0x7D:
1480 : case 0x3D: // Deleted 3-D Area Reference [ 277]
1481 0 : nSeek = 20;
1482 0 : break;
1483 : case 0x59:
1484 : case 0x79:
1485 : case 0x39: // Name or External Name [ 275]
1486 0 : nSeek = 24;
1487 0 : break;
1488 : case 0x17: // String Constant [314 266]
1489 0 : nSeek = rStrm.ReaduInt8();
1490 0 : break;
1491 : case 0x19: // Special Attribute [327 279]
1492 : {
1493 : sal_uInt8 nOpt;
1494 : sal_uInt16 nData;
1495 0 : rStrm >> nOpt >> nData;
1496 0 : if( nOpt & 0x04 )
1497 0 : nSeek = nData * 2 + 2;
1498 : }
1499 0 : break;
1500 : }
1501 :
1502 0 : rStrm.Ignore( nSeek );
1503 : }
1504 0 : rStrm.Seek( nEndPos );
1505 :
1506 0 : return !rRangeList.empty();
1507 : }
1508 :
1509 3079 : void ExcelToSc::DoMulArgs( DefTokenId eId, sal_uInt8 nAnz )
1510 : {
1511 3079 : TokenId eParam[ 256 ];
1512 : sal_Int32 nLauf;
1513 :
1514 3079 : if( eId == ocCeil || eId == ocFloor )
1515 : {
1516 0 : aStack << aPool.Store( 1.0 ); // default, because not present in Excel
1517 0 : nAnz++;
1518 : }
1519 :
1520 8988 : for( nLauf = 0; aStack.HasMoreTokens() && (nLauf < nAnz); nLauf++ )
1521 5909 : aStack >> eParam[ nLauf ];
1522 : // #i70925# reduce parameter count, if no more tokens available on token stack
1523 3079 : if( nLauf < nAnz )
1524 0 : nAnz = static_cast< sal_uInt8 >( nLauf );
1525 :
1526 3079 : if( nAnz > 0 && eId == ocExternal )
1527 : {
1528 1 : TokenId n = eParam[ nAnz - 1 ];
1529 : //##### GRUETZE FUER BASIC-FUNCS RICHTEN!
1530 1 : if( const String* pExt = aPool.GetExternal( n ) )
1531 : {
1532 1 : if( const XclFunctionInfo* pFuncInfo = maFuncProv.GetFuncInfoFromXclMacroName( *pExt ) )
1533 0 : aPool << pFuncInfo->meOpCode;
1534 : else
1535 1 : aPool << n;
1536 1 : nAnz--;
1537 : }
1538 : else
1539 0 : aPool << eId;
1540 : }
1541 : else
1542 3078 : aPool << eId;
1543 :
1544 3079 : aPool << ocOpen;
1545 :
1546 3079 : if( nAnz > 0 )
1547 : {
1548 : // attention: 0 = last parameter, nAnz-1 = first parameter
1549 3079 : sal_Int16 nSkipEnd = -1; // skip all parameters <= nSkipEnd
1550 :
1551 3079 : sal_Int16 nLast = nAnz - 1;
1552 :
1553 : // functions for which parameters have to be skipped
1554 3079 : if( eId == ocPercentrank && nAnz == 3 )
1555 0 : nSkipEnd = 0; // skip last parameter if necessary
1556 :
1557 : // Joost special cases
1558 3079 : else if( eId == ocIf )
1559 : {
1560 1 : sal_uInt16 nNullParam = 0;
1561 4 : for( nLauf = 0 ; nLauf < nAnz ; nLauf++ )
1562 : {
1563 3 : if( aPool.IsSingleOp( eParam[ nLauf ], ocMissing ) )
1564 : {
1565 0 : if( !nNullParam )
1566 0 : nNullParam = (sal_uInt16) aPool.Store( ( double ) 0.0 );
1567 0 : eParam[ nLauf ] = nNullParam;
1568 : }
1569 : }
1570 : }
1571 :
1572 : // [Parameter{;Parameter}]
1573 3079 : if( nLast > nSkipEnd )
1574 : {
1575 3079 : sal_Int16 nNull = -1; // skip this parameter
1576 3079 : aPool << eParam[ nLast ];
1577 5908 : for( nLauf = nLast - 1 ; nLauf > nSkipEnd ; nLauf-- )
1578 : {
1579 2829 : if( nLauf != nNull )
1580 2829 : aPool << ocSep << eParam[ nLauf ];
1581 : }
1582 : }
1583 : }
1584 3079 : aPool << ocClose;
1585 :
1586 3079 : aPool >> aStack;
1587 3079 : }
1588 :
1589 :
1590 0 : void ExcelToSc::ExcRelToScRel( sal_uInt16 nRow, sal_uInt8 nCol, ScSingleRefData &rSRD, const sal_Bool bName )
1591 : {
1592 0 : if( bName )
1593 : {
1594 : // C O L
1595 0 : if( nRow & 0x4000 )
1596 : {// rel Col
1597 0 : rSRD.SetColRel( sal_True );
1598 0 : rSRD.nRelCol = static_cast<SCsCOL>(static_cast<sal_Int8>(nCol));
1599 : }
1600 : else
1601 : {// abs Col
1602 0 : rSRD.SetColRel( false );
1603 0 : rSRD.nCol = static_cast<SCCOL>(nCol);
1604 : }
1605 :
1606 : // R O W
1607 0 : if( nRow & 0x8000 )
1608 : {// rel Row
1609 0 : rSRD.SetRowRel( sal_True );
1610 0 : if( nRow & 0x2000 ) // Bit 13 set?
1611 : // -> Row negative
1612 0 : rSRD.nRelRow = static_cast<SCsROW>(static_cast<sal_Int16>(nRow | 0xC000));
1613 : else
1614 : // -> Row positive
1615 0 : rSRD.nRelRow = static_cast<SCsROW>(nRow & nRowMask);
1616 : }
1617 : else
1618 : {// abs Row
1619 0 : rSRD.SetRowRel( false );
1620 0 : rSRD.nRow = static_cast<SCROW>(nRow & nRowMask);
1621 : }
1622 :
1623 : // T A B
1624 : // abs needed if rel in shared formula for ScCompiler UpdateNameReference
1625 0 : if ( rSRD.IsTabRel() && !rSRD.IsFlag3D() )
1626 0 : rSRD.nTab = GetCurrScTab();
1627 : }
1628 : else
1629 : {
1630 : // C O L
1631 0 : rSRD.SetColRel( ( nRow & 0x4000 ) > 0 );
1632 0 : rSRD.nCol = static_cast<SCsCOL>(nCol);
1633 :
1634 : // R O W
1635 0 : rSRD.SetRowRel( ( nRow & 0x8000 ) > 0 );
1636 0 : rSRD.nRow = static_cast<SCsROW>(nRow & nRowMask);
1637 :
1638 0 : if ( rSRD.IsColRel() )
1639 0 : rSRD.nRelCol = rSRD.nCol - aEingPos.Col();
1640 0 : if ( rSRD.IsRowRel() )
1641 0 : rSRD.nRelRow = rSRD.nRow - aEingPos.Row();
1642 :
1643 : // T A B
1644 : // #i10184# abs needed if rel in shared formula for ScCompiler UpdateNameReference
1645 0 : if ( rSRD.IsTabRel() && !rSRD.IsFlag3D() )
1646 0 : rSRD.nTab = GetCurrScTab() + rSRD.nRelTab;
1647 : }
1648 0 : }
1649 :
1650 :
1651 0 : const ScTokenArray* ExcelToSc::GetBoolErr( XclBoolError eType )
1652 : {
1653 : sal_uInt16 nError;
1654 0 : aPool.Reset();
1655 0 : aStack.Reset();
1656 :
1657 : DefTokenId eOc;
1658 :
1659 0 : switch( eType )
1660 : {
1661 0 : case xlErrNull: eOc = ocStop; nError = errNoCode; break;
1662 0 : case xlErrDiv0: eOc = ocStop; nError = errDivisionByZero; break;
1663 0 : case xlErrValue: eOc = ocStop; nError = errNoValue; break;
1664 0 : case xlErrRef: eOc = ocStop; nError = errNoRef; break;
1665 0 : case xlErrName: eOc = ocStop; nError = errNoName; break;
1666 0 : case xlErrNum: eOc = ocStop; nError = errIllegalFPOperation; break;
1667 0 : case xlErrNA: eOc = ocNotAvail; nError = NOTAVAILABLE; break;
1668 0 : case xlErrTrue: eOc = ocTrue; nError = 0; break;
1669 0 : case xlErrFalse: eOc = ocFalse; nError = 0; break;
1670 0 : case xlErrUnknown: eOc = ocStop; nError = errUnknownState; break;
1671 : default:
1672 : OSL_FAIL( "ExcelToSc::GetBoolErr - wrong enum!" );
1673 0 : eOc = ocNoName;
1674 0 : nError = errUnknownState;
1675 : }
1676 :
1677 0 : aPool << eOc;
1678 0 : if( eOc != ocStop )
1679 0 : aPool << ocOpen << ocClose;
1680 :
1681 0 : aPool >> aStack;
1682 :
1683 0 : const ScTokenArray* pErgebnis = aPool[ aStack.Get() ];
1684 0 : if( nError )
1685 0 : ( ( ScTokenArray* ) pErgebnis )->SetCodeError( nError );
1686 :
1687 0 : ( ( ScTokenArray* ) pErgebnis )->SetRecalcModeNormal();
1688 :
1689 0 : return pErgebnis;
1690 : }
1691 :
1692 :
1693 : // if a shared formula was found, stream seeks to first byte after <nFormulaLen>,
1694 : // else stream pointer stays unchanged
1695 328 : sal_Bool ExcelToSc::GetShrFmla( const ScTokenArray*& rpErgebnis, XclImpStream& aIn, sal_Size nFormulaLen )
1696 : {
1697 : sal_uInt8 nOp;
1698 328 : sal_Bool bRet = sal_True;
1699 :
1700 328 : if( nFormulaLen == 0 )
1701 0 : bRet = false;
1702 : else
1703 : {
1704 328 : aIn.PushPosition();
1705 :
1706 328 : aIn >> nOp;
1707 :
1708 328 : if( nOp == 0x01 ) // Shared Formula [ 277]
1709 : {
1710 : sal_uInt16 nCol, nRow;
1711 :
1712 80 : aIn >> nRow >> nCol;
1713 :
1714 80 : aStack << aPool.StoreName( GetOldRoot().pShrfmlaBuff->Find(
1715 160 : ScAddress(static_cast<SCCOL>(nCol), static_cast<SCROW>(nRow), GetCurrScTab())), true);
1716 :
1717 80 : bRet = sal_True;
1718 : }
1719 : else
1720 248 : bRet = false;
1721 :
1722 328 : aIn.PopPosition();
1723 : }
1724 :
1725 328 : if( bRet )
1726 : {
1727 80 : aIn.Ignore( nFormulaLen );
1728 80 : rpErgebnis = aPool[ aStack.Get() ];
1729 : }
1730 : else
1731 248 : rpErgebnis = NULL;
1732 :
1733 328 : return bRet;
1734 : }
1735 :
1736 :
1737 1 : void ExcelToSc::SetError( ScFormulaCell &rCell, const ConvErr eErr )
1738 : {
1739 : sal_uInt16 nInd;
1740 :
1741 1 : switch( eErr )
1742 : {
1743 1 : case ConvErrNi: nInd = errUnknownToken; break;
1744 0 : case ConvErrNoMem: nInd = errCodeOverflow; break;
1745 0 : case ConvErrExternal: nInd = errNoName; break;
1746 0 : case ConvErrCount: nInd = errCodeOverflow; break;
1747 0 : default: nInd = errNoCode; // I had no better idea
1748 : }
1749 :
1750 1 : rCell.SetErrCode( nInd );
1751 1 : }
1752 :
1753 :
1754 0 : void ExcelToSc::SetComplCol( ScComplexRefData &rCRD )
1755 : {
1756 0 : ScSingleRefData &rSRD = rCRD.Ref2;
1757 0 : if( rSRD.IsColRel() )
1758 0 : rSRD.nRelCol = MAXCOL - aEingPos.Col();
1759 : else
1760 0 : rSRD.nCol = MAXCOL;
1761 0 : }
1762 :
1763 :
1764 0 : void ExcelToSc::SetComplRow( ScComplexRefData &rCRD )
1765 : {
1766 0 : ScSingleRefData &rSRD = rCRD.Ref2;
1767 0 : if( rSRD.IsRowRel() )
1768 0 : rSRD.nRelRow = MAXROW - aEingPos.Row();
1769 : else
1770 0 : rSRD.nRow = MAXROW;
1771 0 : }
1772 :
1773 1 : void ExcelToSc::ReadExtensionArray( unsigned int n, XclImpStream& aIn )
1774 : {
1775 : sal_uInt8 nByte;
1776 : sal_uInt16 nUINT16;
1777 : double fDouble;
1778 1 : String aString;
1779 : ScMatrix* pMatrix;
1780 :
1781 1 : aIn >> nByte >> nUINT16;
1782 :
1783 : SCSIZE nC, nCols;
1784 : SCSIZE nR, nRows;
1785 1 : if( GetBiff() == EXC_BIFF8 )
1786 : {
1787 1 : nCols = nByte + 1;
1788 1 : nRows = nUINT16 + 1;
1789 : }
1790 : else
1791 : {
1792 0 : nCols = nByte ? nByte : 256;
1793 0 : nRows = nUINT16;
1794 : }
1795 :
1796 1 : pMatrix = aPool.GetMatrix( n );
1797 :
1798 1 : if( NULL != pMatrix )
1799 : {
1800 1 : pMatrix->Resize(nCols, nRows);
1801 1 : pMatrix->GetDimensions( nC, nR);
1802 1 : if( nC != nCols || nR != nRows )
1803 : {
1804 : OSL_FAIL( "ExcelToSc::ReadExtensionArray - matrix size mismatch" );
1805 0 : pMatrix = NULL;
1806 : }
1807 : }
1808 : else
1809 : {
1810 : OSL_FAIL( "ExcelToSc::ReadExtensionArray - missing matrix" );
1811 : }
1812 :
1813 3 : for( nR = 0 ; nR < nRows; nR++ )
1814 : {
1815 8 : for( nC = 0 ; nC < nCols; nC++ )
1816 : {
1817 6 : aIn >> nByte;
1818 6 : switch( nByte )
1819 : {
1820 : case EXC_CACHEDVAL_EMPTY:
1821 0 : aIn.Ignore( 8 );
1822 0 : if( NULL != pMatrix )
1823 : {
1824 0 : pMatrix->PutEmpty( nC, nR );
1825 : }
1826 0 : break;
1827 :
1828 : case EXC_CACHEDVAL_DOUBLE:
1829 6 : aIn >> fDouble;
1830 6 : if( NULL != pMatrix )
1831 : {
1832 6 : pMatrix->PutDouble( fDouble, nC, nR );
1833 : }
1834 6 : break;
1835 :
1836 : case EXC_CACHEDVAL_STRING:
1837 0 : if( GetBiff() == EXC_BIFF8 )
1838 : {
1839 0 : aIn >> nUINT16;
1840 0 : aString = aIn.ReadUniString( nUINT16 );
1841 : }
1842 : else
1843 : {
1844 0 : aIn >> nByte;
1845 0 : aString = aIn.ReadRawByteString( nByte );
1846 : }
1847 0 : if( NULL != pMatrix )
1848 : {
1849 0 : pMatrix->PutString( aString, nC, nR );
1850 : }
1851 0 : break;
1852 :
1853 : case EXC_CACHEDVAL_BOOL:
1854 0 : aIn >> nByte;
1855 0 : aIn.Ignore( 7 );
1856 0 : if( NULL != pMatrix )
1857 : {
1858 0 : pMatrix->PutBoolean( nByte != 0, nC, nR );
1859 : }
1860 0 : break;
1861 :
1862 : case EXC_CACHEDVAL_ERROR:
1863 0 : aIn >> nByte;
1864 0 : aIn.Ignore( 7 );
1865 0 : if( NULL != pMatrix )
1866 : {
1867 0 : pMatrix->PutError( XclTools::GetScErrorCode( nByte ), nC, nR );
1868 : }
1869 0 : break;
1870 : }
1871 : }
1872 1 : }
1873 1 : }
1874 :
1875 0 : void ExcelToSc::ReadExtensionNlr( XclImpStream& aIn )
1876 : {
1877 : sal_uInt32 nFlags;
1878 0 : aIn >> nFlags;
1879 :
1880 0 : sal_uInt32 nCount = nFlags & EXC_TOK_NLR_ADDMASK;
1881 0 : aIn.Ignore( nCount * 4 ); // Drop the cell positions
1882 0 : }
1883 :
1884 0 : void ExcelToSc::ReadExtensionMemArea( XclImpStream& aIn )
1885 : {
1886 : sal_uInt16 nCount;
1887 0 : aIn >> nCount;
1888 :
1889 0 : aIn.Ignore( nCount * ((GetBiff() == EXC_BIFF8) ? 8 : 6) ); // drop the ranges
1890 0 : }
1891 :
1892 2498 : void ExcelToSc::ReadExtensions( const ExtensionTypeVec& rExtensions,
1893 : XclImpStream& aIn )
1894 : {
1895 2498 : unsigned int nArray = 0;
1896 :
1897 2499 : for( unsigned int i = 0 ; i < rExtensions.size() ; i++ )
1898 : {
1899 1 : ExtensionType eType = rExtensions[i];
1900 :
1901 1 : switch( eType )
1902 : {
1903 : case EXTENSION_ARRAY:
1904 1 : ReadExtensionArray( nArray++, aIn );
1905 1 : break;
1906 :
1907 : case EXTENSION_NLR:
1908 0 : ReadExtensionNlr( aIn );
1909 0 : break;
1910 :
1911 : case EXTENSION_MEMAREA:
1912 0 : ReadExtensionMemArea( aIn );
1913 0 : break;
1914 : }
1915 : }
1916 2507 : }
1917 :
1918 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|