28 define(
'SPREADSHEET_EXCEL_WRITER_ADD',
"+");
33 define(
'SPREADSHEET_EXCEL_WRITER_SUB',
"-");
38 define(
'SPREADSHEET_EXCEL_WRITER_MUL',
"*");
43 define(
'SPREADSHEET_EXCEL_WRITER_DIV',
"/");
48 define(
'SPREADSHEET_EXCEL_WRITER_OPEN',
"(");
53 define(
'SPREADSHEET_EXCEL_WRITER_CLOSE',
")");
58 define(
'SPREADSHEET_EXCEL_WRITER_COMA',
",");
63 define(
'SPREADSHEET_EXCEL_WRITER_SEMICOLON',
";");
68 define(
'SPREADSHEET_EXCEL_WRITER_GT',
">");
73 define(
'SPREADSHEET_EXCEL_WRITER_LT',
"<");
78 define(
'SPREADSHEET_EXCEL_WRITER_LE',
"<=");
83 define(
'SPREADSHEET_EXCEL_WRITER_GE',
">=");
88 define(
'SPREADSHEET_EXCEL_WRITER_EQ',
"=");
93 define(
'SPREADSHEET_EXCEL_WRITER_NE',
"<>");
96 require_once(
'PEAR.php');
170 $this->_current_char = 0;
171 $this->_BIFF_version = $biff_version;
172 $this->_current_token =
'';
173 $this->_formula =
"";
174 $this->_lookahead =
'';
175 $this->_parse_tree =
'';
177 $this->_byte_order = $byte_order;
178 $this->_ext_sheets = array();
179 $this->_references = array();
210 'ptgPercent' => 0x14,
212 'ptgMissArg' => 0x16,
216 'ptgEndSheet' => 0x1B,
223 'ptgFuncVar' => 0x22,
227 'ptgMemArea' => 0x26,
229 'ptgMemNoMem' => 0x28,
230 'ptgMemFunc' => 0x29,
232 'ptgAreaErr' => 0x2B,
235 'ptgMemAreaN' => 0x2E,
236 'ptgMemNoMemN' => 0x2F,
240 'ptgRefErr3d' => 0x3C,
241 'ptgAreaErr3d' => 0x3D,
244 'ptgFuncVarV' => 0x42,
248 'ptgMemAreaV' => 0x46,
249 'ptgMemErrV' => 0x47,
250 'ptgMemNoMemV' => 0x48,
251 'ptgMemFuncV' => 0x49,
252 'ptgRefErrV' => 0x4A,
253 'ptgAreaErrV' => 0x4B,
256 'ptgMemAreaNV' => 0x4E,
257 'ptgMemNoMemN' => 0x4F,
258 'ptgFuncCEV' => 0x58,
261 'ptgArea3dV' => 0x5B,
262 'ptgRefErr3dV' => 0x5C,
263 'ptgAreaErr3d' => 0x5D,
266 'ptgFuncVarA' => 0x62,
270 'ptgMemAreaA' => 0x66,
271 'ptgMemErrA' => 0x67,
272 'ptgMemNoMemA' => 0x68,
273 'ptgMemFuncA' => 0x69,
274 'ptgRefErrA' => 0x6A,
275 'ptgAreaErrA' => 0x6B,
278 'ptgMemAreaNA' => 0x6E,
279 'ptgMemNoMemN' => 0x6F,
280 'ptgFuncCEA' => 0x78,
283 'ptgArea3dA' => 0x7B,
284 'ptgRefErr3dA' => 0x7C,
285 'ptgAreaErr3d' => 0x7D
301 $this->_functions = array(
303 'COUNT' => array( 0, -1, 0, 0 ),
304 'IF' => array( 1, -1, 1, 0 ),
305 'ISNA' => array( 2, 1, 1, 0 ),
306 'ISERROR' => array( 3, 1, 1, 0 ),
307 'SUM' => array( 4, -1, 0, 0 ),
308 'AVERAGE' => array( 5, -1, 0, 0 ),
309 'MIN' => array( 6, -1, 0, 0 ),
310 'MAX' => array( 7, -1, 0, 0 ),
311 'ROW' => array( 8, -1, 0, 0 ),
312 'COLUMN' => array( 9, -1, 0, 0 ),
313 'NA' => array( 10, 0, 0, 0 ),
314 'NPV' => array( 11, -1, 1, 0 ),
315 'STDEV' => array( 12, -1, 0, 0 ),
316 'DOLLAR' => array( 13, -1, 1, 0 ),
317 'FIXED' => array( 14, -1, 1, 0 ),
318 'SIN' => array( 15, 1, 1, 0 ),
319 'COS' => array( 16, 1, 1, 0 ),
320 'TAN' => array( 17, 1, 1, 0 ),
321 'ATAN' => array( 18, 1, 1, 0 ),
322 'PI' => array( 19, 0, 1, 0 ),
323 'SQRT' => array( 20, 1, 1, 0 ),
324 'EXP' => array( 21, 1, 1, 0 ),
325 'LN' => array( 22, 1, 1, 0 ),
326 'LOG10' => array( 23, 1, 1, 0 ),
327 'ABS' => array( 24, 1, 1, 0 ),
328 'INT' => array( 25, 1, 1, 0 ),
329 'SIGN' => array( 26, 1, 1, 0 ),
330 'ROUND' => array( 27, 2, 1, 0 ),
331 'LOOKUP' => array( 28, -1, 0, 0 ),
332 'INDEX' => array( 29, -1, 0, 1 ),
333 'REPT' => array( 30, 2, 1, 0 ),
334 'MID' => array( 31, 3, 1, 0 ),
335 'LEN' => array( 32, 1, 1, 0 ),
336 'VALUE' => array( 33, 1, 1, 0 ),
337 'TRUE' => array( 34, 0, 1, 0 ),
338 'FALSE' => array( 35, 0, 1, 0 ),
339 'AND' => array( 36, -1, 0, 0 ),
340 'OR' => array( 37, -1, 0, 0 ),
341 'NOT' => array( 38, 1, 1, 0 ),
342 'MOD' => array( 39, 2, 1, 0 ),
343 'DCOUNT' => array( 40, 3, 0, 0 ),
344 'DSUM' => array( 41, 3, 0, 0 ),
345 'DAVERAGE' => array( 42, 3, 0, 0 ),
346 'DMIN' => array( 43, 3, 0, 0 ),
347 'DMAX' => array( 44, 3, 0, 0 ),
348 'DSTDEV' => array( 45, 3, 0, 0 ),
349 'VAR' => array( 46, -1, 0, 0 ),
350 'DVAR' => array( 47, 3, 0, 0 ),
351 'TEXT' => array( 48, 2, 1, 0 ),
352 'LINEST' => array( 49, -1, 0, 0 ),
353 'TREND' => array( 50, -1, 0, 0 ),
354 'LOGEST' => array( 51, -1, 0, 0 ),
355 'GROWTH' => array( 52, -1, 0, 0 ),
356 'PV' => array( 56, -1, 1, 0 ),
357 'FV' => array( 57, -1, 1, 0 ),
358 'NPER' => array( 58, -1, 1, 0 ),
359 'PMT' => array( 59, -1, 1, 0 ),
360 'RATE' => array( 60, -1, 1, 0 ),
361 'MIRR' => array( 61, 3, 0, 0 ),
362 'IRR' => array( 62, -1, 0, 0 ),
363 'RAND' => array( 63, 0, 1, 1 ),
364 'MATCH' => array( 64, -1, 0, 0 ),
365 'DATE' => array( 65, 3, 1, 0 ),
366 'TIME' => array( 66, 3, 1, 0 ),
367 'DAY' => array( 67, 1, 1, 0 ),
368 'MONTH' => array( 68, 1, 1, 0 ),
369 'YEAR' => array( 69, 1, 1, 0 ),
370 'WEEKDAY' => array( 70, -1, 1, 0 ),
371 'HOUR' => array( 71, 1, 1, 0 ),
372 'MINUTE' => array( 72, 1, 1, 0 ),
373 'SECOND' => array( 73, 1, 1, 0 ),
374 'NOW' => array( 74, 0, 1, 1 ),
375 'AREAS' => array( 75, 1, 0, 1 ),
376 'ROWS' => array( 76, 1, 0, 1 ),
377 'COLUMNS' => array( 77, 1, 0, 1 ),
378 'OFFSET' => array( 78, -1, 0, 1 ),
379 'SEARCH' => array( 82, -1, 1, 0 ),
380 'TRANSPOSE' => array( 83, 1, 1, 0 ),
381 'TYPE' => array( 86, 1, 1, 0 ),
382 'ATAN2' => array( 97, 2, 1, 0 ),
383 'ASIN' => array( 98, 1, 1, 0 ),
384 'ACOS' => array( 99, 1, 1, 0 ),
385 'CHOOSE' => array( 100, -1, 1, 0 ),
386 'HLOOKUP' => array( 101, -1, 0, 0 ),
387 'VLOOKUP' => array( 102, -1, 0, 0 ),
388 'ISREF' => array( 105, 1, 0, 0 ),
389 'LOG' => array( 109, -1, 1, 0 ),
390 'CHAR' => array( 111, 1, 1, 0 ),
391 'LOWER' => array( 112, 1, 1, 0 ),
392 'UPPER' => array( 113, 1, 1, 0 ),
393 'PROPER' => array( 114, 1, 1, 0 ),
394 'LEFT' => array( 115, -1, 1, 0 ),
395 'RIGHT' => array( 116, -1, 1, 0 ),
396 'EXACT' => array( 117, 2, 1, 0 ),
397 'TRIM' => array( 118, 1, 1, 0 ),
398 'REPLACE' => array( 119, 4, 1, 0 ),
399 'SUBSTITUTE' => array( 120, -1, 1, 0 ),
400 'CODE' => array( 121, 1, 1, 0 ),
401 'FIND' => array( 124, -1, 1, 0 ),
402 'CELL' => array( 125, -1, 0, 1 ),
403 'ISERR' => array( 126, 1, 1, 0 ),
404 'ISTEXT' => array( 127, 1, 1, 0 ),
405 'ISNUMBER' => array( 128, 1, 1, 0 ),
406 'ISBLANK' => array( 129, 1, 1, 0 ),
407 'T' => array( 130, 1, 0, 0 ),
408 'N' => array( 131, 1, 0, 0 ),
409 'DATEVALUE' => array( 140, 1, 1, 0 ),
410 'TIMEVALUE' => array( 141, 1, 1, 0 ),
411 'SLN' => array( 142, 3, 1, 0 ),
412 'SYD' => array( 143, 4, 1, 0 ),
413 'DDB' => array( 144, -1, 1, 0 ),
414 'INDIRECT' => array( 148, -1, 1, 1 ),
415 'CALL' => array( 150, -1, 1, 0 ),
416 'CLEAN' => array( 162, 1, 1, 0 ),
417 'MDETERM' => array( 163, 1, 2, 0 ),
418 'MINVERSE' => array( 164, 1, 2, 0 ),
419 'MMULT' => array( 165, 2, 2, 0 ),
420 'IPMT' => array( 167, -1, 1, 0 ),
421 'PPMT' => array( 168, -1, 1, 0 ),
422 'COUNTA' => array( 169, -1, 0, 0 ),
423 'PRODUCT' => array( 183, -1, 0, 0 ),
424 'FACT' => array( 184, 1, 1, 0 ),
425 'DPRODUCT' => array( 189, 3, 0, 0 ),
426 'ISNONTEXT' => array( 190, 1, 1, 0 ),
427 'STDEVP' => array( 193, -1, 0, 0 ),
428 'VARP' => array( 194, -1, 0, 0 ),
429 'DSTDEVP' => array( 195, 3, 0, 0 ),
430 'DVARP' => array( 196, 3, 0, 0 ),
431 'TRUNC' => array( 197, -1, 1, 0 ),
432 'ISLOGICAL' => array( 198, 1, 1, 0 ),
433 'DCOUNTA' => array( 199, 3, 0, 0 ),
434 'ROUNDUP' => array( 212, 2, 1, 0 ),
435 'ROUNDDOWN' => array( 213, 2, 1, 0 ),
436 'RANK' => array( 216, -1, 0, 0 ),
437 'ADDRESS' => array( 219, -1, 1, 0 ),
438 'DAYS360' => array( 220, -1, 1, 0 ),
439 'TODAY' => array( 221, 0, 1, 1 ),
440 'VDB' => array( 222, -1, 1, 0 ),
441 'MEDIAN' => array( 227, -1, 0, 0 ),
442 'SUMPRODUCT' => array( 228, -1, 2, 0 ),
443 'SINH' => array( 229, 1, 1, 0 ),
444 'COSH' => array( 230, 1, 1, 0 ),
445 'TANH' => array( 231, 1, 1, 0 ),
446 'ASINH' => array( 232, 1, 1, 0 ),
447 'ACOSH' => array( 233, 1, 1, 0 ),
448 'ATANH' => array( 234, 1, 1, 0 ),
449 'DGET' => array( 235, 3, 0, 0 ),
450 'INFO' => array( 244, 1, 1, 1 ),
451 'DB' => array( 247, -1, 1, 0 ),
452 'FREQUENCY' => array( 252, 2, 0, 0 ),
453 'ERROR.TYPE' => array( 261, 1, 1, 0 ),
454 'REGISTER.ID' => array( 267, -1, 1, 0 ),
455 'AVEDEV' => array( 269, -1, 0, 0 ),
456 'BETADIST' => array( 270, -1, 1, 0 ),
457 'GAMMALN' => array( 271, 1, 1, 0 ),
458 'BETAINV' => array( 272, -1, 1, 0 ),
459 'BINOMDIST' => array( 273, 4, 1, 0 ),
460 'CHIDIST' => array( 274, 2, 1, 0 ),
461 'CHIINV' => array( 275, 2, 1, 0 ),
462 'COMBIN' => array( 276, 2, 1, 0 ),
463 'CONFIDENCE' => array( 277, 3, 1, 0 ),
464 'CRITBINOM' => array( 278, 3, 1, 0 ),
465 'EVEN' => array( 279, 1, 1, 0 ),
466 'EXPONDIST' => array( 280, 3, 1, 0 ),
467 'FDIST' => array( 281, 3, 1, 0 ),
468 'FINV' => array( 282, 3, 1, 0 ),
469 'FISHER' => array( 283, 1, 1, 0 ),
470 'FISHERINV' => array( 284, 1, 1, 0 ),
471 'FLOOR' => array( 285, 2, 1, 0 ),
472 'GAMMADIST' => array( 286, 4, 1, 0 ),
473 'GAMMAINV' => array( 287, 3, 1, 0 ),
474 'CEILING' => array( 288, 2, 1, 0 ),
475 'HYPGEOMDIST' => array( 289, 4, 1, 0 ),
476 'LOGNORMDIST' => array( 290, 3, 1, 0 ),
477 'LOGINV' => array( 291, 3, 1, 0 ),
478 'NEGBINOMDIST' => array( 292, 3, 1, 0 ),
479 'NORMDIST' => array( 293, 4, 1, 0 ),
480 'NORMSDIST' => array( 294, 1, 1, 0 ),
481 'NORMINV' => array( 295, 3, 1, 0 ),
482 'NORMSINV' => array( 296, 1, 1, 0 ),
483 'STANDARDIZE' => array( 297, 3, 1, 0 ),
484 'ODD' => array( 298, 1, 1, 0 ),
485 'PERMUT' => array( 299, 2, 1, 0 ),
486 'POISSON' => array( 300, 3, 1, 0 ),
487 'TDIST' => array( 301, 3, 1, 0 ),
488 'WEIBULL' => array( 302, 4, 1, 0 ),
489 'SUMXMY2' => array( 303, 2, 2, 0 ),
490 'SUMX2MY2' => array( 304, 2, 2, 0 ),
491 'SUMX2PY2' => array( 305, 2, 2, 0 ),
492 'CHITEST' => array( 306, 2, 2, 0 ),
493 'CORREL' => array( 307, 2, 2, 0 ),
494 'COVAR' => array( 308, 2, 2, 0 ),
495 'FORECAST' => array( 309, 3, 2, 0 ),
496 'FTEST' => array( 310, 2, 2, 0 ),
497 'INTERCEPT' => array( 311, 2, 2, 0 ),
498 'PEARSON' => array( 312, 2, 2, 0 ),
499 'RSQ' => array( 313, 2, 2, 0 ),
500 'STEYX' => array( 314, 2, 2, 0 ),
501 'SLOPE' => array( 315, 2, 2, 0 ),
502 'TTEST' => array( 316, 4, 2, 0 ),
503 'PROB' => array( 317, -1, 2, 0 ),
504 'DEVSQ' => array( 318, -1, 0, 0 ),
505 'GEOMEAN' => array( 319, -1, 0, 0 ),
506 'HARMEAN' => array( 320, -1, 0, 0 ),
507 'SUMSQ' => array( 321, -1, 0, 0 ),
508 'KURT' => array( 322, -1, 0, 0 ),
509 'SKEW' => array( 323, -1, 0, 0 ),
510 'ZTEST' => array( 324, -1, 0, 0 ),
511 'LARGE' => array( 325, 2, 0, 0 ),
512 'SMALL' => array( 326, 2, 0, 0 ),
513 'QUARTILE' => array( 327, 2, 0, 0 ),
514 'PERCENTILE' => array( 328, 2, 0, 0 ),
515 'PERCENTRANK' => array( 329, -1, 0, 0 ),
516 'MODE' => array( 330, -1, 2, 0 ),
517 'TRIMMEAN' => array( 331, 2, 0, 0 ),
518 'TINV' => array( 332, 2, 1, 0 ),
519 'CONCATENATE' => array( 336, -1, 1, 0 ),
520 'POWER' => array( 337, 2, 1, 0 ),
521 'RADIANS' => array( 342, 1, 1, 0 ),
522 'DEGREES' => array( 343, 1, 1, 0 ),
523 'SUBTOTAL' => array( 344, -1, 0, 0 ),
524 'SUMIF' => array( 345, -1, 0, 0 ),
525 'COUNTIF' => array( 346, 2, 0, 0 ),
526 'COUNTBLANK' => array( 347, 1, 0, 0 ),
527 'ROMAN' => array( 354, -1, 1, 0 )
541 if (preg_match(
"/^\"[^\"]{0,255}\"$/", $token))
545 elseif (is_numeric($token))
550 elseif (preg_match(
'/^\$?([A-Ia-i]?[A-Za-z])\$?(\d+)$/',$token))
555 elseif (preg_match(
"/^\w+(\:\w+)?\![A-Ia-i]?[A-Za-z](\d+)$/",$token))
560 elseif (preg_match(
"/^'\w+(\:\w+)?'\![A-Ia-i]?[A-Za-z](\d+)$/",$token))
565 elseif (preg_match(
"/^(\$)?[A-Ia-i]?[A-Za-z](\$)?(\d+)\:(\$)?[A-Ia-i]?[A-Za-z](\$)?(\d+)$/",$token))
570 elseif (preg_match(
"/^(\$)?[A-Ia-i]?[A-Za-z](\$)?(\d+)\.\.(\$)?[A-Ia-i]?[A-Za-z](\$)?(\d+)$/",$token))
575 elseif (preg_match(
"/^\w+(\:\w+)?\!([A-Ia-i]?[A-Za-z])?(\d+)\:([A-Ia-i]?[A-Za-z])?(\d+)$/",$token))
580 elseif (preg_match(
"/^'\w+(\:\w+)?'\!([A-Ia-i]?[A-Za-z])?(\d+)\:([A-Ia-i]?[A-Za-z])?(\d+)$/",$token))
584 elseif (isset($this->ptg[$token]))
586 return pack(
"C", $this->ptg[$token]);
594 elseif ($token ==
'arg')
599 return $this->
raiseError(
"Unknown token $token");
611 if ((preg_match(
"/^\d+$/",$num)) and ($num <= 65535)) {
612 return pack(
"Cv", $this->ptg[
'ptgInt'], $num);
616 if ($this->_byte_order) {
619 return pack(
"Cd", $this->ptg[
'ptgNum'], $num);
634 $string = substr($string, 1, strlen($string) - 2);
635 if (strlen($string) > 255) {
636 return $this->
raiseError(
"String is too long");
638 if ($this->_BIFF_version == 0x0500) {
639 return pack(
"CC", $this->ptg[
'ptgStr'], strlen($string)).$string;
641 elseif ($this->_BIFF_version == 0x0600) {
643 return pack(
"CCC", $this->ptg[
'ptgStr'], strlen($string), $encoding).$string;
658 $args = $this->_functions[$token][1];
659 $volatile = $this->_functions[$token][3];
663 return pack(
"Cv", $this->ptg[
'ptgFuncV'], $this->_functions[$token][0]);
667 return pack(
"CCv", $this->ptg[
'ptgFuncVarV'], $num_args, $this->_functions[$token][0]);
682 if (preg_match(
"/^([A-Ia-i]?[A-Za-z])(\d+)\:([A-Ia-i]?[A-Za-z])(\d+)$/",$range)) {
683 list($cell1, $cell2) = split(
':', $range);
685 elseif (preg_match(
"/^([A-Ia-i]?[A-Za-z])(\d+)\.\.([A-Ia-i]?[A-Za-z])(\d+)$/",$range)) {
686 list($cell1, $cell2) = split(
'\.\.', $range);
699 list($row1, $col1) = $cell_array1;
704 list($row2, $col2) = $cell_array2;
708 $ptgArea = pack(
"C", $this->ptg[
'ptgArea']);
710 elseif ($class == 1) {
711 $ptgArea = pack(
"C", $this->ptg[
'ptgAreaV']);
713 elseif ($class == 2) {
714 $ptgArea = pack(
"C", $this->ptg[
'ptgAreaA']);
720 return $ptgArea . $row1 . $row2 . $col1. $col2;
736 list($ext_ref, $range) = split(
'!', $token);
739 if ($this->_BIFF_version == 0x0500) {
745 elseif ($this->_BIFF_version == 0x0600) {
753 list($cell1, $cell2) = split(
':', $range);
756 if (preg_match(
"/^(\$)?[A-Ia-i]?[A-Za-z](\$)?(\d+)$/", $cell1))
762 list($row1, $col1) = $cell_array1;
767 list($row2, $col2) = $cell_array2;
774 list($row1, $col1, $row2, $col2) = $cells_array;
779 $ptgArea = pack(
"C", $this->ptg[
'ptgArea3d']);
781 elseif ($class == 1) {
782 $ptgArea = pack(
"C", $this->ptg[
'ptgArea3dV']);
784 elseif ($class == 2) {
785 $ptgArea = pack(
"C", $this->ptg[
'ptgArea3dA']);
791 return $ptgArea . $ext_ref . $row1 . $row2 . $col1. $col2;
810 list(
$row, $col) = $cell_array;
814 $ptgRef = pack(
"C", $this->ptg[
'ptgRef']);
816 elseif ($class == 1) {
817 $ptgRef = pack(
"C", $this->ptg[
'ptgRefV']);
819 elseif ($class == 2) {
820 $ptgRef = pack(
"C", $this->ptg[
'ptgRefA']);
824 return $this->
raiseError(
"Unknown class $class");
826 return $ptgRef.$row.$col;
842 list($ext_ref, $cell) = split(
'!', $cell);
845 if ($this->_BIFF_version == 0x0500) {
851 elseif ($this->_BIFF_version == 0x0600) {
863 $ptgRef = pack(
"C", $this->ptg[
'ptgRef3d']);
865 elseif ($class == 1) {
866 $ptgRef = pack(
"C", $this->ptg[
'ptgRef3dV']);
868 elseif ($class == 2) {
869 $ptgRef = pack(
"C", $this->ptg[
'ptgRef3dA']);
875 return $ptgRef . $ext_ref.
$row . $col;
888 $ext_ref = preg_replace(
"/^'/",
'', $ext_ref);
889 $ext_ref = preg_replace(
"/'$/",
'', $ext_ref);
892 if (preg_match(
"/:/", $ext_ref))
894 list($sheet_name1, $sheet_name2) = split(
':', $ext_ref);
898 return $this->
raiseError(
"Unknown sheet name $sheet_name1 in formula");
902 return $this->
raiseError(
"Unknown sheet name $sheet_name2 in formula");
906 if ($sheet1 > $sheet2) {
907 list($sheet1, $sheet2) = array($sheet2, $sheet1);
914 return $this->
raiseError(
"Unknown sheet name $ext_ref in formula");
920 $offset = -1 - $sheet1;
922 return pack(
'vdvv', $offset, 0x00, $sheet1, $sheet2);
937 $ext_ref = preg_replace(
"/^'/",
'', $ext_ref);
938 $ext_ref = preg_replace(
"/'$/",
'', $ext_ref);
941 if (preg_match(
"/:/", $ext_ref))
943 list($sheet_name1, $sheet_name2) = split(
':', $ext_ref);
947 return $this->
raiseError(
"Unknown sheet name $sheet_name1 in formula");
951 return $this->
raiseError(
"Unknown sheet name $sheet_name2 in formula");
955 if ($sheet1 > $sheet2) {
956 list($sheet1, $sheet2) = array($sheet2, $sheet1);
963 return $this->
raiseError(
"Unknown sheet name $ext_ref in formula");
969 $supbook_index = 0x00;
970 $ref = pack(
'vvv', $supbook_index, $sheet1, $sheet2);
971 $total_references = count($this->_references);
973 for ($i = 0; $i < $total_references; $i++)
975 if ($ref == $this->_references[$i]) {
983 $this->_references[$total_references] = $ref;
984 $index = $total_references;
987 return pack(
'v', $index);
1000 if (!isset($this->_ext_sheets[$sheet_name])) {
1004 return $this->_ext_sheets[$sheet_name];
1020 $this->_ext_sheets[
$name] = $index;
1032 $cell = strtoupper($cell);
1035 return $this->
raiseError(
"Column in: $cell greater than 255");
1038 if (
$row >= 16384) {
1039 return $this->
raiseError(
"Row in: $cell greater than 16384 ");
1043 if ($this->_BIFF_version == 0x0500) {
1044 $row |= $col_rel << 14;
1045 $row |= $row_rel << 15;
1046 $col = pack(
'C', $col);
1048 elseif ($this->_BIFF_version == 0x0600) {
1049 $col |= $col_rel << 14;
1050 $col |= $row_rel << 15;
1051 $col = pack(
'v', $col);
1055 return array(
$row, $col);
1068 preg_match(
'/(\$)?(\d+)\:(\$)?(\d+)/', $range, $match);
1070 $row1_rel = empty($match[1]) ? 1 : 0;
1072 $row2_rel = empty($match[3]) ? 1 : 0;
1082 if (($row1 >= 16384) or ($row2 >= 16384)) {
1083 return $this->
raiseError(
"Row in: $range greater than 16384 ");
1087 if ($this->_BIFF_version == 0x0500) {
1088 $row1 |= $row1_rel << 14;
1089 $row2 |= $row2_rel << 15;
1090 $col1 = pack(
'C', $col1);
1091 $col2 = pack(
'C', $col2);
1093 elseif ($this->_BIFF_version == 0x0600) {
1094 $col1 |= $row1_rel << 15;
1095 $col2 |= $row2_rel << 15;
1096 $col1 = pack(
'v', $col1);
1097 $col2 = pack(
'v', $col2);
1099 $row1 = pack(
'v', $row1);
1100 $row2 = pack(
'v', $row2);
1102 return array($row1, $col1, $row2, $col2);
1116 preg_match(
'/(\$)?([A-I]?[A-Z])(\$)?(\d+)/',$cell,$match);
1118 $col_rel = empty($match[1]) ? 1 : 0;
1119 $col_ref = $match[2];
1120 $row_rel = empty($match[3]) ? 1 : 0;
1124 $expn = strlen($col_ref) - 1;
1126 for ($i=0; $i < strlen($col_ref); $i++)
1128 $col += (ord($col_ref{$i}) - ord(
'A') + 1) * pow(26, $expn);
1136 return array(
$row, $col, $row_rel, $col_rel);
1148 if ($i < strlen($this->_formula))
1150 while ($this->_formula{$i} ==
" ") {
1153 if ($i < strlen($this->_formula) - 1) {
1154 $this->_lookahead = $this->_formula{$i+1};
1158 while ($i < strlen($this->_formula))
1160 $token .= $this->_formula{$i};
1161 if ($i < strlen($this->_formula) - 1) {
1162 $this->_lookahead = $this->_formula{$i+1};
1165 $this->_lookahead =
'';
1167 if ($this->
_match($token) !=
'')
1172 $this->_current_char = $i + 1;
1173 $this->_current_token = $token;
1176 if ($i < strlen($this->_formula) - 2) {
1177 $this->_lookahead = $this->_formula{$i+2};
1181 $this->_lookahead =
'';
1224 if ($this->_lookahead ==
'=') {
1231 if (($this->_lookahead ==
'=') or ($this->_lookahead ==
'>')) {
1250 if (preg_match(
'/^\$?[A-Ia-i]?[A-Za-z]\$?[0-9]+$/',$token) and
1251 !ereg(
"[0-9]",$this->_lookahead) and
1252 ($this->_lookahead !=
':') and ($this->_lookahead !=
'.') and
1253 ($this->_lookahead !=
'!'))
1258 elseif (preg_match(
"/^\w+(\:\w+)?\![A-Ia-i]?[A-Za-z][0-9]+$/",$token) and
1259 !ereg(
"[0-9]",$this->_lookahead) and
1260 ($this->_lookahead !=
':') and ($this->_lookahead !=
'.'))
1265 elseif (preg_match(
"/^'\w+(\:\w+)?'\![A-Ia-i]?[A-Za-z][0-9]+$/",$token) and
1266 !ereg(
"[0-9]",$this->_lookahead) and
1267 ($this->_lookahead !=
':') and ($this->_lookahead !=
'.'))
1272 elseif (preg_match(
"/^(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+:(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+$/",$token) and
1273 !ereg(
"[0-9]",$this->_lookahead))
1278 elseif (preg_match(
"/^(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+\.\.(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+$/",$token) and
1279 !ereg(
"[0-9]",$this->_lookahead))
1284 elseif (preg_match(
"/^\w+(\:\w+)?\!([A-Ia-i]?[A-Za-z])?[0-9]+:([A-Ia-i]?[A-Za-z])?[0-9]+$/",$token) and
1285 !ereg(
"[0-9]",$this->_lookahead))
1290 elseif (preg_match(
"/^'\w+(\:\w+)?'\!([A-Ia-i]?[A-Za-z])?[0-9]+:([A-Ia-i]?[A-Za-z])?[0-9]+$/",$token) and
1291 !ereg(
"[0-9]",$this->_lookahead))
1296 elseif (is_numeric($token) and
1297 (!is_numeric($token.$this->_lookahead) or ($this->_lookahead ==
'')) and
1298 ($this->_lookahead !=
'!') and ($this->_lookahead !=
':'))
1303 elseif (ereg(
"^\"[^\"]{0,255}\"$",$token))
1308 elseif (eregi(
"^[A-Z0-9\xc0-\xdc\.]+$",$token) and ($this->_lookahead ==
"("))
1326 $this->_current_char = 0;
1327 $this->_formula = $formula;
1328 $this->_lookahead = $formula{1};
1357 $result = $this->
_createTree(
'ptgLT', $result, $result2);
1366 $result = $this->
_createTree(
'ptgGT', $result, $result2);
1375 $result = $this->
_createTree(
'ptgLE', $result, $result2);
1384 $result = $this->
_createTree(
'ptgGE', $result, $result2);
1393 $result = $this->
_createTree(
'ptgEQ', $result, $result2);
1402 $result = $this->
_createTree(
'ptgNE', $result, $result2);
1419 if (ereg(
"^\"[^\"]{0,255}\"$", $this->_current_token)) {
1420 $result = $this->
_createTree($this->_current_token,
'',
'');
1428 $result = $this->
_createTree(
'ptgUminus', $result2,
'');
1431 $result = $this->
_term();
1441 $result2 = $this->
_term();
1445 $result = $this->
_createTree(
'ptgAdd', $result, $result2);
1450 $result2 = $this->
_term();
1454 $result = $this->
_createTree(
'ptgSub', $result, $result2);
1483 $result = $this->
_fact();
1493 $result2 = $this->
_fact();
1497 $result = $this->
_createTree(
'ptgMul', $result, $result2);
1502 $result2 = $this->
_fact();
1506 $result = $this->
_createTree(
'ptgDiv', $result, $result2);
1530 return $this->
raiseError(
"')' token expected.");
1536 if (preg_match(
'/^\$?[A-Ia-i]?[A-Za-z]\$?[0-9]+$/',$this->_current_token))
1538 $result = $this->
_createTree($this->_current_token,
'',
'');
1543 elseif (preg_match(
"/^\w+(\:\w+)?\![A-Ia-i]?[A-Za-z][0-9]+$/",$this->_current_token))
1545 $result = $this->
_createTree($this->_current_token,
'',
'');
1550 elseif (preg_match(
"/^'\w+(\:\w+)?'\![A-Ia-i]?[A-Za-z][0-9]+$/",$this->_current_token))
1552 $result = $this->
_createTree($this->_current_token,
'',
'');
1557 elseif (preg_match(
"/^(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+:(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+$/",$this->_current_token) or
1558 preg_match(
"/^(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+\.\.(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+$/",$this->_current_token))
1565 elseif (preg_match(
"/^\w+(\:\w+)?\!([A-Ia-i]?[A-Za-z])?[0-9]+:([A-Ia-i]?[A-Za-z])?[0-9]+$/",$this->_current_token))
1572 elseif (preg_match(
"/^'\w+(\:\w+)?'\!([A-Ia-i]?[A-Za-z])?[0-9]+:([A-Ia-i]?[A-Za-z])?[0-9]+$/",$this->_current_token))
1578 elseif (is_numeric($this->_current_token))
1580 $result = $this->
_createTree($this->_current_token,
'',
'');
1585 elseif (eregi(
"^[A-Z0-9\xc0-\xdc\.]+$",$this->_current_token))
1587 $result = $this->
_func();
1590 return $this->
raiseError(
"Syntax error: ".$this->_current_token.
1591 ", lookahead: ".$this->_lookahead.
1592 ", current char: ".$this->_current_char);
1608 while ($this->_current_token !=
')')
1618 return $this->
raiseError(
"Syntax error: comma expected in ".
1619 "function $function, arg #{$num_args}");
1625 $result = $this->
_createTree(
'arg', $result, $result2);
1633 $result = $this->
_createTree(
'arg',
'', $result2);
1637 $args = $this->_functions[$function][1];
1639 if (($args >= 0) and ($args != $num_args)) {
1640 return $this->
raiseError(
"Incorrect number of arguments in function $function() ");
1643 $result = $this->
_createTree($function, $result, $num_args);
1660 return array(
'value' => $value,
'left' => $left,
'right' => $right);
1697 if (is_array($tree[
'left']))
1701 return $converted_tree;
1703 $polish .= $converted_tree;
1705 elseif ($tree[
'left'] !=
'')
1707 $converted_tree = $this->
_convert($tree[
'left']);
1709 return $converted_tree;
1711 $polish .= $converted_tree;
1713 if (is_array($tree[
'right']))
1717 return $converted_tree;
1719 $polish .= $converted_tree;
1721 elseif ($tree[
'right'] !=
'')
1723 $converted_tree = $this->
_convert($tree[
'right']);
1725 return $converted_tree;
1727 $polish .= $converted_tree;
1730 if (preg_match(
"/^[A-Z0-9\xc0-\xdc\.]+$/",$tree[
'value']) and
1731 !preg_match(
'/^([A-Ia-i]?[A-Za-z])(\d+)$/',$tree[
'value']) and
1732 !preg_match(
"/^[A-Ia-i]?[A-Za-z](\d+)\.\.[A-Ia-i]?[A-Za-z](\d+)$/",$tree[
'value']) and
1733 !is_numeric($tree[
'value']) and
1734 !isset($this->ptg[$tree[
'value']]))
1737 if ($tree[
'left'] !=
'') {
1747 return $left_tree.$this->_convertFunction($tree[
'value'], $tree[
'right']);
1751 $converted_tree = $this->
_convert($tree[
'value']);
1753 return $converted_tree;
1756 $polish .= $converted_tree;