35 require_once(
'classes/Spreadsheet/Excel/Writer/Parser.php');
36 require_once(
'classes/Spreadsheet/Excel/Writer/BIFFwriter.php');
365 &$firstsheet, &$str_total,
366 &$str_unique, &$str_table,
367 &$url_format, &$parser)
371 $this->_BIFF_version = $BIFF_version;
377 $this->activesheet = &$activesheet;
378 $this->firstsheet = &$firstsheet;
379 $this->_str_total = &$str_total;
380 $this->_str_unique = &$str_unique;
381 $this->_str_table = &$str_table;
382 $this->_url_format = &$url_format;
383 $this->_parser = &$parser;
386 $this->_filehandle =
"";
387 $this->_using_tmpfile =
true;
390 $this->_xls_rowmax = $rowmax;
391 $this->_xls_colmax = $colmax;
392 $this->_xls_strmax = 255;
393 $this->_dim_rowmin = $rowmax + 1;
394 $this->_dim_rowmax = 0;
395 $this->_dim_colmin = $colmax + 1;
396 $this->_dim_colmax = 0;
397 $this->_colinfo = array();
398 $this->_selection = array(0,0,0,0);
399 $this->_panes = array();
400 $this->_active_pane = 3;
404 $this->_paper_size = 0x0;
405 $this->_orientation = 0x1;
410 $this->_margin_head = 0.50;
411 $this->_margin_foot = 0.50;
412 $this->_margin_left = 0.75;
413 $this->_margin_right = 0.75;
414 $this->_margin_top = 1.00;
415 $this->_margin_bottom = 1.00;
417 $this->title_rowmin = NULL;
418 $this->title_rowmax = NULL;
419 $this->title_colmin = NULL;
420 $this->title_colmax = NULL;
421 $this->print_rowmin = NULL;
422 $this->print_rowmax = NULL;
423 $this->print_colmin = NULL;
424 $this->print_colmax = NULL;
426 $this->_print_gridlines = 1;
427 $this->_print_headers = 0;
429 $this->_fit_page = 0;
430 $this->_fit_width = 0;
431 $this->_fit_height = 0;
433 $this->_hbreaks = array();
434 $this->_vbreaks = array();
437 $this->_password = NULL;
439 $this->col_sizes = array();
440 $this->row_sizes = array();
443 $this->_print_scale = 100;
445 $this->_outline_row_level = 0;
446 $this->_outline_style = 0;
447 $this->_outline_below = 1;
448 $this->_outline_right = 1;
449 $this->_outline_on = 1;
451 $this->_merged_ranges = array();
453 $this->_dv = array();
467 if ($this->_using_tmpfile ==
false) {
471 $tmp_filename = @tempnam(
"",
"Worksheet_Data");
472 $fh = @fopen($tmp_filename,
"w+b");
475 $this->_filehandle = $fh;
479 $this->_using_tmpfile =
false;
494 $num_sheets = count($sheetnames);
550 if ($this->_BIFF_version == 0x0500) {
561 if ($this->_BIFF_version == 0x0500) {
562 for ($i = $num_sheets; $i > 0; $i--) {
563 $sheetname = $sheetnames[$i-1];
569 if ($this->_BIFF_version == 0x0500) {
574 if (!empty($this->_colinfo))
576 for ($i=0; $i < count($this->_colinfo); $i++) {
592 if (!empty($this->_panes)) {
627 if (isset($this->_data))
632 if ($this->_using_tmpfile) {
638 if ($this->_using_tmpfile)
640 if ($tmp = fread($this->_filehandle, $buffer)) {
658 function setMerge($first_row, $first_col, $last_row, $last_col)
660 if (($last_row < $first_row) or ($last_col < $first_col)) {
665 $this->_merged_ranges[] = array($first_row, $first_col, $last_row, $last_col);
729 function setColumn($firstcol, $lastcol, $width, $format = 0, $hidden = 0, $level = 0)
731 $this->_colinfo[] = array($firstcol, $lastcol, $width, &$format, $hidden, $level);
734 $width = ($hidden) ? 0 : $width;
736 for ($col = $firstcol; $col <= $lastcol; $col++) {
737 $this->col_sizes[$col] = $width;
752 $this->_selection = array($first_row,$first_column,$last_row,$last_column);
769 $this->_panes = $panes;
786 $this->_panes = $panes;
796 $this->_orientation = 1;
806 $this->_orientation = 0;
817 $this->_paper_size = $size;
830 if (strlen($string) >= 255) {
834 $this->_header = $string;
835 $this->_margin_head = $margin;
847 if (strlen($string) >= 255) {
851 $this->_footer = $string;
852 $this->_margin_foot = $margin;
863 $this->_hcenter = $center;
874 $this->_vcenter = $center;
923 $this->_margin_left = $margin;
934 $this->_margin_right = $margin;
945 $this->_margin_top = $margin;
956 $this->_margin_bottom = $margin;
968 $this->title_rowmin = $first_row;
969 if (isset($last_row)) {
970 $this->title_rowmax = $last_row;
973 $this->title_rowmax = $first_row;
986 $this->title_colmin = $first_col;
987 if (isset($last_col)) {
988 $this->title_colmax = $last_col;
991 $this->title_colmax = $first_col;
1004 function printArea($first_row, $first_col, $last_row, $last_col)
1006 $this->print_rowmin = $first_row;
1007 $this->print_colmin = $first_col;
1008 $this->print_rowmax = $last_row;
1009 $this->print_colmax = $last_col;
1020 $this->_print_gridlines = 0;
1031 $this->_print_headers = $print;
1045 $this->_fit_page = 1;
1046 $this->_fit_width = $width;
1047 $this->_fit_height = $height;
1059 foreach($breaks as $break) {
1060 array_push($this->_hbreaks,$break);
1073 foreach($breaks as $break) {
1074 array_push($this->_vbreaks,$break);
1088 if ($scale < 10 or $scale > 400)
1090 $this->
raiseError(
"Zoom factor $scale outside range: 10 <= zoom <= 400");
1094 $this->_zoom = floor($scale);
1107 if ($scale < 10 or $scale > 400)
1109 $this->
raiseError(
"Print scale $scale outside range: 10 <= zoom <= 400");
1114 $this->_fit_page = 0;
1116 $this->_print_scale = floor($scale);
1137 if (preg_match(
"/^([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/",$token)) {
1141 elseif (preg_match(
"/^[fh]tt?p:\/\//",$token)) {
1142 return $this->
writeUrl(
$row, $col, $token,
'', $format);
1145 elseif (preg_match(
"/^mailto:/",$token)) {
1146 return $this->
writeUrl(
$row, $col, $token,
'', $format);
1149 elseif (preg_match(
"/^(?:in|ex)ternal:/",$token)) {
1150 return $this->
writeUrl(
$row, $col, $token,
'', $format);
1153 elseif (preg_match(
"/^=/",$token)) {
1157 elseif (preg_match(
"/^@/",$token)) {
1161 elseif ($token ==
'') {
1184 if (is_array($val)) {
1185 foreach($val as $v) {
1194 $retval =
new PEAR_Error(
'$val needs to be an array');
1213 if (is_array($val)) {
1214 foreach($val as $v) {
1219 $retval =
new PEAR_Error(
'$val needs to be an array');
1234 return($format->getXfIndex());
1258 if ($this->_using_tmpfile)
1261 if (strlen(
$data) > $this->_limit) {
1264 fwrite($this->_filehandle,
$data);
1265 $this->_datasize += strlen(
$data);
1284 $cell = strtoupper($cell);
1287 if (preg_match(
"/([A-I]?[A-Z]):([A-I]?[A-Z])/",$cell,$match)) {
1288 list($no_use, $col1) = $this->
_cellToRowcol($match[1] .
'1');
1289 list($no_use, $col2) = $this->
_cellToRowcol($match[2] .
'1');
1290 return(array($col1, $col2));
1294 if (preg_match(
"/\$?([A-I]?[A-Z]\$?\d+):\$?([A-I]?[A-Z]\$?\d+)/",$cell,$match)) {
1297 return(array($row1, $col1, $row2, $col2));
1301 if (preg_match(
"/\$?([A-I]?[A-Z]\$?\d+)/",$cell)) {
1303 return(array($row1, $col1));
1320 preg_match(
"/\$?([A-I]?[A-Z])\$?(\d+)/",$cell,$match);
1325 $chars = split(
'', $col);
1330 $char = array_pop($chars);
1331 $col += (ord($char) -ord(
'A') +1) * pow(26,$expn);
1339 return(array(
$row, $col));
1355 $chars = preg_split(
'//', $plaintext, -1, PREG_SPLIT_NO_EMPTY);
1356 foreach($chars as $char)
1358 $value = ord($char) << $i;
1359 $rotated_bits = $value >> 15;
1361 $password ^= ($value | $rotated_bits);
1365 $password ^= strlen($plaintext);
1366 $password ^= 0xCE4B;
1380 function setOutline($visible =
true, $symbols_below =
true, $symbols_right =
true, $auto_style =
false)
1382 $this->_outline_on = $visible;
1383 $this->_outline_below = $symbols_below;
1384 $this->_outline_right = $symbols_right;
1385 $this->_outline_style = $auto_style;
1388 if ($this->_outline_on) {
1389 $this->_outline_on = 1;
1420 $xf = $this->
_XF($format);
1423 if (
$row >= $this->_xls_rowmax)
1427 if ($col >= $this->_xls_colmax)
1431 if ($row < $this->_dim_rowmin)
1433 $this->_dim_rowmin =
$row;
1435 if (
$row > $this->_dim_rowmax)
1437 $this->_dim_rowmax =
$row;
1439 if ($col < $this->_dim_colmin)
1441 $this->_dim_colmin = $col;
1443 if ($col > $this->_dim_colmax)
1445 $this->_dim_colmax = $col;
1450 $xl_double = pack(
"d", $num);
1451 if ($this->_byte_order)
1453 $xl_double = strrev($xl_double);
1477 if ($this->_BIFF_version == 0x0600) {
1480 $strlen = strlen($str);
1483 $xf = $this->
_XF($format);
1488 if (
$row >= $this->_xls_rowmax)
1492 if ($col >= $this->_xls_colmax)
1496 if ($row < $this->_dim_rowmin)
1498 $this->_dim_rowmin =
$row;
1500 if (
$row > $this->_dim_rowmax)
1502 $this->_dim_rowmax =
$row;
1504 if ($col < $this->_dim_colmin)
1506 $this->_dim_colmin = $col;
1508 if ($col > $this->_dim_colmax)
1510 $this->_dim_colmax = $col;
1513 if ($strlen > $this->_xls_strmax)
1515 $str = substr($str, 0, $this->_xls_strmax);
1522 $data = pack(
"vvvv",
$row, $col, $xf, $strlen);
1529 $strlen = strlen($str);
1532 $xf = $this->
_XF($format);
1542 $str = pack(
'vC', $strlen, $encoding).$str;
1545 if (!isset($this->_str_table[$str])) {
1546 $this->_str_table[$str] = $this->_str_unique++;
1548 $this->_str_total++;
1551 $data = pack(
'vvvV',
$row, $col, $xf, $this->_str_table[$str]);
1568 if (
$row >= $this->_xls_rowmax) {
1571 if ($col >= $this->_xls_colmax) {
1574 if ($row < $this->_dim_rowmin) {
1575 $this->_dim_rowmin =
$row;
1577 if (
$row > $this->_dim_rowmax) {
1578 $this->_dim_rowmax =
$row;
1580 if ($col < $this->_dim_colmin) {
1581 $this->_dim_colmin = $col;
1583 if ($col > $this->_dim_colmax) {
1584 $this->_dim_colmax = $col;
1600 $note_length = strlen($note);
1606 if (
$row >= $this->_xls_rowmax)
1610 if ($col >= $this->_xls_colmax)
1614 if ($row < $this->_dim_rowmin)
1616 $this->_dim_rowmin =
$row;
1618 if (
$row > $this->_dim_rowmax)
1620 $this->_dim_rowmax =
$row;
1622 if ($col < $this->_dim_colmin)
1624 $this->_dim_colmin = $col;
1626 if ($col > $this->_dim_colmax)
1628 $this->_dim_colmax = $col;
1632 $length = 0x0006 + min($note_length, 2048);
1634 $data = pack(
"vvv",
$row, $col, $note_length);
1637 for($i = $max_length; $i < $note_length; $i += $max_length)
1639 $chunk = substr($note, $i, $max_length);
1640 $length = 0x0006 + strlen($chunk);
1642 $data = pack(
"vvv", -1, 0, strlen($chunk));
1675 $xf = $this->
_XF($format);
1678 if (
$row >= $this->_xls_rowmax)
1682 if ($col >= $this->_xls_colmax)
1686 if ($row < $this->_dim_rowmin)
1688 $this->_dim_rowmin =
$row;
1690 if (
$row > $this->_dim_rowmax)
1692 $this->_dim_rowmax =
$row;
1694 if ($col < $this->_dim_colmin)
1696 $this->_dim_colmin = $col;
1698 if ($col > $this->_dim_colmax)
1700 $this->_dim_colmax = $col;
1734 $xf = $this->
_XF($format);
1746 if (preg_match(
"/^=/",$formula)) {
1747 $formula = preg_replace(
"/(^=)/",
"",$formula);
1749 elseif (preg_match(
"/^@/",$formula)) {
1750 $formula = preg_replace(
"/(^@)/",
"",$formula);
1760 $error = $this->_parser->parse($formula);
1767 $formula = $this->_parser->toReversePolish();
1774 $formlen = strlen($formula);
1778 $data = pack(
"vvvdvVv",
$row, $col, $xf, $num,
1779 $grbit, $unknown, $formlen);
1836 if (preg_match(
'[^internal:]',
$url)) {
1839 if (preg_match(
'[^external:]',
$url)) {
1842 return($this->
_writeUrlWeb($row1, $col1, $row2, $col2,
$url, $string, $format));
1881 $unknown1 = pack(
"H*",
"D0C9EA79F9BACE118C8200AA004BA90B02000000");
1882 $unknown2 = pack(
"H*",
"E0C9EA79F9BACE118C8200AA004BA90B");
1885 $options = pack(
"V", 0x03);
1888 $url = join(
"\0", preg_split(
"''",
$url, -1, PREG_SPLIT_NO_EMPTY));
1892 $url_len = pack(
"V", strlen(
$url));
1899 $data = pack(
"vvvv", $row1, $row2, $col1, $col2);
1932 $url = preg_replace(
's[^internal:]',
'',
$url);
1944 $unknown1 = pack(
"H*",
"D0C9EA79F9BACE118C8200AA004BA90B02000000");
1947 $options = pack(
"V", 0x08);
1950 $url = join(
"\0", preg_split(
"''",
$url, -1, PREG_SPLIT_NO_EMPTY));
1954 $url_len = pack(
"V", floor(strlen(
$url)/2));
1961 $data = pack(
"vvvv", $row1, $row2, $col1, $col2);
2010 $str = preg_replace(
'[\#]',
' - ',
$url);
2023 if (!preg_match(
'[\\]',
$url)) {
2026 if (preg_match(
'[^\.\.\\]',
$url)) {
2036 if (isset($sheet)) {
2038 $sheet_len = pack(
"V", strlen($sheet) + 0x01);
2039 $sheet = join(
"\0", split(
'', $sheet));
2067 $unknown1 = pack(
"H*",
'D0C9EA79F9BACE118C8200AA004BA90B02000000' );
2069 $unknown3 = pack(
"H*",
'FFFFADDE000000000000000000000000000000000000000');
2073 $data = pack(
"vvvv", $row1, $row2, $col1, $col2) .
2109 function setRow(
$row, $height, $format = 0, $hidden =
false, $level = 0)
2119 $ixfe = $this->_XF($format);
2122 if ($height != NULL) {
2123 $miyRw = $height * 20;
2129 $level = max(0, min($level, 7));
2130 $this->_outline_row_level = max($level, $this->_outline_row_level);
2149 $header = pack(
"vv", $record, $length);
2150 $data = pack(
"vvvvvvvv",
$row, $colMic, $colMac, $miyRw,
2151 $irwMac,$reserved, $grbit, $ixfe);
2152 $this->_append($header.$data);
2160 function _storeDimensions()
2163 $row_min = $this->_dim_rowmin;
2164 $row_max = $this->_dim_rowmax + 1;
2165 $col_min = $this->_dim_colmin;
2166 $col_max = $this->_dim_colmax + 1;
2169 if ($this->_BIFF_version == 0x0500) {
2171 $data = pack(
"vvvvv", $row_min, $row_max,
2172 $col_min, $col_max, $reserved);
2174 elseif ($this->_BIFF_version == 0x0600) {
2176 $data = pack(
"VVvvv", $row_min, $row_max,
2177 $col_min, $col_max, $reserved);
2179 $header = pack(
"vv", $record, $length);
2180 $this->_prepend($header.$data);
2188 function _storeWindow2()
2191 if ($this->_BIFF_version == 0x0500) {
2194 elseif ($this->_BIFF_version == 0x0600) {
2207 $fFrozen = $this->_frozen;
2211 $fDspGuts = $this->_outline_on;
2212 $fFrozenNoSplit = 0;
2213 $fSelected = $this->selected;
2217 $grbit |= $fDspGrid << 1;
2218 $grbit |= $fDspRwCol << 2;
2219 $grbit |= $fFrozen << 3;
2220 $grbit |= $fDspZeros << 4;
2221 $grbit |= $fDefaultHdr << 5;
2222 $grbit |= $fArabic << 6;
2223 $grbit |= $fDspGuts << 7;
2224 $grbit |= $fFrozenNoSplit << 8;
2225 $grbit |= $fSelected << 9;
2226 $grbit |= $fPaged << 10;
2228 $header = pack(
"vv", $record, $length);
2229 $data = pack(
"vvv", $grbit, $rwTop, $colLeft);
2231 if ($this->_BIFF_version == 0x0500) {
2232 $rgbHdr = 0x00000000;
2233 $data .= pack(
"V", $rgbHdr);
2235 elseif ($this->_BIFF_version == 0x0600) {
2237 $zoom_factor_page_break = 0x0000;
2238 $zoom_factor_normal = 0x0000;
2239 $data .= pack(
"vvvvV", $rgbHdr, 0x0000, $zoom_factor_page_break, $zoom_factor_normal, 0x00000000);
2241 $this->_append($header.$data);
2249 function _storeDefcol()
2255 $header = pack(
"vv", $record, $length);
2256 $data = pack(
"v", $colwidth);
2257 $this->_prepend($header.$data);
2275 function _storeColinfo($col_array)
2277 if (isset($col_array[0])) {
2278 $colFirst = $col_array[0];
2280 if (isset($col_array[1])) {
2281 $colLast = $col_array[1];
2283 if (isset($col_array[2])) {
2284 $coldx = $col_array[2];
2289 if (isset($col_array[3])) {
2290 $format = $col_array[3];
2295 if (isset($col_array[4])) {
2296 $grbit = $col_array[4];
2301 if (isset($col_array[5])) {
2302 $level = $col_array[5];
2313 $ixfe = $this->_XF($format);
2316 $level = max(0, min($level, 7));
2317 $grbit |= $level << 8;
2319 $header = pack(
"vv", $record, $length);
2320 $data = pack(
"vvvvvC", $colFirst, $colLast, $coldx,
2321 $ixfe, $grbit, $reserved);
2322 $this->_prepend($header.$data);
2332 function _storeSelection($array)
2334 list($rwFirst,$colFirst,$rwLast,$colLast) = $array;
2338 $pnn = $this->_active_pane;
2340 $colAct = $colFirst;
2344 if (!isset($rwLast)) {
2347 if (!isset($colLast)) {
2348 $colLast = $colFirst;
2352 if ($rwFirst > $rwLast)
2354 list($rwFirst, $rwLast) = array($rwLast, $rwFirst);
2357 if ($colFirst > $colLast)
2359 list($colFirst, $colLast) = array($colLast, $colFirst);
2362 $header = pack(
"vv", $record, $length);
2363 $data = pack(
"CvvvvvvCC", $pnn, $rwAct, $colAct,
2366 $colFirst, $colLast);
2367 $this->_append($header.$data);
2375 function _storeMergedCells()
2378 if (count($this->_merged_ranges) == 0) {
2382 $length = 2 + count($this->_merged_ranges) * 8;
2384 $header = pack(
'vv', $record, $length);
2385 $data = pack(
'v', count($this->_merged_ranges));
2386 foreach ($this->_merged_ranges as $range) {
2387 $data .= pack(
'vvvv', $range[0], $range[2], $range[1], $range[3]);
2389 $this->_append($header.$data);
2405 function _storeExterncount($count)
2410 $header = pack(
"vv", $record, $length);
2411 $data = pack(
"v", $count);
2412 $this->_prepend($header.$data);
2424 function _storeExternsheet($sheetname)
2431 if ($this->name == $sheetname) {
2438 $length = 0x02 + strlen($sheetname);
2439 $cch = strlen($sheetname);
2443 $header = pack(
"vv", $record, $length);
2444 $data = pack(
"CC", $cch, $rgch);
2445 $this->_prepend($header.$data.$sheetname);
2462 function _storePanes($panes)
2467 $colLeft = $panes[3];
2468 if (count($panes) > 4) {
2469 $pnnAct = $panes[4];
2481 if (!isset($rwTop)) {
2484 if (!isset($colLeft)) {
2491 if (!isset($rwTop)) {
2494 if (!isset($colLeft)) {
2504 $x = 113.879*
$x + 390;
2511 if (!isset($pnnAct))
2513 if (
$x != 0 and
$y != 0)
2515 if (
$x != 0 and
$y == 0)
2517 if (
$x == 0 and
$y != 0)
2519 if (
$x == 0 and
$y == 0)
2523 $this->_active_pane = $pnnAct;
2525 $header = pack(
"vv", $record, $length);
2526 $data = pack(
"vvvvv",
$x,
$y, $rwTop, $colLeft, $pnnAct);
2527 $this->_append($header.$data);
2535 function _storeSetup()
2540 $iPaperSize = $this->_paper_size;
2541 $iScale = $this->_print_scale;
2543 $iFitWidth = $this->_fit_width;
2544 $iFitHeight = $this->_fit_height;
2548 $numHdr = $this->_margin_head;
2549 $numFtr = $this->_margin_foot;
2552 $fLeftToRight = 0x0;
2553 $fLandscape = $this->_orientation;
2561 $grbit = $fLeftToRight;
2562 $grbit |= $fLandscape << 1;
2563 $grbit |= $fNoPls << 2;
2564 $grbit |= $fNoColor << 3;
2565 $grbit |= $fDraft << 4;
2566 $grbit |= $fNotes << 5;
2567 $grbit |= $fNoOrient << 6;
2568 $grbit |= $fUsePage << 7;
2570 $numHdr = pack(
"d", $numHdr);
2571 $numFtr = pack(
"d", $numFtr);
2572 if ($this->_byte_order)
2574 $numHdr = strrev($numHdr);
2575 $numFtr = strrev($numFtr);
2578 $header = pack(
"vv", $record, $length);
2579 $data1 = pack(
"vvvvvvvv", $iPaperSize,
2587 $data2 = $numHdr.$numFtr;
2588 $data3 = pack(
"v", $iCopies);
2589 $this->_prepend($header.$data1.$data2.$data3);
2597 function _storeHeader()
2601 $str = $this->_header;
2602 $cch = strlen($str);
2603 if ($this->_BIFF_version == 0x0600) {
2610 $header = pack(
"vv", $record, $length);
2611 if ($this->_BIFF_version == 0x0600) {
2612 $data = pack(
"vC", $cch, $encoding);
2615 $data = pack(
"C", $cch);
2618 $this->_append($header.$data.$str);
2626 function _storeFooter()
2630 $str = $this->_footer;
2631 $cch = strlen($str);
2632 if ($this->_BIFF_version == 0x0600) {
2639 $header = pack(
"vv", $record, $length);
2640 if ($this->_BIFF_version == 0x0600) {
2641 $data = pack(
"vC", $cch, $encoding);
2644 $data = pack(
"C", $cch);
2647 $this->_append($header.$data.$str);
2655 function _storeHcenter()
2660 $fHCenter = $this->_hcenter;
2662 $header = pack(
"vv", $record, $length);
2663 $data = pack(
"v", $fHCenter);
2665 $this->_append($header.$data);
2673 function _storeVcenter()
2678 $fVCenter = $this->_vcenter;
2680 $header = pack(
"vv", $record, $length);
2681 $data = pack(
"v", $fVCenter);
2682 $this->_append($header.$data);
2690 function _storeMarginLeft()
2695 $margin = $this->_margin_left;
2697 $header = pack(
"vv", $record, $length);
2698 $data = pack(
"d", $margin);
2699 if ($this->_byte_order)
2704 $this->_append($header.$data);
2712 function _storeMarginRight()
2717 $margin = $this->_margin_right;
2719 $header = pack(
"vv", $record, $length);
2720 $data = pack(
"d", $margin);
2721 if ($this->_byte_order)
2726 $this->_append($header.$data);
2734 function _storeMarginTop()
2739 $margin = $this->_margin_top;
2741 $header = pack(
"vv", $record, $length);
2742 $data = pack(
"d", $margin);
2743 if ($this->_byte_order)
2748 $this->_append($header.$data);
2756 function _storeMarginBottom()
2761 $margin = $this->_margin_bottom;
2763 $header = pack(
"vv", $record, $length);
2764 $data = pack(
"d", $margin);
2765 if ($this->_byte_order)
2770 $this->_append($header.$data);
2784 function mergeCells($first_row, $first_col, $last_row, $last_col)
2791 if ($first_row > $last_row) {
2792 list($first_row, $last_row) = array($last_row, $first_row);
2795 if ($first_col > $last_col) {
2796 list($first_col, $last_col) = array($last_col, $first_col);
2799 $header = pack(
"vv", $record, $length);
2800 $data = pack(
"vvvvv", $cref, $first_row, $last_row,
2801 $first_col, $last_col);
2803 $this->_append($header.$data);
2811 function _storePrintHeaders()
2816 $fPrintRwCol = $this->_print_headers;
2818 $header = pack(
"vv", $record, $length);
2819 $data = pack(
"v", $fPrintRwCol);
2820 $this->_prepend($header.$data);
2829 function _storePrintGridlines()
2834 $fPrintGrid = $this->_print_gridlines;
2836 $header = pack(
"vv", $record, $length);
2837 $data = pack(
"v", $fPrintGrid);
2838 $this->_prepend($header.$data);
2847 function _storeGridset()
2852 $fGridSet = !($this->_print_gridlines);
2854 $header = pack(
"vv", $record, $length);
2855 $data = pack(
"v", $fGridSet);
2856 $this->_prepend($header.$data);
2867 function _storeGuts()
2875 $row_level = $this->_outline_row_level;
2880 for ($i=0; $i < count($this->_colinfo); $i++)
2883 if (count($col_level) >= 6) {
2884 $col_level = max($this->_colinfo[$i][5], $col_level);
2889 $col_level = max(0, min($col_level, 7));
2899 $header = pack(
"vv", $record, $length);
2900 $data = pack(
"vvvv", $dxRwGut, $dxColGut, $row_level, $col_level);
2902 $this->_prepend($header.$data);
2912 function _storeWsbool()
2929 if ($this->_outline_style) {
2932 if ($this->_outline_below) {
2935 if ($this->_outline_right) {
2938 if ($this->_fit_page) {
2941 if ($this->_outline_on) {
2945 $header = pack(
"vv", $record, $length);
2946 $data = pack(
"v", $grbit);
2947 $this->_prepend($header.$data);
2955 function _storeHbreak()
2958 if (empty($this->_hbreaks)) {
2963 $breaks = $this->_hbreaks;
2964 sort($breaks, SORT_NUMERIC);
2965 if ($breaks[0] == 0) {
2966 array_shift($breaks);
2970 $cbrk = count($breaks);
2971 $length = 2 + 6*$cbrk;
2973 $header = pack(
"vv", $record, $length);
2974 $data = pack(
"v", $cbrk);
2977 foreach($breaks as $break) {
2978 $data .= pack(
"vvv", $break, 0x0000, 0x00ff);
2981 $this->_prepend($header.$data);
2990 function _storeVbreak()
2993 if (empty($this->_vbreaks)) {
2999 $breaks = array_slice($this->_vbreaks,0,1000);
3002 sort($breaks, SORT_NUMERIC);
3003 if ($breaks[0] == 0) {
3004 array_shift($breaks);
3008 $cbrk = count($breaks);
3009 $length = 2 + 6*$cbrk;
3011 $header = pack(
"vv", $record, $length);
3012 $data = pack(
"v", $cbrk);
3015 foreach ($breaks as $break) {
3016 $data .= pack(
"vvv", $break, 0x0000, 0xffff);
3019 $this->_prepend($header.$data);
3027 function _storeProtect()
3030 if ($this->_protect == 0) {
3037 $fLock = $this->_protect;
3039 $header = pack(
"vv", $record, $length);
3040 $data = pack(
"v", $fLock);
3042 $this->_prepend($header.$data);
3050 function _storePassword()
3053 if (($this->_protect == 0) or (!isset($this->_password))) {
3060 $wPassword = $this->_password;
3062 $header = pack(
"vv", $record, $length);
3063 $data = pack(
"v", $wPassword);
3065 $this->_prepend($header.$data);
3081 function insertBitmap(
$row, $col, $bitmap,
$x = 0,
$y = 0, $scale_x = 1, $scale_y = 1)
3083 $bitmap_array = $this->_processBitmap($bitmap);
3084 if ($this->isError($bitmap_array))
3086 $this->writeString(
$row, $col, $bitmap_array->getMessage());
3089 list($width, $height, $size,
$data) = $bitmap_array;
3093 $height *= $scale_y;
3096 $this->_positionImage($col,
$row,
$x,
$y, $width, $height);
3100 $length = 8 + $size;
3105 $header = pack(
"vvvvV", $record, $length, $cf, $env, $lcb);
3106 $this->_append($header.$data);
3160 function _positionImage($col_start, $row_start, $x1, $y1, $width, $height)
3163 $col_end = $col_start;
3164 $row_end = $row_start;
3167 if ($x1 >= $this->_sizeCol($col_start))
3171 if ($y1 >= $this->_sizeRow($row_start))
3176 $width = $width + $x1 -1;
3177 $height = $height + $y1 -1;
3180 while ($width >= $this->_sizeCol($col_end)) {
3181 $width -= $this->_sizeCol($col_end);
3186 while ($height >= $this->_sizeRow($row_end)) {
3187 $height -= $this->_sizeRow($row_end);
3194 if ($this->_sizeCol($col_start) == 0)
3196 if ($this->_sizeCol($col_end) == 0)
3198 if ($this->_sizeRow($row_start) == 0)
3200 if ($this->_sizeRow($row_end) == 0)
3204 $x1 = $x1 / $this->_sizeCol($col_start) * 1024;
3205 $y1 = $y1 / $this->_sizeRow($row_start) * 256;
3206 $x2 = $width / $this->_sizeCol($col_end) * 1024;
3207 $y2 = $height / $this->_sizeRow($row_end) * 256;
3209 $this->_storeObjPicture( $col_start, $x1,
3225 function _sizeCol($col)
3228 if (isset($this->col_sizes[$col])) {
3229 if ($this->col_sizes[$col] == 0) {
3233 return(floor(7 * $this->col_sizes[$col] + 5));
3254 if (isset($this->row_sizes[
$row])) {
3255 if ($this->row_sizes[$row] == 0) {
3259 return(floor(4/3 * $this->row_sizes[$row]));
3281 function _storeObjPicture($colL,$dxL,$rwT,$dyT,$colR,$dxR,$rwB,$dyB)
3292 $Reserved1 = 0x0000;
3293 $Reserved2 = 0x0000;
3305 $Reserved3 = 0x0000;
3306 $cbPictFmla = 0x0000;
3307 $Reserved4 = 0x0000;
3309 $Reserved5 = 0x0000;
3312 $header = pack(
"vv", $record, $length);
3313 $data = pack(
"V", $cObj);
3314 $data .= pack(
"v", $OT);
3315 $data .= pack(
"v", $id);
3316 $data .= pack(
"v", $grbit);
3317 $data .= pack(
"v", $colL);
3318 $data .= pack(
"v", $dxL);
3319 $data .= pack(
"v", $rwT);
3320 $data .= pack(
"v", $dyT);
3321 $data .= pack(
"v", $colR);
3322 $data .= pack(
"v", $dxR);
3323 $data .= pack(
"v", $rwB);
3324 $data .= pack(
"v", $dyB);
3325 $data .= pack(
"v", $cbMacro);
3326 $data .= pack(
"V", $Reserved1);
3327 $data .= pack(
"v", $Reserved2);
3328 $data .= pack(
"C", $icvBack);
3329 $data .= pack(
"C", $icvFore);
3330 $data .= pack(
"C", $fls);
3331 $data .= pack(
"C", $fAuto);
3332 $data .= pack(
"C", $icv);
3333 $data .= pack(
"C", $lns);
3334 $data .= pack(
"C", $lnw);
3335 $data .= pack(
"C", $fAutoB);
3336 $data .= pack(
"v", $frs);
3337 $data .= pack(
"V", $cf);
3338 $data .= pack(
"v", $Reserved3);
3339 $data .= pack(
"v", $cbPictFmla);
3340 $data .= pack(
"v", $Reserved4);
3341 $data .= pack(
"v", $grbit2);
3342 $data .= pack(
"V", $Reserved5);
3344 $this->_append($header.$data);
3356 function _processBitmap($bitmap)
3359 $bmp_fd = @fopen($bitmap,
"rb");
3361 $this->raiseError(
"Couldn't import $bitmap");
3365 $data = fread($bmp_fd, filesize($bitmap));
3368 if (strlen(
$data) <= 0x36) {
3369 $this->raiseError(
"$bitmap doesn't contain enough data.\n");
3373 $identity = unpack(
"A2",
$data);
3374 if ($identity[
''] !=
"BM") {
3375 $this->raiseError(
"$bitmap doesn't appear to be a valid bitmap image.\n");
3384 $size_array = unpack(
"V", substr(
$data, 0, 4));
3385 $size = $size_array[
''];
3394 $width_and_height = unpack(
"V2", substr(
$data, 0, 8));
3395 $width = $width_and_height[1];
3396 $height = $width_and_height[2];
3398 if ($width > 0xFFFF) {
3399 $this->raiseError(
"$bitmap: largest image width supported is 65k.\n");
3401 if ($height > 0xFFFF) {
3402 $this->raiseError(
"$bitmap: largest image height supported is 65k.\n");
3406 $planes_and_bitcount = unpack(
"v2", substr(
$data, 0, 4));
3408 if ($planes_and_bitcount[2] != 24) {
3409 $this->raiseError(
"$bitmap isn't a 24bit true color bitmap.\n");
3411 if ($planes_and_bitcount[1] != 1) {
3412 $this->raiseError(
"$bitmap: only 1 plane nupported in bitmap image.\n");
3416 $compression = unpack(
"V", substr(
$data, 0, 4));
3420 if ($compression[
""] != 0) {
3421 $this->raiseError(
"$bitmap: compression not supported in bitmap image.\n");
3428 $header = pack(
"Vvvvv", 0x000c, $width, $height, 0x01, 0x18);
3431 return (array($width, $height, $size,
$data));
3440 function _storeZoom()
3443 if ($this->_zoom == 100) {
3450 $header = pack(
"vv", $record, $length);
3451 $data = pack(
"vv", $this->_zoom, 100);
3452 $this->_append($header.$data);
3458 function setValidation($row1, $col1, $row2, $col2, &$validator)
3460 $this->_dv[] = $validator->_getData() .
3461 pack(
"vvvvv", 1, $row1, $row2, $col1, $col2);
3469 function _storeDataValidity()
3475 $horPos = 0x00000000;
3476 $verPos = 0x00000000;
3477 $objId = 0xffffffff;
3479 $header = pack(
'vv', $record, $length);
3480 $data = pack(
'vVVVV', $grbit, $horPos, $verPos, $objId,
3482 $this->_append($header.$data);
3485 foreach($this->_dv as $dv)
3487 $length = strlen($dv);
3488 $header = pack(
"vv", $record, $length);
3489 $this->_append($header.$dv);