LCOV - code coverage report
Current view: top level - sc/source/filter/excel - excform.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 284 937 30.3 %
Date: 2015-06-13 12:38:46 Functions: 16 26 61.5 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.11