35 require_once
'Spreadsheet/Excel/Writer/Parser.php';
36 require_once
'Spreadsheet/Excel/Writer/BIFFwriter.php';
372 &$firstsheet, &$str_total,
373 &$str_unique, &$str_table,
374 &$url_format, &$parser,
379 $this->_BIFF_version = $BIFF_version;
385 $this->activesheet = &$activesheet;
386 $this->firstsheet = &$firstsheet;
387 $this->_str_total = &$str_total;
388 $this->_str_unique = &$str_unique;
389 $this->_str_table = &$str_table;
390 $this->_url_format = &$url_format;
391 $this->_parser = &$parser;
394 $this->_filehandle =
'';
395 $this->_using_tmpfile =
true;
398 $this->_xls_rowmax = $rowmax;
399 $this->_xls_colmax = $colmax;
400 $this->_xls_strmax = 255;
401 $this->_dim_rowmin = $rowmax + 1;
402 $this->_dim_rowmax = 0;
403 $this->_dim_colmin = $colmax + 1;
404 $this->_dim_colmax = 0;
405 $this->_colinfo = array();
406 $this->_selection = array(0,0,0,0);
407 $this->_panes = array();
408 $this->_active_pane = 3;
412 $this->_paper_size = 0x0;
413 $this->_orientation = 0x1;
418 $this->_margin_head = 0.50;
419 $this->_margin_foot = 0.50;
420 $this->_margin_left = 0.75;
421 $this->_margin_right = 0.75;
422 $this->_margin_top = 1.00;
423 $this->_margin_bottom = 1.00;
425 $this->title_rowmin = null;
426 $this->title_rowmax = null;
427 $this->title_colmin = null;
428 $this->title_colmax = null;
429 $this->print_rowmin = null;
430 $this->print_rowmax = null;
431 $this->print_colmin = null;
432 $this->print_colmax = null;
434 $this->_print_gridlines = 1;
435 $this->_screen_gridlines = 1;
436 $this->_print_headers = 0;
438 $this->_fit_page = 0;
439 $this->_fit_width = 0;
440 $this->_fit_height = 0;
442 $this->_hbreaks = array();
443 $this->_vbreaks = array();
446 $this->_password = null;
448 $this->col_sizes = array();
449 $this->_row_sizes = array();
452 $this->_print_scale = 100;
454 $this->_outline_row_level = 0;
455 $this->_outline_style = 0;
456 $this->_outline_below = 1;
457 $this->_outline_right = 1;
458 $this->_outline_on = 1;
460 $this->_merged_ranges = array();
462 $this->_input_encoding =
'';
464 $this->_dv = array();
466 $this->_tmp_dir = $tmp_dir;
480 if ($this->_using_tmpfile ==
false) {
484 if ($this->_tmp_dir ===
'' && ini_get(
'open_basedir') ===
false) {
487 $this->_using_tmpfile =
false;
488 return new PEAR_Error(
'Temp file could not be opened since open_basedir restriction in effect - please use setTmpDir() - using memory storage instead');
492 if ($this->_tmp_dir ===
'') {
496 $tmpfilename = tempnam($this->_tmp_dir,
"Spreadsheet_Excel_Writer");
497 $fh = @fopen($tmpfilename,
"w+b");
502 $this->_using_tmpfile =
false;
505 $this->_filehandle = $fh;
520 $num_sheets = count($sheetnames);
576 if ($this->_BIFF_version == 0x0500) {
587 if ($this->_BIFF_version == 0x0500) {
588 for ($i = $num_sheets; $i > 0; $i--) {
589 $sheetname = $sheetnames[$i-1];
595 if ($this->_BIFF_version == 0x0500) {
600 if (!empty($this->_colinfo)) {
601 $colcount = count($this->_colinfo);
602 for ($i = 0; $i < $colcount; $i++) {
618 if (!empty($this->_panes)) {
653 if (isset($this->_data)) {
657 if ($this->_using_tmpfile) {
663 if ($this->_using_tmpfile) {
664 if ($tmp = fread($this->_filehandle, $buffer)) {
682 function setMerge($first_row, $first_col, $last_row, $last_col)
684 if (($last_row < $first_row) || ($last_col < $first_col)) {
689 $this->_merged_ranges[] = array($first_row, $first_col, $last_row, $last_col);
753 function setColumn($firstcol, $lastcol, $width, $format = null, $hidden = 0, $level = 0)
755 $this->_colinfo[] = array($firstcol, $lastcol, $width, &$format, $hidden, $level);
758 $width = ($hidden) ? 0 : $width;
760 for ($col = $firstcol; $col <= $lastcol; $col++) {
761 $this->col_sizes[$col] = $width;
776 $this->_selection = array($first_row,$first_column,$last_row,$last_column);
793 $this->_panes = $panes;
810 $this->_panes = $panes;
820 $this->_orientation = 1;
830 $this->_orientation = 0;
841 $this->_paper_size =
$size;
854 if (strlen($string) >= 255) {
858 $this->_header = $string;
859 $this->_margin_head = $margin;
871 if (strlen($string) >= 255) {
875 $this->_footer = $string;
876 $this->_margin_foot = $margin;
887 $this->_hcenter = $center;
898 $this->_vcenter = $center;
947 $this->_margin_left = $margin;
958 $this->_margin_right = $margin;
969 $this->_margin_top = $margin;
980 $this->_margin_bottom = $margin;
992 $this->title_rowmin = $first_row;
993 if (isset($last_row)) {
994 $this->title_rowmax = $last_row;
996 $this->title_rowmax = $first_row;
1009 $this->title_colmin = $first_col;
1010 if (isset($last_col)) {
1011 $this->title_colmax = $last_col;
1013 $this->title_colmax = $first_col;
1026 function printArea($first_row, $first_col, $last_row, $last_col)
1028 $this->print_rowmin = $first_row;
1029 $this->print_colmin = $first_col;
1030 $this->print_rowmax = $last_row;
1031 $this->print_colmax = $last_col;
1042 $this->_print_gridlines = 0;
1052 $this->_screen_gridlines = 0;
1063 $this->_print_headers = $print;
1077 $this->_fit_page = 1;
1078 $this->_fit_width = $width;
1079 $this->_fit_height = $height;
1091 foreach ($breaks as $break) {
1092 array_push($this->_hbreaks, $break);
1105 foreach ($breaks as $break) {
1106 array_push($this->_vbreaks, $break);
1120 if ($scale < 10 || $scale > 400) {
1121 $this->
raiseError(
"Zoom factor $scale outside range: 10 <= zoom <= 400");
1125 $this->_zoom = floor($scale);
1138 if ($scale < 10 || $scale > 400) {
1139 $this->
raiseError(
"Print scale $scale outside range: 10 <= zoom <= 400");
1144 $this->_fit_page = 0;
1146 $this->_print_scale = floor($scale);
1165 if (preg_match(
"/^([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/", $token)) {
1168 } elseif (preg_match(
"/^[fh]tt?p:\/\//", $token)) {
1170 return $this->
writeUrl(
$row, $col, $token,
'', $format);
1171 } elseif (preg_match(
"/^mailto:/", $token)) {
1173 return $this->
writeUrl(
$row, $col, $token,
'', $format);
1174 } elseif (preg_match(
"/^(?:in|ex)ternal:/", $token)) {
1176 return $this->
writeUrl(
$row, $col, $token,
'', $format);
1177 } elseif (preg_match(
"/^=/", $token)) {
1180 } elseif ($token ==
'') {
1203 if (is_array($val)) {
1204 foreach ($val as $v) {
1213 $retval =
new PEAR_Error(
'$val needs to be an array');
1232 if (is_array($val)) {
1233 foreach ($val as $v) {
1238 $retval =
new PEAR_Error(
'$val needs to be an array');
1253 return($format->getXfIndex());
1276 if ($this->_using_tmpfile) {
1278 if (strlen(
$data) > $this->_limit) {
1281 fwrite($this->_filehandle,
$data);
1282 $this->_datasize += strlen(
$data);
1300 $cell = strtoupper($cell);
1303 if (preg_match(
"/([A-I]?[A-Z]):([A-I]?[A-Z])/", $cell, $match)) {
1304 list($no_use, $col1) = $this->
_cellToRowcol($match[1] .
'1');
1305 list($no_use, $col2) = $this->
_cellToRowcol($match[2] .
'1');
1306 return(array($col1, $col2));
1310 if (preg_match(
"/\$?([A-I]?[A-Z]\$?\d+):\$?([A-I]?[A-Z]\$?\d+)/", $cell, $match)) {
1313 return(array($row1, $col1, $row2, $col2));
1317 if (preg_match(
"/\$?([A-I]?[A-Z]\$?\d+)/", $cell)) {
1319 return(array($row1, $col1));
1336 preg_match(
"/\$?([A-I]?[A-Z])\$?(\d+)/",$cell,$match);
1341 $chars = split(
'', $col);
1346 $char = array_pop($chars);
1347 $col += (ord($char) -ord(
'A') +1) * pow(26,$expn);
1355 return(array(
$row, $col));
1371 $chars = preg_split(
'//', $plaintext, -1, PREG_SPLIT_NO_EMPTY);
1372 foreach ($chars as $char) {
1373 $value = ord($char) << $i;
1374 $rotated_bits = $value >> 15;
1376 $password ^= ($value | $rotated_bits);
1380 $password ^= strlen($plaintext);
1381 $password ^= 0xCE4B;
1395 function setOutline($visible =
true, $symbols_below =
true, $symbols_right =
true, $auto_style =
false)
1397 $this->_outline_on = $visible;
1398 $this->_outline_below = $symbols_below;
1399 $this->_outline_right = $symbols_right;
1400 $this->_outline_style = $auto_style;
1403 if ($this->_outline_on) {
1404 $this->_outline_on = 1;
1435 $xf = $this->
_XF($format);
1438 if (
$row >= $this->_xls_rowmax) {
1441 if ($col >= $this->_xls_colmax) {
1444 if ($row < $this->_dim_rowmin) {
1445 $this->_dim_rowmin =
$row;
1447 if (
$row > $this->_dim_rowmax) {
1448 $this->_dim_rowmax =
$row;
1450 if ($col < $this->_dim_colmin) {
1451 $this->_dim_colmin = $col;
1453 if ($col > $this->_dim_colmax) {
1454 $this->_dim_colmax = $col;
1459 $xl_double = pack(
"d", $num);
1460 if ($this->_byte_order) {
1461 $xl_double = strrev($xl_double);
1485 if ($this->_BIFF_version == 0x0600) {
1488 $strlen = strlen($str);
1491 $xf = $this->
_XF($format);
1496 if (
$row >= $this->_xls_rowmax) {
1499 if ($col >= $this->_xls_colmax) {
1502 if ($row < $this->_dim_rowmin) {
1503 $this->_dim_rowmin =
$row;
1505 if (
$row > $this->_dim_rowmax) {
1506 $this->_dim_rowmax =
$row;
1508 if ($col < $this->_dim_colmin) {
1509 $this->_dim_colmin = $col;
1511 if ($col > $this->_dim_colmax) {
1512 $this->_dim_colmax = $col;
1515 if ($strlen > $this->_xls_strmax) {
1516 $str = substr($str, 0, $this->_xls_strmax);
1523 $data = pack(
"vvvv",
$row, $col, $xf, $strlen);
1536 if ($encoding !=
'UTF-16LE' && !function_exists(
'iconv')) {
1537 $this->
raiseError(
"Using an input encoding other than UTF-16LE requires PHP support for iconv");
1539 $this->_input_encoding = $encoding;
1559 if ($this->_input_encoding ==
'UTF-16LE')
1561 $strlen = function_exists(
'mb_strlen') ? mb_strlen($str,
'UTF-16LE') : (strlen($str) / 2);
1564 elseif ($this->_input_encoding !=
'')
1566 $str = iconv($this->_input_encoding,
'UTF-16LE', $str);
1567 $strlen = function_exists(
'mb_strlen') ? mb_strlen($str,
'UTF-16LE') : (strlen($str) / 2);
1572 $strlen = strlen($str);
1577 $xf = $this->
_XF($format);
1586 $str = pack(
'vC', $strlen, $encoding).$str;
1589 if (!isset($this->_str_table[$str])) {
1590 $this->_str_table[$str] = $this->_str_unique++;
1592 $this->_str_total++;
1595 $data = pack(
'vvvV',
$row, $col, $xf, $this->_str_table[$str]);
1612 if (
$row >= $this->_xls_rowmax) {
1615 if ($col >= $this->_xls_colmax) {
1618 if ($row < $this->_dim_rowmin) {
1619 $this->_dim_rowmin =
$row;
1621 if (
$row > $this->_dim_rowmax) {
1622 $this->_dim_rowmax =
$row;
1624 if ($col < $this->_dim_colmin) {
1625 $this->_dim_colmin = $col;
1627 if ($col > $this->_dim_colmax) {
1628 $this->_dim_colmax = $col;
1644 $note_length = strlen($note);
1650 if (
$row >= $this->_xls_rowmax) {
1653 if ($col >= $this->_xls_colmax) {
1656 if ($row < $this->_dim_rowmin) {
1657 $this->_dim_rowmin =
$row;
1659 if (
$row > $this->_dim_rowmax) {
1660 $this->_dim_rowmax =
$row;
1662 if ($col < $this->_dim_colmin) {
1663 $this->_dim_colmin = $col;
1665 if ($col > $this->_dim_colmax) {
1666 $this->_dim_colmax = $col;
1670 $length = 0x0006 + min($note_length, 2048);
1672 $data = pack(
"vvv",
$row, $col, $note_length);
1675 for ($i = $max_length; $i < $note_length; $i += $max_length) {
1676 $chunk = substr($note, $i, $max_length);
1677 $length = 0x0006 + strlen($chunk);
1679 $data = pack(
"vvv", -1, 0, strlen($chunk));
1711 $xf = $this->
_XF($format);
1714 if (
$row >= $this->_xls_rowmax) {
1717 if ($col >= $this->_xls_colmax) {
1720 if ($row < $this->_dim_rowmin) {
1721 $this->_dim_rowmin =
$row;
1723 if (
$row > $this->_dim_rowmax) {
1724 $this->_dim_rowmax =
$row;
1726 if ($col < $this->_dim_colmin) {
1727 $this->_dim_colmin = $col;
1729 if ($col > $this->_dim_colmax) {
1730 $this->_dim_colmax = $col;
1764 $xf = $this->
_XF($format);
1776 if (preg_match(
"/^=/", $formula)) {
1777 $formula = preg_replace(
"/(^=)/",
"", $formula);
1778 } elseif (preg_match(
"/^@/", $formula)) {
1779 $formula = preg_replace(
"/(^@)/",
"", $formula);
1787 $error = $this->_parser->parse($formula);
1793 $formula = $this->_parser->toReversePolish();
1794 if ($this->
isError($formula)) {
1799 $formlen = strlen($formula);
1803 $data = pack(
"vvvdvVv",
$row, $col, $xf, $num,
1804 $grbit, $unknown, $formlen);
1861 if (preg_match(
'[^internal:]',
$url)) {
1864 if (preg_match(
'[^external:]',
$url)) {
1867 return($this->
_writeUrlWeb($row1, $col1, $row2, $col2,
$url, $string, $format));
1906 $unknown1 = pack(
"H*",
"D0C9EA79F9BACE118C8200AA004BA90B02000000");
1907 $unknown2 = pack(
"H*",
"E0C9EA79F9BACE118C8200AA004BA90B");
1913 $url = join(
"\0", preg_split(
"''",
$url, -1, PREG_SPLIT_NO_EMPTY));
1917 $url_len = pack(
"V", strlen(
$url));
1924 $data = pack(
"vvvv", $row1, $row2, $col1, $col2);
1957 $url = preg_replace(
'/^internal:/',
'',
$url);
1969 $unknown1 = pack(
"H*",
"D0C9EA79F9BACE118C8200AA004BA90B02000000");
1975 $url = join(
"\0", preg_split(
"''",
$url, -1, PREG_SPLIT_NO_EMPTY));
1979 $url_len = pack(
"V", floor(strlen(
$url)/2));
1986 $data = pack(
"vvvv", $row1, $row2, $col1, $col2);
2035 $str = preg_replace(
'/\#/',
' - ',
$url);
2048 if (!preg_match(
"/\\\/",
$url)) {
2051 if (preg_match(
"/^\.\.\\\/",
$url)) {
2075 if (preg_match(
"/\#/",
$url)) {
2101 $unknown1 = pack(
"H*",
'D0C9EA79F9BACE118C8200AA004BA90B02000000' );
2103 $unknown3 = pack(
"H*",
'FFFFADDE000000000000000000000000000000000000000');
2107 $data = pack(
"vvvv", $row1, $row2, $col1, $col2) .
2143 function setRow(
$row, $height, $format = null, $hidden =
false, $level = 0)
2153 $ixfe = $this->_XF($format);
2156 $this->_row_sizes[
$row] = $height;
2159 if ($height != null) {
2160 $miyRw = $height * 20;
2165 $level = max(0, min($level, 7));
2166 $this->_outline_row_level = max($level, $this->_outline_row_level);
2185 $header = pack(
"vv", $record, $length);
2186 $data = pack(
"vvvvvvvv",
$row, $colMic, $colMac, $miyRw,
2187 $irwMac,$reserved, $grbit, $ixfe);
2188 $this->_append($header.$data);
2196 function _storeDimensions()
2199 $row_min = $this->_dim_rowmin;
2200 $row_max = $this->_dim_rowmax + 1;
2201 $col_min = $this->_dim_colmin;
2202 $col_max = $this->_dim_colmax + 1;
2205 if ($this->_BIFF_version == 0x0500) {
2207 $data = pack(
"vvvvv", $row_min, $row_max,
2208 $col_min, $col_max, $reserved);
2209 } elseif ($this->_BIFF_version == 0x0600) {
2211 $data = pack(
"VVvvv", $row_min, $row_max,
2212 $col_min, $col_max, $reserved);
2214 $header = pack(
"vv", $record, $length);
2215 $this->_prepend($header.$data);
2223 function _storeWindow2()
2226 if ($this->_BIFF_version == 0x0500) {
2228 } elseif ($this->_BIFF_version == 0x0600) {
2239 $fDspGrid = $this->_screen_gridlines;
2241 $fFrozen = $this->_frozen;
2245 $fDspGuts = $this->_outline_on;
2246 $fFrozenNoSplit = 0;
2247 $fSelected = $this->selected;
2251 $grbit |= $fDspGrid << 1;
2252 $grbit |= $fDspRwCol << 2;
2253 $grbit |= $fFrozen << 3;
2254 $grbit |= $fDspZeros << 4;
2255 $grbit |= $fDefaultHdr << 5;
2256 $grbit |= $fArabic << 6;
2257 $grbit |= $fDspGuts << 7;
2258 $grbit |= $fFrozenNoSplit << 8;
2259 $grbit |= $fSelected << 9;
2260 $grbit |= $fPaged << 10;
2262 $header = pack(
"vv", $record, $length);
2263 $data = pack(
"vvv", $grbit, $rwTop, $colLeft);
2265 if ($this->_BIFF_version == 0x0500) {
2266 $rgbHdr = 0x00000000;
2267 $data .= pack(
"V", $rgbHdr);
2268 } elseif ($this->_BIFF_version == 0x0600) {
2270 $zoom_factor_page_break = 0x0000;
2271 $zoom_factor_normal = 0x0000;
2272 $data .= pack(
"vvvvV", $rgbHdr, 0x0000, $zoom_factor_page_break, $zoom_factor_normal, 0x00000000);
2274 $this->_append($header.$data);
2282 function _storeDefcol()
2288 $header = pack(
"vv", $record, $length);
2289 $data = pack(
"v", $colwidth);
2290 $this->_prepend($header . $data);
2308 function _storeColinfo($col_array)
2310 if (isset($col_array[0])) {
2311 $colFirst = $col_array[0];
2313 if (isset($col_array[1])) {
2314 $colLast = $col_array[1];
2316 if (isset($col_array[2])) {
2317 $coldx = $col_array[2];
2321 if (isset($col_array[3])) {
2322 $format = $col_array[3];
2326 if (isset($col_array[4])) {
2327 $grbit = $col_array[4];
2331 if (isset($col_array[5])) {
2332 $level = $col_array[5];
2342 $ixfe = $this->_XF($format);
2345 $level = max(0, min($level, 7));
2346 $grbit |= $level << 8;
2348 $header = pack(
"vv", $record, $length);
2349 $data = pack(
"vvvvvC", $colFirst, $colLast, $coldx,
2350 $ixfe, $grbit, $reserved);
2351 $this->_prepend($header.$data);
2361 function _storeSelection($array)
2363 list($rwFirst,$colFirst,$rwLast,$colLast) = $array;
2367 $pnn = $this->_active_pane;
2369 $colAct = $colFirst;
2373 if (!isset($rwLast)) {
2376 if (!isset($colLast)) {
2377 $colLast = $colFirst;
2381 if ($rwFirst > $rwLast) {
2382 list($rwFirst, $rwLast) = array($rwLast, $rwFirst);
2385 if ($colFirst > $colLast) {
2386 list($colFirst, $colLast) = array($colLast, $colFirst);
2389 $header = pack(
"vv", $record, $length);
2390 $data = pack(
"CvvvvvvCC", $pnn, $rwAct, $colAct,
2393 $colFirst, $colLast);
2394 $this->_append($header . $data);
2402 function _storeMergedCells()
2405 if (count($this->_merged_ranges) == 0) {
2409 $length = 2 + count($this->_merged_ranges) * 8;
2411 $header = pack(
'vv', $record, $length);
2412 $data = pack(
'v', count($this->_merged_ranges));
2413 foreach ($this->_merged_ranges as $range) {
2414 $data .= pack(
'vvvv', $range[0], $range[2], $range[1], $range[3]);
2416 $this->_append($header . $data);
2432 function _storeExterncount($count)
2437 $header = pack(
"vv", $record, $length);
2438 $data = pack(
"v", $count);
2439 $this->_prepend($header . $data);
2451 function _storeExternsheet($sheetname)
2458 if ($this->name == $sheetname) {
2464 $length = 0x02 + strlen($sheetname);
2465 $cch = strlen($sheetname);
2469 $header = pack(
"vv", $record, $length);
2470 $data = pack(
"CC", $cch, $rgch);
2471 $this->_prepend($header . $data . $sheetname);
2488 function _storePanes($panes)
2493 $colLeft = $panes[3];
2494 if (count($panes) > 4) {
2495 $pnnAct = $panes[4];
2503 if ($this->_frozen) {
2505 if (!isset($rwTop)) {
2508 if (!isset($colLeft)) {
2513 if (!isset($rwTop)) {
2516 if (!isset($colLeft)) {
2526 $x = 113.879*$x + 390;
2533 if (!isset($pnnAct)) {
2534 if ($x != 0 && $y != 0) {
2537 if ($x != 0 && $y == 0) {
2540 if ($x == 0 && $y != 0) {
2543 if ($x == 0 && $y == 0) {
2548 $this->_active_pane = $pnnAct;
2550 $header = pack(
"vv", $record, $length);
2551 $data = pack(
"vvvvv", $x, $y, $rwTop, $colLeft, $pnnAct);
2552 $this->_append($header . $data);
2560 function _storeSetup()
2565 $iPaperSize = $this->_paper_size;
2566 $iScale = $this->_print_scale;
2568 $iFitWidth = $this->_fit_width;
2569 $iFitHeight = $this->_fit_height;
2573 $numHdr = $this->_margin_head;
2574 $numFtr = $this->_margin_foot;
2577 $fLeftToRight = 0x0;
2578 $fLandscape = $this->_orientation;
2586 $grbit = $fLeftToRight;
2587 $grbit |= $fLandscape << 1;
2588 $grbit |= $fNoPls << 2;
2589 $grbit |= $fNoColor << 3;
2590 $grbit |= $fDraft << 4;
2591 $grbit |= $fNotes << 5;
2592 $grbit |= $fNoOrient << 6;
2593 $grbit |= $fUsePage << 7;
2595 $numHdr = pack(
"d", $numHdr);
2596 $numFtr = pack(
"d", $numFtr);
2597 if ($this->_byte_order) {
2598 $numHdr = strrev($numHdr);
2599 $numFtr = strrev($numFtr);
2602 $header = pack(
"vv", $record, $length);
2603 $data1 = pack(
"vvvvvvvv", $iPaperSize,
2611 $data2 = $numHdr.$numFtr;
2612 $data3 = pack(
"v", $iCopies);
2613 $this->_prepend($header . $data1 . $data2 . $data3);
2621 function _storeHeader()
2625 $str = $this->_header;
2626 $cch = strlen($str);
2627 if ($this->_BIFF_version == 0x0600) {
2634 $header = pack(
"vv", $record, $length);
2635 if ($this->_BIFF_version == 0x0600) {
2636 $data = pack(
"vC", $cch, $encoding);
2638 $data = pack(
"C", $cch);
2641 $this->_prepend($header.$data.$str);
2649 function _storeFooter()
2653 $str = $this->_footer;
2654 $cch = strlen($str);
2655 if ($this->_BIFF_version == 0x0600) {
2662 $header = pack(
"vv", $record, $length);
2663 if ($this->_BIFF_version == 0x0600) {
2664 $data = pack(
"vC", $cch, $encoding);
2666 $data = pack(
"C", $cch);
2669 $this->_prepend($header . $data . $str);
2677 function _storeHcenter()
2682 $fHCenter = $this->_hcenter;
2684 $header = pack(
"vv", $record, $length);
2685 $data = pack(
"v", $fHCenter);
2687 $this->_prepend($header.$data);
2695 function _storeVcenter()
2700 $fVCenter = $this->_vcenter;
2702 $header = pack(
"vv", $record, $length);
2703 $data = pack(
"v", $fVCenter);
2704 $this->_prepend($header . $data);
2712 function _storeMarginLeft()
2717 $margin = $this->_margin_left;
2719 $header = pack(
"vv", $record, $length);
2720 $data = pack(
"d", $margin);
2721 if ($this->_byte_order) {
2722 $data = strrev($data);
2725 $this->_prepend($header . $data);
2733 function _storeMarginRight()
2738 $margin = $this->_margin_right;
2740 $header = pack(
"vv", $record, $length);
2741 $data = pack(
"d", $margin);
2742 if ($this->_byte_order) {
2743 $data = strrev($data);
2746 $this->_prepend($header . $data);
2754 function _storeMarginTop()
2759 $margin = $this->_margin_top;
2761 $header = pack(
"vv", $record, $length);
2762 $data = pack(
"d", $margin);
2763 if ($this->_byte_order) {
2764 $data = strrev($data);
2767 $this->_prepend($header . $data);
2775 function _storeMarginBottom()
2780 $margin = $this->_margin_bottom;
2782 $header = pack(
"vv", $record, $length);
2783 $data = pack(
"d", $margin);
2784 if ($this->_byte_order) {
2785 $data = strrev($data);
2788 $this->_prepend($header . $data);
2802 function mergeCells($first_row, $first_col, $last_row, $last_col)
2809 if ($first_row > $last_row) {
2810 list($first_row, $last_row) = array($last_row, $first_row);
2813 if ($first_col > $last_col) {
2814 list($first_col, $last_col) = array($last_col, $first_col);
2817 $header = pack(
"vv", $record, $length);
2818 $data = pack(
"vvvvv", $cref, $first_row, $last_row,
2819 $first_col, $last_col);
2821 $this->_append($header.$data);
2829 function _storePrintHeaders()
2834 $fPrintRwCol = $this->_print_headers;
2836 $header = pack(
"vv", $record, $length);
2837 $data = pack(
"v", $fPrintRwCol);
2838 $this->_prepend($header . $data);
2847 function _storePrintGridlines()
2852 $fPrintGrid = $this->_print_gridlines;
2854 $header = pack(
"vv", $record, $length);
2855 $data = pack(
"v", $fPrintGrid);
2856 $this->_prepend($header . $data);
2865 function _storeGridset()
2870 $fGridSet = !($this->_print_gridlines);
2872 $header = pack(
"vv", $record, $length);
2873 $data = pack(
"v", $fGridSet);
2874 $this->_prepend($header . $data);
2885 function _storeGuts()
2893 $row_level = $this->_outline_row_level;
2898 $colcount = count($this->_colinfo);
2899 for ($i = 0; $i < $colcount; $i++) {
2901 if (count($this->_colinfo[$i]) >= 6) {
2902 $col_level = max($this->_colinfo[$i][5], $col_level);
2907 $col_level = max(0, min($col_level, 7));
2917 $header = pack(
"vv", $record, $length);
2918 $data = pack(
"vvvv", $dxRwGut, $dxColGut, $row_level, $col_level);
2920 $this->_prepend($header.$data);
2930 function _storeWsbool()
2946 if ($this->_outline_style) {
2949 if ($this->_outline_below) {
2952 if ($this->_outline_right) {
2955 if ($this->_fit_page) {
2958 if ($this->_outline_on) {
2962 $header = pack(
"vv", $record, $length);
2963 $data = pack(
"v", $grbit);
2964 $this->_prepend($header . $data);
2972 function _storeHbreak()
2975 if (empty($this->_hbreaks)) {
2980 $breaks = $this->_hbreaks;
2981 sort($breaks, SORT_NUMERIC);
2982 if ($breaks[0] == 0) {
2983 array_shift($breaks);
2987 $cbrk = count($breaks);
2988 if ($this->_BIFF_version == 0x0600) {
2989 $length = 2 + 6*$cbrk;
2991 $length = 2 + 2*$cbrk;
2994 $header = pack(
"vv", $record, $length);
2995 $data = pack(
"v", $cbrk);
2998 foreach ($breaks as $break) {
2999 if ($this->_BIFF_version == 0x0600) {
3000 $data .= pack(
"vvv", $break, 0x0000, 0x00ff);
3002 $data .= pack(
"v", $break);
3006 $this->_prepend($header.$data);
3015 function _storeVbreak()
3018 if (empty($this->_vbreaks)) {
3024 $breaks = array_slice($this->_vbreaks,0,1000);
3027 sort($breaks, SORT_NUMERIC);
3028 if ($breaks[0] == 0) {
3029 array_shift($breaks);
3033 $cbrk = count($breaks);
3034 if ($this->_BIFF_version == 0x0600) {
3035 $length = 2 + 6*$cbrk;
3037 $length = 2 + 2*$cbrk;
3040 $header = pack(
"vv", $record, $length);
3041 $data = pack(
"v", $cbrk);
3044 foreach ($breaks as $break) {
3045 if ($this->_BIFF_version == 0x0600) {
3046 $data .= pack(
"vvv", $break, 0x0000, 0xffff);
3048 $data .= pack(
"v", $break);
3052 $this->_prepend($header . $data);
3060 function _storeProtect()
3063 if ($this->_protect == 0) {
3070 $fLock = $this->_protect;
3072 $header = pack(
"vv", $record, $length);
3073 $data = pack(
"v", $fLock);
3075 $this->_prepend($header.$data);
3083 function _storePassword()
3086 if (($this->_protect == 0) || (!isset($this->_password))) {
3093 $wPassword = $this->_password;
3095 $header = pack(
"vv", $record, $length);
3096 $data = pack(
"v", $wPassword);
3098 $this->_prepend($header . $data);
3114 function insertBitmap(
$row, $col, $bitmap, $x = 0, $y = 0, $scale_x = 1, $scale_y = 1)
3116 $bitmap_array = $this->_processBitmap($bitmap);
3117 if ($this->isError($bitmap_array)) {
3118 $this->writeString(
$row, $col, $bitmap_array->getMessage());
3121 list($width, $height,
$size, $data) = $bitmap_array;
3125 $height *= $scale_y;
3128 $this->_positionImage($col,
$row, $x, $y, $width, $height);
3132 $length = 8 +
$size;
3137 $header = pack(
"vvvvV", $record, $length, $cf, $env, $lcb);
3138 $this->_append($header.$data);
3192 function _positionImage($col_start, $row_start, $x1, $y1, $width, $height)
3195 $col_end = $col_start;
3196 $row_end = $row_start;
3199 if ($x1 >= $this->_sizeCol($col_start)) {
3202 if ($y1 >= $this->_sizeRow($row_start)) {
3206 $width = $width + $x1 -1;
3207 $height = $height + $y1 -1;
3210 while ($width >= $this->_sizeCol($col_end)) {
3211 $width -= $this->_sizeCol($col_end);
3216 while ($height >= $this->_sizeRow($row_end)) {
3217 $height -= $this->_sizeRow($row_end);
3224 if ($this->_sizeCol($col_start) == 0) {
3227 if ($this->_sizeCol($col_end) == 0) {
3230 if ($this->_sizeRow($row_start) == 0) {
3233 if ($this->_sizeRow($row_end) == 0) {
3238 $x1 = $x1 / $this->_sizeCol($col_start) * 1024;
3239 $y1 = $y1 / $this->_sizeRow($row_start) * 256;
3240 $x2 = $width / $this->_sizeCol($col_end) * 1024;
3241 $y2 = $height / $this->_sizeRow($row_end) * 256;
3243 $this->_storeObjPicture($col_start, $x1,
3258 function _sizeCol($col)
3261 if (isset($this->col_sizes[$col])) {
3262 if ($this->col_sizes[$col] == 0) {
3265 return(floor(7 * $this->col_sizes[$col] + 5));
3285 if (isset($this->_row_sizes[
$row])) {
3286 if ($this->_row_sizes[$row] == 0) {
3289 return(floor(4/3 * $this->_row_sizes[$row]));
3310 function _storeObjPicture($colL,$dxL,$rwT,$dyT,$colR,$dxR,$rwB,$dyB)
3321 $Reserved1 = 0x0000;
3322 $Reserved2 = 0x0000;
3334 $Reserved3 = 0x0000;
3335 $cbPictFmla = 0x0000;
3336 $Reserved4 = 0x0000;
3338 $Reserved5 = 0x0000;
3341 $header = pack(
"vv", $record, $length);
3342 $data = pack(
"V", $cObj);
3343 $data .= pack(
"v", $OT);
3344 $data .= pack(
"v", $id);
3345 $data .= pack(
"v", $grbit);
3346 $data .= pack(
"v", $colL);
3347 $data .= pack(
"v", $dxL);
3348 $data .= pack(
"v", $rwT);
3349 $data .= pack(
"v", $dyT);
3350 $data .= pack(
"v", $colR);
3351 $data .= pack(
"v", $dxR);
3352 $data .= pack(
"v", $rwB);
3353 $data .= pack(
"v", $dyB);
3354 $data .= pack(
"v", $cbMacro);
3355 $data .= pack(
"V", $Reserved1);
3356 $data .= pack(
"v", $Reserved2);
3357 $data .= pack(
"C", $icvBack);
3358 $data .= pack(
"C", $icvFore);
3359 $data .= pack(
"C", $fls);
3360 $data .= pack(
"C", $fAuto);
3361 $data .= pack(
"C", $icv);
3362 $data .= pack(
"C", $lns);
3363 $data .= pack(
"C", $lnw);
3364 $data .= pack(
"C", $fAutoB);
3365 $data .= pack(
"v", $frs);
3366 $data .= pack(
"V", $cf);
3367 $data .= pack(
"v", $Reserved3);
3368 $data .= pack(
"v", $cbPictFmla);
3369 $data .= pack(
"v", $Reserved4);
3370 $data .= pack(
"v", $grbit2);
3371 $data .= pack(
"V", $Reserved5);
3373 $this->_append($header . $data);
3385 function _processBitmap($bitmap)
3388 $bmp_fd = @fopen($bitmap,
"rb");
3390 $this->raiseError(
"Couldn't import $bitmap");
3394 $data = fread($bmp_fd, filesize($bitmap));
3397 if (strlen($data) <= 0x36) {
3398 $this->raiseError(
"$bitmap doesn't contain enough data.\n");
3402 $identity = unpack(
"A2ident", $data);
3403 if ($identity[
'ident'] !=
"BM") {
3404 $this->raiseError(
"$bitmap doesn't appear to be a valid bitmap image.\n");
3408 $data = substr($data, 2);
3413 $size_array = unpack(
"Vsa", substr($data, 0, 4));
3414 $size = $size_array[
'sa'];
3415 $data = substr($data, 4);
3420 $data = substr($data, 12);
3423 $width_and_height = unpack(
"V2", substr($data, 0, 8));
3424 $width = $width_and_height[1];
3425 $height = $width_and_height[2];
3426 $data = substr($data, 8);
3427 if ($width > 0xFFFF) {
3428 $this->raiseError(
"$bitmap: largest image width supported is 65k.\n");
3430 if ($height > 0xFFFF) {
3431 $this->raiseError(
"$bitmap: largest image height supported is 65k.\n");
3435 $planes_and_bitcount = unpack(
"v2", substr($data, 0, 4));
3436 $data = substr($data, 4);
3437 if ($planes_and_bitcount[2] != 24) {
3438 $this->raiseError(
"$bitmap isn't a 24bit true color bitmap.\n");
3440 if ($planes_and_bitcount[1] != 1) {
3441 $this->raiseError(
"$bitmap: only 1 plane supported in bitmap image.\n");
3445 $compression = unpack(
"Vcomp", substr($data, 0, 4));
3446 $data = substr($data, 4);
3449 if ($compression[
'comp'] != 0) {
3450 $this->raiseError(
"$bitmap: compression not supported in bitmap image.\n");
3454 $data = substr($data, 20);
3457 $header = pack(
"Vvvvv", 0x000c, $width, $height, 0x01, 0x18);
3458 $data = $header . $data;
3460 return (array($width, $height,
$size, $data));
3469 function _storeZoom()
3472 if ($this->_zoom == 100) {
3479 $header = pack(
"vv", $record, $length);
3480 $data = pack(
"vv", $this->_zoom, 100);
3481 $this->_append($header . $data);
3487 function setValidation($row1, $col1, $row2, $col2, &$validator)
3489 $this->_dv[] = $validator->_getData() .
3490 pack(
"vvvvv", 1, $row1, $row2, $col1, $col2);
3498 function _storeDataValidity()
3504 $horPos = 0x00000000;
3505 $verPos = 0x00000000;
3506 $objId = 0xffffffff;
3508 $header = pack(
'vv', $record, $length);
3509 $data = pack(
'vVVVV', $grbit, $horPos, $verPos, $objId,
3511 $this->_append($header.$data);
3514 foreach ($this->_dv as $dv) {
3515 $length = strlen($dv);
3516 $header = pack(
"vv", $record, $length);
3517 $this->_append($header . $dv);