1*b1cdbd2cSJim Jagielski /************************************************************** 2*b1cdbd2cSJim Jagielski * 3*b1cdbd2cSJim Jagielski * Licensed to the Apache Software Foundation (ASF) under one 4*b1cdbd2cSJim Jagielski * or more contributor license agreements. See the NOTICE file 5*b1cdbd2cSJim Jagielski * distributed with this work for additional information 6*b1cdbd2cSJim Jagielski * regarding copyright ownership. The ASF licenses this file 7*b1cdbd2cSJim Jagielski * to you under the Apache License, Version 2.0 (the 8*b1cdbd2cSJim Jagielski * "License"); you may not use this file except in compliance 9*b1cdbd2cSJim Jagielski * with the License. You may obtain a copy of the License at 10*b1cdbd2cSJim Jagielski * 11*b1cdbd2cSJim Jagielski * http://www.apache.org/licenses/LICENSE-2.0 12*b1cdbd2cSJim Jagielski * 13*b1cdbd2cSJim Jagielski * Unless required by applicable law or agreed to in writing, 14*b1cdbd2cSJim Jagielski * software distributed under the License is distributed on an 15*b1cdbd2cSJim Jagielski * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*b1cdbd2cSJim Jagielski * KIND, either express or implied. See the License for the 17*b1cdbd2cSJim Jagielski * specific language governing permissions and limitations 18*b1cdbd2cSJim Jagielski * under the License. 19*b1cdbd2cSJim Jagielski * 20*b1cdbd2cSJim Jagielski *************************************************************/ 21*b1cdbd2cSJim Jagielski 22*b1cdbd2cSJim Jagielski 23*b1cdbd2cSJim Jagielski 24*b1cdbd2cSJim Jagielski #ifndef OOX_XLS_FORMULABASE_HXX 25*b1cdbd2cSJim Jagielski #define OOX_XLS_FORMULABASE_HXX 26*b1cdbd2cSJim Jagielski 27*b1cdbd2cSJim Jagielski #include <com/sun/star/beans/Pair.hpp> 28*b1cdbd2cSJim Jagielski #include <com/sun/star/sheet/FormulaOpCodeMapEntry.hpp> 29*b1cdbd2cSJim Jagielski #include <com/sun/star/sheet/FormulaToken.hpp> 30*b1cdbd2cSJim Jagielski #include <com/sun/star/table/CellAddress.hpp> 31*b1cdbd2cSJim Jagielski #include <com/sun/star/table/CellRangeAddress.hpp> 32*b1cdbd2cSJim Jagielski #include <com/sun/star/uno/Sequence.hxx> 33*b1cdbd2cSJim Jagielski #include "oox/helper/propertyset.hxx" 34*b1cdbd2cSJim Jagielski #include "oox/helper/refvector.hxx" 35*b1cdbd2cSJim Jagielski #include "oox/xls/addressconverter.hxx" 36*b1cdbd2cSJim Jagielski 37*b1cdbd2cSJim Jagielski namespace com { namespace sun { namespace star { 38*b1cdbd2cSJim Jagielski namespace sheet { class XFormulaOpCodeMapper; } 39*b1cdbd2cSJim Jagielski namespace sheet { class XFormulaParser; } 40*b1cdbd2cSJim Jagielski } } } 41*b1cdbd2cSJim Jagielski 42*b1cdbd2cSJim Jagielski namespace oox { template< typename Type > class Matrix; } 43*b1cdbd2cSJim Jagielski 44*b1cdbd2cSJim Jagielski namespace oox { 45*b1cdbd2cSJim Jagielski namespace xls { 46*b1cdbd2cSJim Jagielski 47*b1cdbd2cSJim Jagielski // Constants ================================================================== 48*b1cdbd2cSJim Jagielski 49*b1cdbd2cSJim Jagielski const size_t BIFF_TOKARR_MAXLEN = 4096; /// Maximum size of a token array. 50*b1cdbd2cSJim Jagielski 51*b1cdbd2cSJim Jagielski // token class flags ---------------------------------------------------------- 52*b1cdbd2cSJim Jagielski 53*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOKCLASS_MASK = 0x60; 54*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOKCLASS_NONE = 0x00; /// 00-1F: Base tokens. 55*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOKCLASS_REF = 0x20; /// 20-3F: Reference class tokens. 56*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOKCLASS_VAL = 0x40; /// 40-5F: Value class tokens. 57*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOKCLASS_ARR = 0x60; /// 60-7F: Array class tokens. 58*b1cdbd2cSJim Jagielski 59*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOKFLAG_INVALID = 0x80; /// This bit must be null for a valid token identifier. 60*b1cdbd2cSJim Jagielski 61*b1cdbd2cSJim Jagielski // base token identifiers ----------------------------------------------------- 62*b1cdbd2cSJim Jagielski 63*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOKID_MASK = 0x1F; 64*b1cdbd2cSJim Jagielski 65*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOKID_NONE = 0x00; /// Placeholder for invalid token id. 66*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOKID_EXP = 0x01; /// Array or shared formula reference. 67*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOKID_TBL = 0x02; /// Multiple operation reference. 68*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOKID_ADD = 0x03; /// Addition operator. 69*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOKID_SUB = 0x04; /// Subtraction operator. 70*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOKID_MUL = 0x05; /// Multiplication operator. 71*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOKID_DIV = 0x06; /// Division operator. 72*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOKID_POWER = 0x07; /// Power operator. 73*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOKID_CONCAT = 0x08; /// String concatenation operator. 74*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOKID_LT = 0x09; /// Less than operator. 75*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOKID_LE = 0x0A; /// Less than or equal operator. 76*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOKID_EQ = 0x0B; /// Equal operator. 77*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOKID_GE = 0x0C; /// Greater than or equal operator. 78*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOKID_GT = 0x0D; /// Greater than operator. 79*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOKID_NE = 0x0E; /// Not equal operator. 80*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOKID_ISECT = 0x0F; /// Intersection operator. 81*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOKID_LIST = 0x10; /// List operator. 82*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOKID_RANGE = 0x11; /// Range operator. 83*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOKID_UPLUS = 0x12; /// Unary plus. 84*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOKID_UMINUS = 0x13; /// Unary minus. 85*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOKID_PERCENT = 0x14; /// Percent sign. 86*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOKID_PAREN = 0x15; /// Parentheses. 87*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOKID_MISSARG = 0x16; /// Missing argument. 88*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOKID_STR = 0x17; /// String constant. 89*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOKID_NLR = 0x18; /// Natural language reference (NLR). 90*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOKID_ATTR = 0x19; /// Special attribute. 91*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOKID_SHEET = 0x1A; /// Start of a sheet reference (BIFF2-BIFF4). 92*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOKID_ENDSHEET = 0x1B; /// End of a sheet reference (BIFF2-BIFF4). 93*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOKID_ERR = 0x1C; /// Error constant. 94*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOKID_BOOL = 0x1D; /// Boolean constant. 95*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOKID_INT = 0x1E; /// Integer constant. 96*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOKID_NUM = 0x1F; /// Floating-point constant. 97*b1cdbd2cSJim Jagielski 98*b1cdbd2cSJim Jagielski // base identifiers of classified tokens -------------------------------------- 99*b1cdbd2cSJim Jagielski 100*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOKID_ARRAY = 0x00; /// Array constant. 101*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOKID_FUNC = 0x01; /// Function, fixed number of arguments. 102*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOKID_FUNCVAR = 0x02; /// Function, variable number of arguments. 103*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOKID_NAME = 0x03; /// Defined name. 104*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOKID_REF = 0x04; /// 2D cell reference. 105*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOKID_AREA = 0x05; /// 2D area reference. 106*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOKID_MEMAREA = 0x06; /// Constant reference subexpression. 107*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOKID_MEMERR = 0x07; /// Deleted reference subexpression. 108*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOKID_MEMNOMEM = 0x08; /// Constant reference subexpression without result. 109*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOKID_MEMFUNC = 0x09; /// Variable reference subexpression. 110*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOKID_REFERR = 0x0A; /// Deleted 2D cell reference. 111*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOKID_AREAERR = 0x0B; /// Deleted 2D area reference. 112*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOKID_REFN = 0x0C; /// Relative 2D cell reference (in names). 113*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOKID_AREAN = 0x0D; /// Relative 2D area reference (in names). 114*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOKID_MEMAREAN = 0x0E; /// Reference subexpression (in names). 115*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOKID_MEMNOMEMN = 0x0F; /// Reference subexpression (in names) without result. 116*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOKID_FUNCCE = 0x18; 117*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOKID_NAMEX = 0x19; /// External reference. 118*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOKID_REF3D = 0x1A; /// 3D cell reference. 119*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOKID_AREA3D = 0x1B; /// 3D area reference. 120*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOKID_REFERR3D = 0x1C; /// Deleted 3D cell reference. 121*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOKID_AREAERR3D = 0x1D; /// Deleted 3D area reference 122*b1cdbd2cSJim Jagielski 123*b1cdbd2cSJim Jagielski // specific token constants --------------------------------------------------- 124*b1cdbd2cSJim Jagielski 125*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOK_ARRAY_DOUBLE = 0; /// Double value in an array. 126*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOK_ARRAY_STRING = 1; /// String value in an array. 127*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOK_ARRAY_BOOL = 2; /// Boolean value in an array. 128*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOK_ARRAY_ERROR = 4; /// Error code in an array. 129*b1cdbd2cSJim Jagielski 130*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOK_BOOL_FALSE = 0; /// FALSE value of a tBool token. 131*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOK_BOOL_TRUE = 1; /// TRUE value of a tBool token. 132*b1cdbd2cSJim Jagielski 133*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOK_ATTR_VOLATILE = 0x01; /// Volatile function. 134*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOK_ATTR_IF = 0x02; /// Start of true condition in IF function. 135*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOK_ATTR_CHOOSE = 0x04; /// Jump array of CHOOSE function. 136*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOK_ATTR_SKIP = 0x08; /// Skip tokens. 137*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOK_ATTR_SUM = 0x10; /// SUM function with one parameter. 138*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOK_ATTR_ASSIGN = 0x20; /// BASIC style assignment. 139*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOK_ATTR_SPACE = 0x40; /// Spaces in formula representation. 140*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOK_ATTR_SPACE_VOLATILE = 0x41; /// Leading spaces and volatile formula. 141*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOK_ATTR_IFERROR = 0x80; /// Start of condition in IFERROR function (BIFF12 only). 142*b1cdbd2cSJim Jagielski 143*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOK_ATTR_SPACE_SP = 0x00; /// Spaces before next token. 144*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOK_ATTR_SPACE_BR = 0x01; /// Line breaks before next token. 145*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOK_ATTR_SPACE_SP_OPEN = 0x02; /// Spaces before opening parenthesis. 146*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOK_ATTR_SPACE_BR_OPEN = 0x03; /// Line breaks before opening parenthesis. 147*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOK_ATTR_SPACE_SP_CLOSE = 0x04; /// Spaces before closing parenthesis. 148*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOK_ATTR_SPACE_BR_CLOSE = 0x05; /// Line breaks before closing parenthesis. 149*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOK_ATTR_SPACE_SP_PRE = 0x06; /// Spaces before formula (BIFF3). 150*b1cdbd2cSJim Jagielski 151*b1cdbd2cSJim Jagielski const sal_uInt16 BIFF_TOK_FUNCVAR_CMD = 0x8000; /// Macro command. 152*b1cdbd2cSJim Jagielski const sal_uInt16 BIFF_TOK_FUNCVAR_FUNCIDMASK = 0x7FFF; /// Mask for function/command index. 153*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOK_FUNCVAR_CMDPROMPT = 0x80; /// User prompt for macro commands. 154*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOK_FUNCVAR_COUNTMASK = 0x7F; /// Mask for parameter count. 155*b1cdbd2cSJim Jagielski 156*b1cdbd2cSJim Jagielski const sal_uInt16 BIFF12_TOK_REF_COLMASK = 0x3FFF; /// Mask to extract column from reference (BIFF12). 157*b1cdbd2cSJim Jagielski const sal_Int32 BIFF12_TOK_REF_ROWMASK = 0xFFFFF; /// Mask to extract row from reference (BIFF12). 158*b1cdbd2cSJim Jagielski const sal_uInt16 BIFF12_TOK_REF_COLREL = 0x4000; /// True = column is relative (BIFF12). 159*b1cdbd2cSJim Jagielski const sal_uInt16 BIFF12_TOK_REF_ROWREL = 0x8000; /// True = row is relative (BIFF12). 160*b1cdbd2cSJim Jagielski 161*b1cdbd2cSJim Jagielski const sal_uInt16 BIFF_TOK_REF_COLMASK = 0x00FF; /// Mask to extract BIFF8 column from reference. 162*b1cdbd2cSJim Jagielski const sal_uInt16 BIFF_TOK_REF_ROWMASK = 0x3FFF; /// Mask to extract BIFF2-BIFF5 row from reference. 163*b1cdbd2cSJim Jagielski const sal_uInt16 BIFF_TOK_REF_COLREL = 0x4000; /// True = column is relative. 164*b1cdbd2cSJim Jagielski const sal_uInt16 BIFF_TOK_REF_ROWREL = 0x8000; /// True = row is relative. 165*b1cdbd2cSJim Jagielski 166*b1cdbd2cSJim Jagielski const sal_uInt16 BIFF12_TOK_TABLE_COLUMN = 0x0001; /// Table reference: Single column. 167*b1cdbd2cSJim Jagielski const sal_uInt16 BIFF12_TOK_TABLE_COLRANGE = 0x0002; /// Table reference: Range of columns. 168*b1cdbd2cSJim Jagielski const sal_uInt16 BIFF12_TOK_TABLE_ALL = 0x0004; /// Table reference: Special [#All] range. 169*b1cdbd2cSJim Jagielski const sal_uInt16 BIFF12_TOK_TABLE_HEADERS = 0x0008; /// Table reference: Special [#Headers] range. 170*b1cdbd2cSJim Jagielski const sal_uInt16 BIFF12_TOK_TABLE_DATA = 0x0010; /// Table reference: Special [#Data] range. 171*b1cdbd2cSJim Jagielski const sal_uInt16 BIFF12_TOK_TABLE_TOTALS = 0x0020; /// Table reference: Special [#Totals] range. 172*b1cdbd2cSJim Jagielski const sal_uInt16 BIFF12_TOK_TABLE_THISROW = 0x0040; /// Table reference: Special [#This Row] range. 173*b1cdbd2cSJim Jagielski const sal_uInt16 BIFF12_TOK_TABLE_SP_BRACKETS = 0x0080; /// Table reference: Spaces in outer brackets. 174*b1cdbd2cSJim Jagielski const sal_uInt16 BIFF12_TOK_TABLE_SP_SEP = 0x0100; /// Table reference: Spaces after separators. 175*b1cdbd2cSJim Jagielski const sal_uInt16 BIFF12_TOK_TABLE_ROW = 0x0200; /// Table reference: Single row. 176*b1cdbd2cSJim Jagielski const sal_uInt16 BIFF12_TOK_TABLE_CELL = 0x0400; /// Table reference: Single cell. 177*b1cdbd2cSJim Jagielski 178*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOK_NLR_ERR = 0x01; /// NLR: Invalid/deleted. 179*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOK_NLR_ROWR = 0x02; /// NLR: Row index. 180*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOK_NLR_COLR = 0x03; /// NLR: Column index. 181*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOK_NLR_ROWV = 0x06; /// NLR: Value in row. 182*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOK_NLR_COLV = 0x07; /// NLR: Value in column. 183*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOK_NLR_RANGE = 0x0A; /// NLR: Range. 184*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOK_NLR_SRANGE = 0x0B; /// Stacked NLR: Range. 185*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOK_NLR_SROWR = 0x0C; /// Stacked NLR: Row index. 186*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOK_NLR_SCOLR = 0x0D; /// Stacked NLR: Column index. 187*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOK_NLR_SROWV = 0x0E; /// Stacked NLR: Value in row. 188*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOK_NLR_SCOLV = 0x0F; /// Stacked NLR: Value in column. 189*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOK_NLR_RANGEERR = 0x10; /// NLR: Invalid/deleted range. 190*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_TOK_NLR_SXNAME = 0x1D; /// NLR: Pivot table name. 191*b1cdbd2cSJim Jagielski const sal_uInt16 BIFF_TOK_NLR_REL = 0x8000; /// True = NLR is relative. 192*b1cdbd2cSJim Jagielski const sal_uInt16 BIFF_TOK_NLR_MASK = 0x3FFF; /// Mask to extract BIFF8 column from NLR. 193*b1cdbd2cSJim Jagielski 194*b1cdbd2cSJim Jagielski const sal_uInt32 BIFF_TOK_NLR_ADDREL = 0x80000000; /// NLR relative (in appended data). 195*b1cdbd2cSJim Jagielski const sal_uInt32 BIFF_TOK_NLR_ADDMASK = 0x3FFFFFFF; /// Mask for number of appended ranges. 196*b1cdbd2cSJim Jagielski 197*b1cdbd2cSJim Jagielski // function constants --------------------------------------------------------- 198*b1cdbd2cSJim Jagielski 199*b1cdbd2cSJim Jagielski const sal_uInt8 OOX_MAX_PARAMCOUNT = 255; /// Maximum parameter count for OOXML/BIFF12 files. 200*b1cdbd2cSJim Jagielski const sal_uInt8 BIFF_MAX_PARAMCOUNT = 30; /// Maximum parameter count for BIFF2-BIFF8 files. 201*b1cdbd2cSJim Jagielski 202*b1cdbd2cSJim Jagielski const sal_uInt16 BIFF_FUNC_IF = 1; /// Function identifier of the IF function. 203*b1cdbd2cSJim Jagielski const sal_uInt16 BIFF_FUNC_SUM = 4; /// Function identifier of the SUM function. 204*b1cdbd2cSJim Jagielski const sal_uInt16 BIFF_FUNC_TRUE = 34; /// Function identifier of the TRUE function. 205*b1cdbd2cSJim Jagielski const sal_uInt16 BIFF_FUNC_FALSE = 35; /// Function identifier of the FALSE function. 206*b1cdbd2cSJim Jagielski const sal_uInt16 BIFF_FUNC_ROWS = 76; /// Function identifier of the ROWS function. 207*b1cdbd2cSJim Jagielski const sal_uInt16 BIFF_FUNC_COLUMNS = 77; /// Function identifier of the COLUMNS function. 208*b1cdbd2cSJim Jagielski const sal_uInt16 BIFF_FUNC_OFFSET = 78; /// Function identifier of the OFFSET function. 209*b1cdbd2cSJim Jagielski const sal_uInt16 BIFF_FUNC_EXTERNCALL = 255; /// BIFF function id of the EXTERN.CALL function. 210*b1cdbd2cSJim Jagielski const sal_uInt16 BIFF_FUNC_FLOOR = 285; /// Function identifier of the FLOOR function. 211*b1cdbd2cSJim Jagielski const sal_uInt16 BIFF_FUNC_CEILING = 288; /// Function identifier of the CEILING function. 212*b1cdbd2cSJim Jagielski const sal_uInt16 BIFF_FUNC_HYPERLINK = 359; /// Function identifier of the HYPERLINK function. 213*b1cdbd2cSJim Jagielski const sal_uInt16 BIFF_FUNC_WEEKNUM = 465; /// Function identifier of the WEEKNUM function. 214*b1cdbd2cSJim Jagielski 215*b1cdbd2cSJim Jagielski // Formula type =============================================================== 216*b1cdbd2cSJim Jagielski 217*b1cdbd2cSJim Jagielski /** Enumerates all possible types of a formula. */ 218*b1cdbd2cSJim Jagielski enum FormulaType 219*b1cdbd2cSJim Jagielski { 220*b1cdbd2cSJim Jagielski FORMULATYPE_CELL, /// Simple cell formula, or reference to a shared formula name. 221*b1cdbd2cSJim Jagielski FORMULATYPE_ARRAY, /// Array (matrix) formula. 222*b1cdbd2cSJim Jagielski FORMULATYPE_SHAREDFORMULA, /// Shared formula definition. 223*b1cdbd2cSJim Jagielski FORMULATYPE_CONDFORMAT, /// Condition of a conditional format rule. 224*b1cdbd2cSJim Jagielski FORMULATYPE_VALIDATION, /// Condition of a data validation. 225*b1cdbd2cSJim Jagielski FORMULATYPE_DEFINEDNAME /// Definition of a defined name. 226*b1cdbd2cSJim Jagielski }; 227*b1cdbd2cSJim Jagielski 228*b1cdbd2cSJim Jagielski // Reference helpers ========================================================== 229*b1cdbd2cSJim Jagielski 230*b1cdbd2cSJim Jagielski /** A 2D formula cell reference struct with relative flags. */ 231*b1cdbd2cSJim Jagielski struct BinSingleRef2d 232*b1cdbd2cSJim Jagielski { 233*b1cdbd2cSJim Jagielski sal_Int32 mnCol; /// Column index. 234*b1cdbd2cSJim Jagielski sal_Int32 mnRow; /// Row index. 235*b1cdbd2cSJim Jagielski bool mbColRel; /// True = relative column reference. 236*b1cdbd2cSJim Jagielski bool mbRowRel; /// True = relative row reference. 237*b1cdbd2cSJim Jagielski 238*b1cdbd2cSJim Jagielski explicit BinSingleRef2d(); 239*b1cdbd2cSJim Jagielski 240*b1cdbd2cSJim Jagielski void setBiff12Data( sal_uInt16 nCol, sal_Int32 nRow, bool bRelativeAsOffset ); 241*b1cdbd2cSJim Jagielski void setBiff2Data( sal_uInt8 nCol, sal_uInt16 nRow, bool bRelativeAsOffset ); 242*b1cdbd2cSJim Jagielski void setBiff8Data( sal_uInt16 nCol, sal_uInt16 nRow, bool bRelativeAsOffset ); 243*b1cdbd2cSJim Jagielski 244*b1cdbd2cSJim Jagielski void readBiff12Data( SequenceInputStream& rStrm, bool bRelativeAsOffset ); 245*b1cdbd2cSJim Jagielski void readBiff2Data( BiffInputStream& rStrm, bool bRelativeAsOffset ); 246*b1cdbd2cSJim Jagielski void readBiff8Data( BiffInputStream& rStrm, bool bRelativeAsOffset ); 247*b1cdbd2cSJim Jagielski }; 248*b1cdbd2cSJim Jagielski 249*b1cdbd2cSJim Jagielski // ---------------------------------------------------------------------------- 250*b1cdbd2cSJim Jagielski 251*b1cdbd2cSJim Jagielski /** A 2D formula cell range reference struct with relative flags. */ 252*b1cdbd2cSJim Jagielski struct BinComplexRef2d 253*b1cdbd2cSJim Jagielski { 254*b1cdbd2cSJim Jagielski BinSingleRef2d maRef1; /// Start (top-left) cell address. 255*b1cdbd2cSJim Jagielski BinSingleRef2d maRef2; /// End (bottom-right) cell address. 256*b1cdbd2cSJim Jagielski 257*b1cdbd2cSJim Jagielski void readBiff12Data( SequenceInputStream& rStrm, bool bRelativeAsOffset ); 258*b1cdbd2cSJim Jagielski void readBiff2Data( BiffInputStream& rStrm, bool bRelativeAsOffset ); 259*b1cdbd2cSJim Jagielski void readBiff8Data( BiffInputStream& rStrm, bool bRelativeAsOffset ); 260*b1cdbd2cSJim Jagielski }; 261*b1cdbd2cSJim Jagielski 262*b1cdbd2cSJim Jagielski // Token vector, token sequence =============================================== 263*b1cdbd2cSJim Jagielski 264*b1cdbd2cSJim Jagielski typedef ::com::sun::star::sheet::FormulaToken ApiToken; 265*b1cdbd2cSJim Jagielski typedef ::com::sun::star::uno::Sequence< ApiToken > ApiTokenSequence; 266*b1cdbd2cSJim Jagielski 267*b1cdbd2cSJim Jagielski /** Contains the base address and type of a special token representing an array 268*b1cdbd2cSJim Jagielski formula or a shared formula (sal_False), or a table operation (sal_True). */ 269*b1cdbd2cSJim Jagielski typedef ::com::sun::star::beans::Pair< ::com::sun::star::table::CellAddress, sal_Bool > ApiSpecialTokenInfo; 270*b1cdbd2cSJim Jagielski 271*b1cdbd2cSJim Jagielski /** A vector of formula tokens with additional convenience functions. */ 272*b1cdbd2cSJim Jagielski class ApiTokenVector : public ::std::vector< ApiToken > 273*b1cdbd2cSJim Jagielski { 274*b1cdbd2cSJim Jagielski public: 275*b1cdbd2cSJim Jagielski explicit ApiTokenVector(); 276*b1cdbd2cSJim Jagielski 277*b1cdbd2cSJim Jagielski /** Appends a new token with the passed op-code, returns its data field. */ 278*b1cdbd2cSJim Jagielski ::com::sun::star::uno::Any& 279*b1cdbd2cSJim Jagielski append( sal_Int32 nOpCode ); 280*b1cdbd2cSJim Jagielski 281*b1cdbd2cSJim Jagielski /** Appends a new token with the passed op-code and data. */ 282*b1cdbd2cSJim Jagielski template< typename Type > append(sal_Int32 nOpCode,const Type & rData)283*b1cdbd2cSJim Jagielski inline void append( sal_Int32 nOpCode, const Type& rData ) { append( nOpCode ) <<= rData; } 284*b1cdbd2cSJim Jagielski }; 285*b1cdbd2cSJim Jagielski 286*b1cdbd2cSJim Jagielski // Token sequence iterator ==================================================== 287*b1cdbd2cSJim Jagielski 288*b1cdbd2cSJim Jagielski /** Token sequence iterator that is able to skip space tokens. */ 289*b1cdbd2cSJim Jagielski class ApiTokenIterator 290*b1cdbd2cSJim Jagielski { 291*b1cdbd2cSJim Jagielski public: 292*b1cdbd2cSJim Jagielski explicit ApiTokenIterator( const ApiTokenSequence& rTokens, sal_Int32 nSpacesOpCode, bool bSkipSpaces ); 293*b1cdbd2cSJim Jagielski /** Copy constructor that allows to change the skip spaces mode. */ 294*b1cdbd2cSJim Jagielski explicit ApiTokenIterator( const ApiTokenIterator& rIter, bool bSkipSpaces ); 295*b1cdbd2cSJim Jagielski is() const296*b1cdbd2cSJim Jagielski inline bool is() const { return mpToken != mpTokenEnd; } get() const297*b1cdbd2cSJim Jagielski inline const ApiToken* get() const { return mpToken; } operator ->() const298*b1cdbd2cSJim Jagielski inline const ApiToken* operator->() const { return mpToken; } operator *() const299*b1cdbd2cSJim Jagielski inline const ApiToken& operator*() const { return *mpToken; } 300*b1cdbd2cSJim Jagielski 301*b1cdbd2cSJim Jagielski ApiTokenIterator& operator++(); 302*b1cdbd2cSJim Jagielski 303*b1cdbd2cSJim Jagielski private: 304*b1cdbd2cSJim Jagielski void skipSpaces(); 305*b1cdbd2cSJim Jagielski 306*b1cdbd2cSJim Jagielski private: 307*b1cdbd2cSJim Jagielski const ApiToken* mpToken; /// Pointer to current token of the token sequence. 308*b1cdbd2cSJim Jagielski const ApiToken* mpTokenEnd; /// Pointer behind last token of the token sequence. 309*b1cdbd2cSJim Jagielski const sal_Int32 mnSpacesOpCode; /// Op-code for whitespace tokens. 310*b1cdbd2cSJim Jagielski const bool mbSkipSpaces; /// true = Skip whitespace tokens. 311*b1cdbd2cSJim Jagielski }; 312*b1cdbd2cSJim Jagielski 313*b1cdbd2cSJim Jagielski // List of API op-codes ======================================================= 314*b1cdbd2cSJim Jagielski 315*b1cdbd2cSJim Jagielski /** Contains all API op-codes needed to build formulas with tokens. */ 316*b1cdbd2cSJim Jagielski struct ApiOpCodes 317*b1cdbd2cSJim Jagielski { 318*b1cdbd2cSJim Jagielski // special 319*b1cdbd2cSJim Jagielski sal_Int32 OPCODE_UNKNOWN; /// Internal: function name unknown to mapper. 320*b1cdbd2cSJim Jagielski sal_Int32 OPCODE_EXTERNAL; /// External function call (e.g. add-ins). 321*b1cdbd2cSJim Jagielski // formula structure 322*b1cdbd2cSJim Jagielski sal_Int32 OPCODE_PUSH; /// Op-code for common value operands. 323*b1cdbd2cSJim Jagielski sal_Int32 OPCODE_MISSING; /// Placeholder for a missing function parameter. 324*b1cdbd2cSJim Jagielski sal_Int32 OPCODE_SPACES; /// Spaces between other formula tokens. 325*b1cdbd2cSJim Jagielski sal_Int32 OPCODE_NAME; /// Index of a defined name. 326*b1cdbd2cSJim Jagielski sal_Int32 OPCODE_DBAREA; /// Index of a database area. 327*b1cdbd2cSJim Jagielski sal_Int32 OPCODE_NLR; /// Natural language reference. 328*b1cdbd2cSJim Jagielski sal_Int32 OPCODE_DDE; /// DDE link function. 329*b1cdbd2cSJim Jagielski sal_Int32 OPCODE_MACRO; /// Macro function call. 330*b1cdbd2cSJim Jagielski sal_Int32 OPCODE_BAD; /// Bad token (unknown name, formula error). 331*b1cdbd2cSJim Jagielski sal_Int32 OPCODE_NONAME; /// Function style #NAME? error. 332*b1cdbd2cSJim Jagielski // separators 333*b1cdbd2cSJim Jagielski sal_Int32 OPCODE_OPEN; /// Opening parenthesis. 334*b1cdbd2cSJim Jagielski sal_Int32 OPCODE_CLOSE; /// Closing parenthesis. 335*b1cdbd2cSJim Jagielski sal_Int32 OPCODE_SEP; /// Function parameter separator. 336*b1cdbd2cSJim Jagielski // array separators 337*b1cdbd2cSJim Jagielski sal_Int32 OPCODE_ARRAY_OPEN; /// Opening brace for constant arrays. 338*b1cdbd2cSJim Jagielski sal_Int32 OPCODE_ARRAY_CLOSE; /// Closing brace for constant arrays. 339*b1cdbd2cSJim Jagielski sal_Int32 OPCODE_ARRAY_ROWSEP; /// Row separator in constant arrays. 340*b1cdbd2cSJim Jagielski sal_Int32 OPCODE_ARRAY_COLSEP; /// Column separator in constant arrays. 341*b1cdbd2cSJim Jagielski // unary operators 342*b1cdbd2cSJim Jagielski sal_Int32 OPCODE_PLUS_SIGN; /// Unary plus sign. 343*b1cdbd2cSJim Jagielski sal_Int32 OPCODE_MINUS_SIGN; /// Unary minus sign. 344*b1cdbd2cSJim Jagielski sal_Int32 OPCODE_PERCENT; /// Percent sign. 345*b1cdbd2cSJim Jagielski // binary operators 346*b1cdbd2cSJim Jagielski sal_Int32 OPCODE_ADD; /// Addition operator. 347*b1cdbd2cSJim Jagielski sal_Int32 OPCODE_SUB; /// Subtraction operator. 348*b1cdbd2cSJim Jagielski sal_Int32 OPCODE_MULT; /// Multiplication operator. 349*b1cdbd2cSJim Jagielski sal_Int32 OPCODE_DIV; /// Division operator. 350*b1cdbd2cSJim Jagielski sal_Int32 OPCODE_POWER; /// Power operator. 351*b1cdbd2cSJim Jagielski sal_Int32 OPCODE_CONCAT; /// String concatenation operator. 352*b1cdbd2cSJim Jagielski sal_Int32 OPCODE_EQUAL; /// Compare equal operator. 353*b1cdbd2cSJim Jagielski sal_Int32 OPCODE_NOT_EQUAL; /// Compare not equal operator. 354*b1cdbd2cSJim Jagielski sal_Int32 OPCODE_LESS; /// Compare less operator. 355*b1cdbd2cSJim Jagielski sal_Int32 OPCODE_LESS_EQUAL; /// Compare less or equal operator. 356*b1cdbd2cSJim Jagielski sal_Int32 OPCODE_GREATER; /// Compare greater operator. 357*b1cdbd2cSJim Jagielski sal_Int32 OPCODE_GREATER_EQUAL; /// Compare greater or equal operator. 358*b1cdbd2cSJim Jagielski sal_Int32 OPCODE_INTERSECT; /// Range intersection operator. 359*b1cdbd2cSJim Jagielski sal_Int32 OPCODE_LIST; /// Range list operator. 360*b1cdbd2cSJim Jagielski sal_Int32 OPCODE_RANGE; /// Range operator. 361*b1cdbd2cSJim Jagielski }; 362*b1cdbd2cSJim Jagielski 363*b1cdbd2cSJim Jagielski // Function parameter info ==================================================== 364*b1cdbd2cSJim Jagielski 365*b1cdbd2cSJim Jagielski /** Enumerates validity modes for a function parameter. */ 366*b1cdbd2cSJim Jagielski enum FuncParamValidity 367*b1cdbd2cSJim Jagielski { 368*b1cdbd2cSJim Jagielski FUNC_PARAM_NONE = 0, /// Default for an unspecified entry in a C-array. 369*b1cdbd2cSJim Jagielski FUNC_PARAM_REGULAR, /// Parameter supported by Calc and Excel. 370*b1cdbd2cSJim Jagielski FUNC_PARAM_CALCONLY, /// Parameter supported by Calc only. 371*b1cdbd2cSJim Jagielski FUNC_PARAM_EXCELONLY /// Parameter supported by Excel only. 372*b1cdbd2cSJim Jagielski }; 373*b1cdbd2cSJim Jagielski 374*b1cdbd2cSJim Jagielski /** Enumerates different types of token class conversion in function parameters. */ 375*b1cdbd2cSJim Jagielski enum FuncParamConversion 376*b1cdbd2cSJim Jagielski { 377*b1cdbd2cSJim Jagielski FUNC_PARAMCONV_ORG, /// Use original class of current token. 378*b1cdbd2cSJim Jagielski FUNC_PARAMCONV_VAL, /// Convert tokens to VAL class. 379*b1cdbd2cSJim Jagielski FUNC_PARAMCONV_ARR, /// Convert tokens to ARR class. 380*b1cdbd2cSJim Jagielski FUNC_PARAMCONV_RPT, /// Repeat parent conversion in VALTYPE parameters. 381*b1cdbd2cSJim Jagielski FUNC_PARAMCONV_RPX, /// Repeat parent conversion in REFTYPE parameters. 382*b1cdbd2cSJim Jagielski FUNC_PARAMCONV_RPO /// Repeat parent conversion in operands of operators. 383*b1cdbd2cSJim Jagielski }; 384*b1cdbd2cSJim Jagielski 385*b1cdbd2cSJim Jagielski /** Structure that contains all needed information for a parameter in a 386*b1cdbd2cSJim Jagielski function. 387*b1cdbd2cSJim Jagielski 388*b1cdbd2cSJim Jagielski The member meValid specifies which application supports the parameter. If 389*b1cdbd2cSJim Jagielski set to CALCONLY, import filters have to insert a default value for this 390*b1cdbd2cSJim Jagielski parameter, and export filters have to skip the parameter. If set to 391*b1cdbd2cSJim Jagielski EXCELONLY, import filters have to skip the parameter, and export filters 392*b1cdbd2cSJim Jagielski have to insert a default value for this parameter. 393*b1cdbd2cSJim Jagielski 394*b1cdbd2cSJim Jagielski The member mbValType specifies whether the parameter requires tokens to be 395*b1cdbd2cSJim Jagielski of value type (VAL or ARR class). 396*b1cdbd2cSJim Jagielski 397*b1cdbd2cSJim Jagielski If set to false, the parameter is called to be REFTYPE. Tokens with REF 398*b1cdbd2cSJim Jagielski default class can be inserted for the parameter (e.g. tAreaR tokens). 399*b1cdbd2cSJim Jagielski 400*b1cdbd2cSJim Jagielski If set to true, the parameter is called to be VALTYPE. Tokens with REF 401*b1cdbd2cSJim Jagielski class need to be converted to VAL tokens first (e.g. tAreaR will be 402*b1cdbd2cSJim Jagielski converted to tAreaV), and further conversion is done according to this 403*b1cdbd2cSJim Jagielski new token class. 404*b1cdbd2cSJim Jagielski 405*b1cdbd2cSJim Jagielski The member meConv specifies how to convert the current token class of the 406*b1cdbd2cSJim Jagielski token inserted for the parameter. If the token class is still REF this 407*b1cdbd2cSJim Jagielski means that the token has default REF class and the parameter is REFTYPE 408*b1cdbd2cSJim Jagielski (see member mbValType), the token will not be converted at all and remains 409*b1cdbd2cSJim Jagielski in REF class. Otherwise, token class conversion is depending on the actual 410*b1cdbd2cSJim Jagielski token class of the return value of the function containing this parameter. 411*b1cdbd2cSJim Jagielski The function may return REF class (tFuncR, tFuncVarR, tFuncCER), or it may 412*b1cdbd2cSJim Jagielski return VAL or ARR class (tFuncV, tFuncA, tFuncVarV, tFuncVarA, tFuncCEV, 413*b1cdbd2cSJim Jagielski tFuncCEA). Even if the function is able to return REF class, it may return 414*b1cdbd2cSJim Jagielski VAL or ARR class instead due to the VALTYPE data type of the parent 415*b1cdbd2cSJim Jagielski function parameter that calls the own function. Example: The INDIRECT 416*b1cdbd2cSJim Jagielski function returns REF class by default. But if called from a VALTYPE 417*b1cdbd2cSJim Jagielski function parameter, e.g. in the formula =ABS(INDIRECT("A1")), it returns 418*b1cdbd2cSJim Jagielski VAL or ARR class instead. Additionally, the repeating conversion types RPT 419*b1cdbd2cSJim Jagielski and RPX rely on the conversion executed for the function token class. 420*b1cdbd2cSJim Jagielski 421*b1cdbd2cSJim Jagielski 1) ORG: 422*b1cdbd2cSJim Jagielski Use the original class of the token (VAL or ARR), regardless of any 423*b1cdbd2cSJim Jagielski conversion done for the function return class. 424*b1cdbd2cSJim Jagielski 425*b1cdbd2cSJim Jagielski 2) VAL: 426*b1cdbd2cSJim Jagielski Convert ARR tokens to VAL class, regardless of any conversion done for 427*b1cdbd2cSJim Jagielski the function return class. 428*b1cdbd2cSJim Jagielski 429*b1cdbd2cSJim Jagielski 3) ARR: 430*b1cdbd2cSJim Jagielski Convert VAL tokens to ARR class, regardless of any conversion done for 431*b1cdbd2cSJim Jagielski the function return class. 432*b1cdbd2cSJim Jagielski 433*b1cdbd2cSJim Jagielski 4) RPT: 434*b1cdbd2cSJim Jagielski If the own function returns REF class (thus it is called from a REFTYPE 435*b1cdbd2cSJim Jagielski parameter, see above), and the parent conversion type (for the function 436*b1cdbd2cSJim Jagielski return class) was ORG, VAL, or ARR, ignore that conversion and always 437*b1cdbd2cSJim Jagielski use VAL conversion for the own token instead. If the parent conversion 438*b1cdbd2cSJim Jagielski type was RPT or RPX, repeat the conversion that would have been used if 439*b1cdbd2cSJim Jagielski the function would return value type. 440*b1cdbd2cSJim Jagielski If the own function returns value type (VAL or ARR class, see above), 441*b1cdbd2cSJim Jagielski and the parent conversion type (for the function return class) was ORG, 442*b1cdbd2cSJim Jagielski VAL, ARR, or RPT, repeat this conversion for the own token. If the 443*b1cdbd2cSJim Jagielski parent conversion type was RPX, always use ORG conversion type for the 444*b1cdbd2cSJim Jagielski own token instead. 445*b1cdbd2cSJim Jagielski 446*b1cdbd2cSJim Jagielski 5) RPX: 447*b1cdbd2cSJim Jagielski This type of conversion only occurs in functions returning VAL class by 448*b1cdbd2cSJim Jagielski default. If the own token is value type, and the VAL return class of 449*b1cdbd2cSJim Jagielski the own function has been changed to ARR class (due to direct ARR 450*b1cdbd2cSJim Jagielski conversion, or due to ARR conversion repeated by RPT or RPX), set the 451*b1cdbd2cSJim Jagielski own token to ARR type. Otherwise use the original token type (VAL 452*b1cdbd2cSJim Jagielski conversion from parent parameter will not be repeated at all). If 453*b1cdbd2cSJim Jagielski nested functions have RPT or value-type RPX parameters, they will not 454*b1cdbd2cSJim Jagielski repeat this conversion type, but will use ORG conversion instead (see 455*b1cdbd2cSJim Jagielski description of RPT above). 456*b1cdbd2cSJim Jagielski 457*b1cdbd2cSJim Jagielski 6) RPO: 458*b1cdbd2cSJim Jagielski This type of conversion is only used for the operands of all operators 459*b1cdbd2cSJim Jagielski (unary and binary arithmetic operators, comparison operators, and range 460*b1cdbd2cSJim Jagielski operators). It is not used for function parameters. On conversion, it 461*b1cdbd2cSJim Jagielski will be replaced by the last conversion type that was not the RPO 462*b1cdbd2cSJim Jagielski conversion. This leads to a slightly different behaviour than the RPT 463*b1cdbd2cSJim Jagielski conversion for operands in conjunction with a parent RPX conversion. 464*b1cdbd2cSJim Jagielski */ 465*b1cdbd2cSJim Jagielski struct FunctionParamInfo 466*b1cdbd2cSJim Jagielski { 467*b1cdbd2cSJim Jagielski FuncParamValidity meValid; /// Parameter validity. 468*b1cdbd2cSJim Jagielski FuncParamConversion meConv; /// Token class conversion type. 469*b1cdbd2cSJim Jagielski bool mbValType; /// Data type (false = REFTYPE, true = VALTYPE). 470*b1cdbd2cSJim Jagielski }; 471*b1cdbd2cSJim Jagielski 472*b1cdbd2cSJim Jagielski // Function data ============================================================== 473*b1cdbd2cSJim Jagielski 474*b1cdbd2cSJim Jagielski /** This enumeration contains constants for all known external libraries 475*b1cdbd2cSJim Jagielski containing supported sheet functions. */ 476*b1cdbd2cSJim Jagielski enum FunctionLibraryType 477*b1cdbd2cSJim Jagielski { 478*b1cdbd2cSJim Jagielski FUNCLIB_UNKNOWN = 0, /// Unknown library (must be zero). 479*b1cdbd2cSJim Jagielski FUNCLIB_EUROTOOL /// EuroTool add-in with EUROCONVERT function. 480*b1cdbd2cSJim Jagielski }; 481*b1cdbd2cSJim Jagielski 482*b1cdbd2cSJim Jagielski // ---------------------------------------------------------------------------- 483*b1cdbd2cSJim Jagielski 484*b1cdbd2cSJim Jagielski /** Represents information for a spreadsheet function. 485*b1cdbd2cSJim Jagielski 486*b1cdbd2cSJim Jagielski The member mpParamInfos points to a C-array of type information structures 487*b1cdbd2cSJim Jagielski for all parameters of the function. The last initialized structure 488*b1cdbd2cSJim Jagielski describing a regular parameter (member meValid == FUNC_PARAM_REGULAR) in 489*b1cdbd2cSJim Jagielski this array is used repeatedly for all following parameters supported by a 490*b1cdbd2cSJim Jagielski function. 491*b1cdbd2cSJim Jagielski */ 492*b1cdbd2cSJim Jagielski struct FunctionInfo 493*b1cdbd2cSJim Jagielski { 494*b1cdbd2cSJim Jagielski ::rtl::OUString maOdfFuncName; /// ODF function name. 495*b1cdbd2cSJim Jagielski ::rtl::OUString maOoxFuncName; /// OOXML function name. 496*b1cdbd2cSJim Jagielski ::rtl::OUString maBiffMacroName; /// Expected macro name in EXTERN.CALL function. 497*b1cdbd2cSJim Jagielski ::rtl::OUString maExtProgName; /// Programmatic function name for external functions. 498*b1cdbd2cSJim Jagielski FunctionLibraryType meFuncLibType; /// The external library this function is part of. 499*b1cdbd2cSJim Jagielski sal_Int32 mnApiOpCode; /// API function opcode. 500*b1cdbd2cSJim Jagielski sal_uInt16 mnBiff12FuncId; /// BIFF12 function identifier. 501*b1cdbd2cSJim Jagielski sal_uInt16 mnBiffFuncId; /// BIFF2-BIFF8 function identifier. 502*b1cdbd2cSJim Jagielski sal_uInt8 mnMinParamCount; /// Minimum number of parameters. 503*b1cdbd2cSJim Jagielski sal_uInt8 mnMaxParamCount; /// Maximum number of parameters. 504*b1cdbd2cSJim Jagielski sal_uInt8 mnRetClass; /// BIFF token class of the return value. 505*b1cdbd2cSJim Jagielski const FunctionParamInfo* mpParamInfos; /// Information about all parameters. 506*b1cdbd2cSJim Jagielski bool mbParamPairs; /// True = optional parameters are expected to appear in pairs. 507*b1cdbd2cSJim Jagielski bool mbVolatile; /// True = volatile function. 508*b1cdbd2cSJim Jagielski bool mbExternal; /// True = external function in Calc. 509*b1cdbd2cSJim Jagielski bool mbMacroFunc; /// True = macro sheet function or command. 510*b1cdbd2cSJim Jagielski bool mbVarParam; /// True = use a tFuncVar token, also if min/max are equal. 511*b1cdbd2cSJim Jagielski }; 512*b1cdbd2cSJim Jagielski 513*b1cdbd2cSJim Jagielski typedef RefVector< FunctionInfo > FunctionInfoVector; 514*b1cdbd2cSJim Jagielski 515*b1cdbd2cSJim Jagielski // Function info parameter class iterator ===================================== 516*b1cdbd2cSJim Jagielski 517*b1cdbd2cSJim Jagielski /** Iterator working on the mpParamInfos member of the FunctionInfo struct. 518*b1cdbd2cSJim Jagielski 519*b1cdbd2cSJim Jagielski This iterator can be used to iterate through the array containing the 520*b1cdbd2cSJim Jagielski token class conversion information of function parameters. This iterator 521*b1cdbd2cSJim Jagielski repeats the last valid structure in the array - it stops automatically 522*b1cdbd2cSJim Jagielski before the first empty array entry or before the end of the array, even for 523*b1cdbd2cSJim Jagielski repeated calls to the increment operator. 524*b1cdbd2cSJim Jagielski */ 525*b1cdbd2cSJim Jagielski class FunctionParamInfoIterator 526*b1cdbd2cSJim Jagielski { 527*b1cdbd2cSJim Jagielski public: 528*b1cdbd2cSJim Jagielski explicit FunctionParamInfoIterator( const FunctionInfo& rFuncInfo ); 529*b1cdbd2cSJim Jagielski 530*b1cdbd2cSJim Jagielski const FunctionParamInfo& getParamInfo() const; 531*b1cdbd2cSJim Jagielski bool isCalcOnlyParam() const; 532*b1cdbd2cSJim Jagielski bool isExcelOnlyParam() const; 533*b1cdbd2cSJim Jagielski FunctionParamInfoIterator& operator++(); 534*b1cdbd2cSJim Jagielski 535*b1cdbd2cSJim Jagielski private: 536*b1cdbd2cSJim Jagielski const FunctionParamInfo* mpParamInfo; 537*b1cdbd2cSJim Jagielski const FunctionParamInfo* mpParamInfoEnd; 538*b1cdbd2cSJim Jagielski bool mbParamPairs; 539*b1cdbd2cSJim Jagielski }; 540*b1cdbd2cSJim Jagielski 541*b1cdbd2cSJim Jagielski // Base function provider ===================================================== 542*b1cdbd2cSJim Jagielski 543*b1cdbd2cSJim Jagielski struct FunctionProviderImpl; 544*b1cdbd2cSJim Jagielski 545*b1cdbd2cSJim Jagielski /** Provides access to function info structs for all available sheet functions. 546*b1cdbd2cSJim Jagielski */ 547*b1cdbd2cSJim Jagielski class FunctionProvider // not derived from WorkbookHelper to make it usable in file dumpers 548*b1cdbd2cSJim Jagielski { 549*b1cdbd2cSJim Jagielski public: 550*b1cdbd2cSJim Jagielski explicit FunctionProvider( FilterType eFilter, BiffType eBiff, bool bImportFilter ); 551*b1cdbd2cSJim Jagielski virtual ~FunctionProvider(); 552*b1cdbd2cSJim Jagielski 553*b1cdbd2cSJim Jagielski /** Returns the function info for an ODF function name, or 0 on error. */ 554*b1cdbd2cSJim Jagielski const FunctionInfo* getFuncInfoFromOdfFuncName( const ::rtl::OUString& rFuncName ) const; 555*b1cdbd2cSJim Jagielski 556*b1cdbd2cSJim Jagielski /** Returns the function info for an OOXML function name, or 0 on error. */ 557*b1cdbd2cSJim Jagielski const FunctionInfo* getFuncInfoFromOoxFuncName( const ::rtl::OUString& rFuncName ) const; 558*b1cdbd2cSJim Jagielski 559*b1cdbd2cSJim Jagielski /** Returns the function info for a BIFF12 function index, or 0 on error. */ 560*b1cdbd2cSJim Jagielski const FunctionInfo* getFuncInfoFromBiff12FuncId( sal_uInt16 nFuncId ) const; 561*b1cdbd2cSJim Jagielski 562*b1cdbd2cSJim Jagielski /** Returns the function info for a BIFF2-BIFF8 function index, or 0 on error. */ 563*b1cdbd2cSJim Jagielski const FunctionInfo* getFuncInfoFromBiffFuncId( sal_uInt16 nFuncId ) const; 564*b1cdbd2cSJim Jagielski 565*b1cdbd2cSJim Jagielski /** Returns the function info for a macro function referred by the 566*b1cdbd2cSJim Jagielski EXTERN.CALL function, or 0 on error. */ 567*b1cdbd2cSJim Jagielski const FunctionInfo* getFuncInfoFromMacroName( const ::rtl::OUString& rFuncName ) const; 568*b1cdbd2cSJim Jagielski 569*b1cdbd2cSJim Jagielski /** Returns the library type associated with the passed URL of a function 570*b1cdbd2cSJim Jagielski library (function add-in). */ 571*b1cdbd2cSJim Jagielski FunctionLibraryType getFuncLibTypeFromLibraryName( const ::rtl::OUString& rLibraryName ) const; 572*b1cdbd2cSJim Jagielski 573*b1cdbd2cSJim Jagielski protected: 574*b1cdbd2cSJim Jagielski /** Returns the list of all function infos. */ 575*b1cdbd2cSJim Jagielski const FunctionInfoVector& getFuncs() const; 576*b1cdbd2cSJim Jagielski 577*b1cdbd2cSJim Jagielski private: 578*b1cdbd2cSJim Jagielski typedef ::boost::shared_ptr< FunctionProviderImpl > FunctionProviderImplRef; 579*b1cdbd2cSJim Jagielski FunctionProviderImplRef mxFuncImpl; /// Shared implementation between all copies of the provider. 580*b1cdbd2cSJim Jagielski }; 581*b1cdbd2cSJim Jagielski 582*b1cdbd2cSJim Jagielski // Op-code and function provider ============================================== 583*b1cdbd2cSJim Jagielski 584*b1cdbd2cSJim Jagielski struct OpCodeProviderImpl; 585*b1cdbd2cSJim Jagielski 586*b1cdbd2cSJim Jagielski /** Provides access to API op-codes for all available formula tokens and to 587*b1cdbd2cSJim Jagielski function info structs for all available sheet functions. 588*b1cdbd2cSJim Jagielski */ 589*b1cdbd2cSJim Jagielski class OpCodeProvider : public FunctionProvider // not derived from WorkbookHelper to make it usable as UNO service 590*b1cdbd2cSJim Jagielski { 591*b1cdbd2cSJim Jagielski public: 592*b1cdbd2cSJim Jagielski explicit OpCodeProvider( 593*b1cdbd2cSJim Jagielski const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& rxModelFactory, 594*b1cdbd2cSJim Jagielski FilterType eFilter, BiffType eBiff, bool bImportFilter ); 595*b1cdbd2cSJim Jagielski virtual ~OpCodeProvider(); 596*b1cdbd2cSJim Jagielski 597*b1cdbd2cSJim Jagielski /** Returns the structure containing all token op-codes for operators and 598*b1cdbd2cSJim Jagielski special tokens used by the Calc document and its formula parser. */ 599*b1cdbd2cSJim Jagielski const ApiOpCodes& getOpCodes() const; 600*b1cdbd2cSJim Jagielski 601*b1cdbd2cSJim Jagielski /** Returns the function info for an API token, or 0 on error. */ 602*b1cdbd2cSJim Jagielski const FunctionInfo* getFuncInfoFromApiToken( const ApiToken& rToken ) const; 603*b1cdbd2cSJim Jagielski 604*b1cdbd2cSJim Jagielski /** Returns the op-code map that is used by the OOXML formula parser. */ 605*b1cdbd2cSJim Jagielski ::com::sun::star::uno::Sequence< ::com::sun::star::sheet::FormulaOpCodeMapEntry > 606*b1cdbd2cSJim Jagielski getOoxParserMap() const; 607*b1cdbd2cSJim Jagielski 608*b1cdbd2cSJim Jagielski private: 609*b1cdbd2cSJim Jagielski typedef ::boost::shared_ptr< OpCodeProviderImpl > OpCodeProviderImplRef; 610*b1cdbd2cSJim Jagielski OpCodeProviderImplRef mxOpCodeImpl; /// Shared implementation between all copies of the provider. 611*b1cdbd2cSJim Jagielski }; 612*b1cdbd2cSJim Jagielski 613*b1cdbd2cSJim Jagielski // API formula parser wrapper ================================================= 614*b1cdbd2cSJim Jagielski 615*b1cdbd2cSJim Jagielski /** A wrapper around the FormulaParser service provided by the Calc document. */ 616*b1cdbd2cSJim Jagielski class ApiParserWrapper : public OpCodeProvider 617*b1cdbd2cSJim Jagielski { 618*b1cdbd2cSJim Jagielski public: 619*b1cdbd2cSJim Jagielski explicit ApiParserWrapper( 620*b1cdbd2cSJim Jagielski const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& rxModelFactory, 621*b1cdbd2cSJim Jagielski const OpCodeProvider& rOpCodeProv ); 622*b1cdbd2cSJim Jagielski 623*b1cdbd2cSJim Jagielski /** Returns read/write access to the formula parser property set. */ getParserProperties()624*b1cdbd2cSJim Jagielski inline PropertySet& getParserProperties() { return maParserProps; } 625*b1cdbd2cSJim Jagielski 626*b1cdbd2cSJim Jagielski /** Calls the XFormulaParser::parseFormula() function of the API parser. */ 627*b1cdbd2cSJim Jagielski ApiTokenSequence parseFormula( 628*b1cdbd2cSJim Jagielski const ::rtl::OUString& rFormula, 629*b1cdbd2cSJim Jagielski const ::com::sun::star::table::CellAddress& rRefPos ); 630*b1cdbd2cSJim Jagielski 631*b1cdbd2cSJim Jagielski private: 632*b1cdbd2cSJim Jagielski ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XFormulaParser > 633*b1cdbd2cSJim Jagielski mxParser; 634*b1cdbd2cSJim Jagielski PropertySet maParserProps; 635*b1cdbd2cSJim Jagielski }; 636*b1cdbd2cSJim Jagielski 637*b1cdbd2cSJim Jagielski // Formula parser/printer base class for filters ============================== 638*b1cdbd2cSJim Jagielski 639*b1cdbd2cSJim Jagielski /** Base class for import formula parsers and export formula compilers. */ 640*b1cdbd2cSJim Jagielski class FormulaProcessorBase : public OpCodeProvider, protected ApiOpCodes, public WorkbookHelper 641*b1cdbd2cSJim Jagielski { 642*b1cdbd2cSJim Jagielski public: 643*b1cdbd2cSJim Jagielski explicit FormulaProcessorBase( const WorkbookHelper& rHelper ); 644*b1cdbd2cSJim Jagielski 645*b1cdbd2cSJim Jagielski // ------------------------------------------------------------------------ 646*b1cdbd2cSJim Jagielski 647*b1cdbd2cSJim Jagielski /** Generates a cell address string in A1 notation from the passed cell 648*b1cdbd2cSJim Jagielski address. 649*b1cdbd2cSJim Jagielski 650*b1cdbd2cSJim Jagielski @param rAddress The cell address containing column and row index. 651*b1cdbd2cSJim Jagielski @param bAbsolute True = adds dollar signs before column and row. 652*b1cdbd2cSJim Jagielski */ 653*b1cdbd2cSJim Jagielski static ::rtl::OUString generateAddress2dString( 654*b1cdbd2cSJim Jagielski const ::com::sun::star::table::CellAddress& rAddress, 655*b1cdbd2cSJim Jagielski bool bAbsolute ); 656*b1cdbd2cSJim Jagielski 657*b1cdbd2cSJim Jagielski /** Generates a cell address string in A1 notation from the passed binary 658*b1cdbd2cSJim Jagielski cell address. 659*b1cdbd2cSJim Jagielski 660*b1cdbd2cSJim Jagielski @param rAddress The cell address containing column and row index. 661*b1cdbd2cSJim Jagielski @param bAbsolute True = adds dollar signs before column and row. 662*b1cdbd2cSJim Jagielski */ 663*b1cdbd2cSJim Jagielski static ::rtl::OUString generateAddress2dString( 664*b1cdbd2cSJim Jagielski const BinAddress& rAddress, 665*b1cdbd2cSJim Jagielski bool bAbsolute ); 666*b1cdbd2cSJim Jagielski 667*b1cdbd2cSJim Jagielski /** Generates a cell range string in A1:A1 notation from the passed cell 668*b1cdbd2cSJim Jagielski range address. 669*b1cdbd2cSJim Jagielski 670*b1cdbd2cSJim Jagielski @param rRange The cell range address containing column and row indexes. 671*b1cdbd2cSJim Jagielski @param bAbsolute True = adds dollar signs before columns and rows. 672*b1cdbd2cSJim Jagielski */ 673*b1cdbd2cSJim Jagielski static ::rtl::OUString generateRange2dString( 674*b1cdbd2cSJim Jagielski const ::com::sun::star::table::CellRangeAddress& rRange, 675*b1cdbd2cSJim Jagielski bool bAbsolute ); 676*b1cdbd2cSJim Jagielski 677*b1cdbd2cSJim Jagielski /** Generates a cell range string in A1:A1 notation from the passed binary 678*b1cdbd2cSJim Jagielski cell range address. 679*b1cdbd2cSJim Jagielski 680*b1cdbd2cSJim Jagielski @param rRange The cell range address containing column and row indexes. 681*b1cdbd2cSJim Jagielski @param bAbsolute True = adds dollar signs before columns and rows. 682*b1cdbd2cSJim Jagielski */ 683*b1cdbd2cSJim Jagielski static ::rtl::OUString generateRange2dString( 684*b1cdbd2cSJim Jagielski const BinRange& rRange, 685*b1cdbd2cSJim Jagielski bool bAbsolute ); 686*b1cdbd2cSJim Jagielski 687*b1cdbd2cSJim Jagielski /** Generates a cell range list string in A1:A1 notation from the passed 688*b1cdbd2cSJim Jagielski cell range addresses. May enclose multiple ranges into parentheses. 689*b1cdbd2cSJim Jagielski 690*b1cdbd2cSJim Jagielski @param rRanges The list of cell range addresses. 691*b1cdbd2cSJim Jagielski @param bAbsolute True = adds dollar signs before columns and rows. 692*b1cdbd2cSJim Jagielski @param cSeparator Separator character between ranges. 693*b1cdbd2cSJim Jagielski @param bEncloseMultiple True = enclose multiple ranges in parentheses. 694*b1cdbd2cSJim Jagielski */ 695*b1cdbd2cSJim Jagielski static ::rtl::OUString generateRangeList2dString( 696*b1cdbd2cSJim Jagielski const ApiCellRangeList& rRanges, 697*b1cdbd2cSJim Jagielski bool bAbsolute, 698*b1cdbd2cSJim Jagielski sal_Unicode cSeparator, 699*b1cdbd2cSJim Jagielski bool bEncloseMultiple ); 700*b1cdbd2cSJim Jagielski 701*b1cdbd2cSJim Jagielski // ------------------------------------------------------------------------ 702*b1cdbd2cSJim Jagielski 703*b1cdbd2cSJim Jagielski /** Generates a cell address string in Calc's absolute $Sheet.$A$1 notation 704*b1cdbd2cSJim Jagielski from the passed cell address. 705*b1cdbd2cSJim Jagielski 706*b1cdbd2cSJim Jagielski @param rAddress The cell address to be converted to a string. 707*b1cdbd2cSJim Jagielski */ 708*b1cdbd2cSJim Jagielski ::rtl::OUString generateApiAddressString( 709*b1cdbd2cSJim Jagielski const ::com::sun::star::table::CellAddress& rAddress ) const; 710*b1cdbd2cSJim Jagielski 711*b1cdbd2cSJim Jagielski /** Generates a cell range string in Calc's absolute $Sheet.$A$1:$A$ 712*b1cdbd2cSJim Jagielski notation from the passed cell range address. 713*b1cdbd2cSJim Jagielski 714*b1cdbd2cSJim Jagielski @param rRange The cell range address to be converted to a string. 715*b1cdbd2cSJim Jagielski */ 716*b1cdbd2cSJim Jagielski ::rtl::OUString generateApiRangeString( 717*b1cdbd2cSJim Jagielski const ::com::sun::star::table::CellRangeAddress& rRange ) const; 718*b1cdbd2cSJim Jagielski 719*b1cdbd2cSJim Jagielski /** Generates a cell range list string in Calc's absolute $Sheet.$A$1:$A$1 720*b1cdbd2cSJim Jagielski notation from the passed cell range addresses. 721*b1cdbd2cSJim Jagielski 722*b1cdbd2cSJim Jagielski @param rRanges The list of cell ranges to be converted to a string. 723*b1cdbd2cSJim Jagielski */ 724*b1cdbd2cSJim Jagielski ::rtl::OUString generateApiRangeListString( const ApiCellRangeList& rRanges ) const; 725*b1cdbd2cSJim Jagielski 726*b1cdbd2cSJim Jagielski /** Generates a string in Calc formula notation from the passed string. 727*b1cdbd2cSJim Jagielski 728*b1cdbd2cSJim Jagielski @param rString The string value. 729*b1cdbd2cSJim Jagielski 730*b1cdbd2cSJim Jagielski @return The string enclosed in double quotes, where all contained 731*b1cdbd2cSJim Jagielski quote characters are doubled. 732*b1cdbd2cSJim Jagielski */ 733*b1cdbd2cSJim Jagielski static ::rtl::OUString generateApiString( const ::rtl::OUString& rString ); 734*b1cdbd2cSJim Jagielski 735*b1cdbd2cSJim Jagielski /** Generates an array string in Calc formula notation from the passed 736*b1cdbd2cSJim Jagielski matrix with Any's containing double values or strings. 737*b1cdbd2cSJim Jagielski 738*b1cdbd2cSJim Jagielski @param rMatrix The matrix containing double values or strings. 739*b1cdbd2cSJim Jagielski */ 740*b1cdbd2cSJim Jagielski static ::rtl::OUString generateApiArray( const Matrix< ::com::sun::star::uno::Any >& rMatrix ); 741*b1cdbd2cSJim Jagielski 742*b1cdbd2cSJim Jagielski // ------------------------------------------------------------------------ 743*b1cdbd2cSJim Jagielski 744*b1cdbd2cSJim Jagielski /** Tries to extract a single cell reference from a formula token sequence. 745*b1cdbd2cSJim Jagielski 746*b1cdbd2cSJim Jagielski @param rTokens The token sequence to be parsed. Should contain exactly 747*b1cdbd2cSJim Jagielski one address token or cell range address token. The token sequence 748*b1cdbd2cSJim Jagielski may contain whitespace tokens. 749*b1cdbd2cSJim Jagielski 750*b1cdbd2cSJim Jagielski @return If the token sequence is valid, this function returns an Any 751*b1cdbd2cSJim Jagielski containing a com.sun.star.sheet.SingleReference object, or a 752*b1cdbd2cSJim Jagielski com.sun.star.sheet.ComplexReference object. If the token sequence 753*b1cdbd2cSJim Jagielski contains too many, or unexpected tokens, an empty Any is returned. 754*b1cdbd2cSJim Jagielski */ 755*b1cdbd2cSJim Jagielski ::com::sun::star::uno::Any 756*b1cdbd2cSJim Jagielski extractReference( const ApiTokenSequence& rTokens ) const; 757*b1cdbd2cSJim Jagielski 758*b1cdbd2cSJim Jagielski /** Tries to extract a single cell address from a formula token sequence. 759*b1cdbd2cSJim Jagielski 760*b1cdbd2cSJim Jagielski @param orAddress (output parameter) If the token sequence is valid, 761*b1cdbd2cSJim Jagielski this parameter will contain the extracted cell address. If the 762*b1cdbd2cSJim Jagielski token sequence contains unexpected tokens, nothing meaningful is 763*b1cdbd2cSJim Jagielski inserted, and the function returns false. 764*b1cdbd2cSJim Jagielski 765*b1cdbd2cSJim Jagielski @param rTokens The token sequence to be parsed. Should contain exactly 766*b1cdbd2cSJim Jagielski one cell address token. The token sequence may contain whitespace 767*b1cdbd2cSJim Jagielski tokens. 768*b1cdbd2cSJim Jagielski 769*b1cdbd2cSJim Jagielski @param bAllowRelative True = it is allowed that rTokens contains 770*b1cdbd2cSJim Jagielski relative references (based on cell A1 of the current sheet). 771*b1cdbd2cSJim Jagielski False = only real absolute references will be accepted. 772*b1cdbd2cSJim Jagielski 773*b1cdbd2cSJim Jagielski @return True, if the token sequence contains a valid cell address 774*b1cdbd2cSJim Jagielski which has been extracted to orAddress, false otherwise. 775*b1cdbd2cSJim Jagielski */ 776*b1cdbd2cSJim Jagielski bool extractCellAddress( 777*b1cdbd2cSJim Jagielski ::com::sun::star::table::CellAddress& orAddress, 778*b1cdbd2cSJim Jagielski const ApiTokenSequence& rTokens, 779*b1cdbd2cSJim Jagielski bool bAllowRelative ) const; 780*b1cdbd2cSJim Jagielski 781*b1cdbd2cSJim Jagielski /** Tries to extract a cell range address from a formula token sequence. 782*b1cdbd2cSJim Jagielski 783*b1cdbd2cSJim Jagielski @param orAddress (output parameter) If the token sequence is valid, 784*b1cdbd2cSJim Jagielski this parameter will contain the extracted cell range address. If 785*b1cdbd2cSJim Jagielski the token sequence contains unexpected tokens, nothing meaningful 786*b1cdbd2cSJim Jagielski is inserted, and the function returns false. 787*b1cdbd2cSJim Jagielski 788*b1cdbd2cSJim Jagielski @param rTokens The token sequence to be parsed. Should contain exactly 789*b1cdbd2cSJim Jagielski one cell range address token. The token sequence may contain 790*b1cdbd2cSJim Jagielski whitespace tokens. 791*b1cdbd2cSJim Jagielski 792*b1cdbd2cSJim Jagielski @param bAllowRelative True = it is allowed that rTokens contains 793*b1cdbd2cSJim Jagielski relative references (based on cell A1 of the current sheet). 794*b1cdbd2cSJim Jagielski False = only real absolute references will be accepted. 795*b1cdbd2cSJim Jagielski 796*b1cdbd2cSJim Jagielski @return True, if the token sequence contains a valid cell range 797*b1cdbd2cSJim Jagielski address which has been extracted to orRange, false otherwise. 798*b1cdbd2cSJim Jagielski */ 799*b1cdbd2cSJim Jagielski bool extractCellRange( 800*b1cdbd2cSJim Jagielski ::com::sun::star::table::CellRangeAddress& orRange, 801*b1cdbd2cSJim Jagielski const ApiTokenSequence& rTokens, 802*b1cdbd2cSJim Jagielski bool bAllowRelative ) const; 803*b1cdbd2cSJim Jagielski 804*b1cdbd2cSJim Jagielski /** Tries to extract a cell range list from a formula token sequence. 805*b1cdbd2cSJim Jagielski 806*b1cdbd2cSJim Jagielski @param orRanges (output parameter) If the token sequence is valid, 807*b1cdbd2cSJim Jagielski this parameter will contain the extracted cell range list. Deleted 808*b1cdbd2cSJim Jagielski cells or cell ranges (shown as #REF! error in a formula) will be 809*b1cdbd2cSJim Jagielski skipped. If the token sequence contains unexpected tokens, an empty 810*b1cdbd2cSJim Jagielski list is returned here. 811*b1cdbd2cSJim Jagielski 812*b1cdbd2cSJim Jagielski @param rTokens The token sequence to be parsed. Should contain cell 813*b1cdbd2cSJim Jagielski address tokens or cell range address tokens, separated by the 814*b1cdbd2cSJim Jagielski standard function parameter separator token. The token sequence may 815*b1cdbd2cSJim Jagielski contain parentheses and whitespace tokens. 816*b1cdbd2cSJim Jagielski 817*b1cdbd2cSJim Jagielski @param bAllowRelative True = it is allowed that rTokens contains 818*b1cdbd2cSJim Jagielski relative references (based on cell A1 of the current sheet). 819*b1cdbd2cSJim Jagielski False = only real absolute references will be accepted. 820*b1cdbd2cSJim Jagielski 821*b1cdbd2cSJim Jagielski @param nFilterBySheet If non-negative, this function returns only cell 822*b1cdbd2cSJim Jagielski ranges located in the specified sheet, otherwise returns all cell 823*b1cdbd2cSJim Jagielski ranges contained in the token sequence. 824*b1cdbd2cSJim Jagielski */ 825*b1cdbd2cSJim Jagielski void extractCellRangeList( 826*b1cdbd2cSJim Jagielski ApiCellRangeList& orRanges, 827*b1cdbd2cSJim Jagielski const ApiTokenSequence& rTokens, 828*b1cdbd2cSJim Jagielski bool bAllowRelative, 829*b1cdbd2cSJim Jagielski sal_Int32 nFilterBySheet = -1 ) const; 830*b1cdbd2cSJim Jagielski 831*b1cdbd2cSJim Jagielski /** Tries to extract a string from a formula token sequence. 832*b1cdbd2cSJim Jagielski 833*b1cdbd2cSJim Jagielski @param orString (output parameter) The extracted string. 834*b1cdbd2cSJim Jagielski 835*b1cdbd2cSJim Jagielski @param rTokens The token sequence to be parsed. Should contain exactly 836*b1cdbd2cSJim Jagielski one string token, may contain whitespace tokens. 837*b1cdbd2cSJim Jagielski 838*b1cdbd2cSJim Jagielski @return True = token sequence is valid, output parameter orString 839*b1cdbd2cSJim Jagielski contains the string extracted from the token sequence. 840*b1cdbd2cSJim Jagielski */ 841*b1cdbd2cSJim Jagielski bool extractString( 842*b1cdbd2cSJim Jagielski ::rtl::OUString& orString, 843*b1cdbd2cSJim Jagielski const ApiTokenSequence& rTokens ) const; 844*b1cdbd2cSJim Jagielski 845*b1cdbd2cSJim Jagielski /** Tries to extract information about a special token used for array 846*b1cdbd2cSJim Jagielski formulas, shared formulas, or table operations. 847*b1cdbd2cSJim Jagielski 848*b1cdbd2cSJim Jagielski @param orTokenInfo (output parameter) The extracted information about 849*b1cdbd2cSJim Jagielski the token. Contains the base address and the token type (sal_False 850*b1cdbd2cSJim Jagielski for array or shared formulas, sal_True for table operations). 851*b1cdbd2cSJim Jagielski 852*b1cdbd2cSJim Jagielski @param rTokens The token sequence to be parsed. If it contains exactly 853*b1cdbd2cSJim Jagielski one OPCODE_BAD token with special token information, this 854*b1cdbd2cSJim Jagielski information will be extracted. 855*b1cdbd2cSJim Jagielski 856*b1cdbd2cSJim Jagielski @return True = token sequence is valid, output parameter orTokenInfo 857*b1cdbd2cSJim Jagielski contains the token information extracted from the token sequence. 858*b1cdbd2cSJim Jagielski */ 859*b1cdbd2cSJim Jagielski bool extractSpecialTokenInfo( 860*b1cdbd2cSJim Jagielski ApiSpecialTokenInfo& orTokenInfo, 861*b1cdbd2cSJim Jagielski const ApiTokenSequence& rTokens ) const; 862*b1cdbd2cSJim Jagielski 863*b1cdbd2cSJim Jagielski /** Converts a single string with separators in the passed formula token 864*b1cdbd2cSJim Jagielski sequence to a list of string tokens. 865*b1cdbd2cSJim Jagielski 866*b1cdbd2cSJim Jagielski @param orTokens (input/output parameter) Expects a single string token 867*b1cdbd2cSJim Jagielski in this token sequence (whitespace tokens are allowed). The string 868*b1cdbd2cSJim Jagielski is split into substrings. A list of string tokens separated with 869*b1cdbd2cSJim Jagielski parameter separator tokens is returned in this psrameter. 870*b1cdbd2cSJim Jagielski 871*b1cdbd2cSJim Jagielski @param cStringSep The separator character used to split the input 872*b1cdbd2cSJim Jagielski string. 873*b1cdbd2cSJim Jagielski 874*b1cdbd2cSJim Jagielski @param bTrimLeadingSpaces True = removes leading whitespace from all 875*b1cdbd2cSJim Jagielski substrings inserted into the formula token sequence. 876*b1cdbd2cSJim Jagielski */ 877*b1cdbd2cSJim Jagielski void convertStringToStringList( 878*b1cdbd2cSJim Jagielski ApiTokenSequence& orTokens, 879*b1cdbd2cSJim Jagielski sal_Unicode cStringSep, 880*b1cdbd2cSJim Jagielski bool bTrimLeadingSpaces ) const; 881*b1cdbd2cSJim Jagielski }; 882*b1cdbd2cSJim Jagielski 883*b1cdbd2cSJim Jagielski // ============================================================================ 884*b1cdbd2cSJim Jagielski 885*b1cdbd2cSJim Jagielski } // namespace xls 886*b1cdbd2cSJim Jagielski } // namespace oox 887*b1cdbd2cSJim Jagielski 888*b1cdbd2cSJim Jagielski #endif 889