35 require_once(
'Format.php');
36 require_once(
'classes/Spreadsheet/Excel/Writer/BIFFwriter.php');
37 require_once(
'classes/Spreadsheet/Excel/Writer/Worksheet.php');
38 require_once(
'classes/Spreadsheet/Excel/Writer/Parser.php');
39 require_once(
'classes/OLE/PPS/Root.php');
40 require_once(
'classes/OLE/PPS/File.php');
182 $this->_activesheet = 0;
183 $this->_firstsheet = 0;
184 $this->_selected = 0;
185 $this->_xf_index = 16;
186 $this->_fileclosed = 0;
187 $this->_biffsize = 0;
188 $this->_sheetname =
"Sheet";
190 $this->_worksheets = array();
191 $this->_sheetnames = array();
192 $this->_formats = array();
193 $this->_palette = array();
194 $this->_codepage = 0x04E4;
195 $this->_country_code = -1;
198 $this->_url_format =& $this->
addFormat(array(
'color' =>
'blue',
'underline' => 1));
199 $this->_str_total = 0;
200 $this->_str_unique = 0;
201 $this->_str_table = array();
203 $this->_tmp_dir =
'';
215 if ($this->_fileclosed) {
222 $this->_fileclosed = 1;
266 $this->_BIFF_version = $version;
268 $this->_limit = 8224;
269 $this->_tmp_format->_BIFF_version = $version;
270 $this->_url_format->_BIFF_version = $version;
271 $this->_parser->_BIFF_version = $version;
272 $total_worksheets = count($this->_worksheets);
274 for ($i = 0; $i < $total_worksheets; $i++) {
275 $this->_worksheets[$i]->_BIFF_version = $version;
277 $total_formats = count($this->_formats);
279 for ($i = 0; $i < $total_formats; $i++) {
280 $this->_formats[$i]->_BIFF_version = $version;
294 $this->_country_code = $code;
309 $index = count($this->_worksheets);
313 $name = $sheetname.($index+1);
317 if (strlen(
$name) > 31) {
318 return $this->
raiseError(
"Sheetname $name must be <= 31 chars");
322 $total_worksheets = count($this->_worksheets);
323 for ($i=0; $i < $total_worksheets; $i++)
325 if (
$name == $this->_worksheets[$i]->getName()) {
326 return $this->
raiseError(
"Worksheet '$name' already exists");
332 $this->_activesheet, $this->_firstsheet,
333 $this->_str_total, $this->_str_unique,
334 $this->_str_table, $this->_url_format,
337 $this->_worksheets[$index] = &$worksheet;
338 $this->_sheetnames[$index] =
$name;
339 $this->_parser->setExtSheet(
$name, $index);
354 $this->_xf_index += 1;
355 $this->_formats[] = &$format;
367 include_once(
'Validator.php');
391 if ($index < 8 or $index > 64) {
393 return $this->
raiseError(
"Color index $index outside range: 8 <= index <= 64");
397 if ( ($red < 0 or $red > 255) or
398 ($green < 0 or $green > 255) or
399 ($blue < 0 or $blue > 255) )
401 return $this->
raiseError(
"Color component outside range: 0 <= color <= 255");
407 $this->_palette[$index] = array($red, $green, $blue, 0);
418 $this->_palette = array(
419 array(0x00, 0x00, 0x00, 0x00),
420 array(0xff, 0xff, 0xff, 0x00),
421 array(0xff, 0x00, 0x00, 0x00),
422 array(0x00, 0xff, 0x00, 0x00),
423 array(0x00, 0x00, 0xff, 0x00),
424 array(0xff, 0xff, 0x00, 0x00),
425 array(0xff, 0x00, 0xff, 0x00),
426 array(0x00, 0xff, 0xff, 0x00),
427 array(0x80, 0x00, 0x00, 0x00),
428 array(0x00, 0x80, 0x00, 0x00),
429 array(0x00, 0x00, 0x80, 0x00),
430 array(0x80, 0x80, 0x00, 0x00),
431 array(0x80, 0x00, 0x80, 0x00),
432 array(0x00, 0x80, 0x80, 0x00),
433 array(0xc0, 0xc0, 0xc0, 0x00),
434 array(0x80, 0x80, 0x80, 0x00),
435 array(0x99, 0x99, 0xff, 0x00),
436 array(0x99, 0x33, 0x66, 0x00),
437 array(0xff, 0xff, 0xcc, 0x00),
438 array(0xcc, 0xff, 0xff, 0x00),
439 array(0x66, 0x00, 0x66, 0x00),
440 array(0xff, 0x80, 0x80, 0x00),
441 array(0x00, 0x66, 0xcc, 0x00),
442 array(0xcc, 0xcc, 0xff, 0x00),
443 array(0x00, 0x00, 0x80, 0x00),
444 array(0xff, 0x00, 0xff, 0x00),
445 array(0xff, 0xff, 0x00, 0x00),
446 array(0x00, 0xff, 0xff, 0x00),
447 array(0x80, 0x00, 0x80, 0x00),
448 array(0x80, 0x00, 0x00, 0x00),
449 array(0x00, 0x80, 0x80, 0x00),
450 array(0x00, 0x00, 0xff, 0x00),
451 array(0x00, 0xcc, 0xff, 0x00),
452 array(0xcc, 0xff, 0xff, 0x00),
453 array(0xcc, 0xff, 0xcc, 0x00),
454 array(0xff, 0xff, 0x99, 0x00),
455 array(0x99, 0xcc, 0xff, 0x00),
456 array(0xff, 0x99, 0xcc, 0x00),
457 array(0xcc, 0x99, 0xff, 0x00),
458 array(0xff, 0xcc, 0x99, 0x00),
459 array(0x33, 0x66, 0xff, 0x00),
460 array(0x33, 0xcc, 0xcc, 0x00),
461 array(0x99, 0xcc, 0x00, 0x00),
462 array(0xff, 0xcc, 0x00, 0x00),
463 array(0xff, 0x99, 0x00, 0x00),
464 array(0xff, 0x66, 0x00, 0x00),
465 array(0x66, 0x66, 0x99, 0x00),
466 array(0x96, 0x96, 0x96, 0x00),
467 array(0x00, 0x33, 0x66, 0x00),
468 array(0x33, 0x99, 0x66, 0x00),
469 array(0x00, 0x33, 0x00, 0x00),
470 array(0x33, 0x33, 0x00, 0x00),
471 array(0x99, 0x33, 0x00, 0x00),
472 array(0x99, 0x33, 0x66, 0x00),
473 array(0x33, 0x33, 0x99, 0x00),
474 array(0x33, 0x33, 0x33, 0x00),
488 if ($this->_activesheet == 0) {
489 $this->_worksheets[0]->selected = 1;
494 $total_worksheets = count($this->_worksheets);
495 for ($i=0; $i < $total_worksheets; $i++) {
496 if ($this->_worksheets[$i]->selected) {
499 $this->_worksheets[$i]->close($this->_sheetnames);
504 if ($this->_BIFF_version == 0x0600) {
508 if ($this->_BIFF_version == 0x0500) {
512 if ($this->_BIFF_version == 0x0500) {
524 for ($i=0; $i < $total_worksheets; $i++) {
525 $this->
_storeBoundsheet($this->_worksheets[$i]->name,$this->_worksheets[$i]->offset);
528 if ($this->_country_code != -1) {
532 if ($this->_BIFF_version == 0x0600) {
561 $this->_tmp_dir =
$dir;
576 if ($this->_tmp_dir !=
'') {
577 $OLE->setTempDir($this->_tmp_dir);
583 $OLE->append($this->_data);
584 $total_worksheets = count($this->_worksheets);
585 for ($i = 0; $i < $total_worksheets; $i++)
587 while ($tmp = $this->_worksheets[$i]->getData()) {
592 if ($this->_tmp_dir !=
'') {
593 $root->setTempDir($this->_tmp_dir);
595 $res = $root->save($this->_filename);
609 if ($this->_BIFF_version == 0x0600) {
610 $boundsheet_length = 12;
613 $boundsheet_length = 11;
618 if ($this->_BIFF_version == 0x0600) {
622 if ($this->_country_code != -1) {
628 $total_worksheets = count($this->_worksheets);
630 for ($i=0; $i < $total_worksheets; $i++) {
631 $offset += $boundsheet_length + strlen($this->_worksheets[$i]->name);
635 for ($i=0; $i < $total_worksheets; $i++) {
636 $this->_worksheets[$i]->offset = $offset;
637 $offset += $this->_worksheets[$i]->_datasize;
639 $this->_biffsize = $offset;
651 $font = $format->getFont();
656 for ($i=1; $i <= 5; $i++){
666 $key = $format->getFontKey();
669 $total_formats = count($this->_formats);
670 for ($i=0; $i < $total_formats; $i++)
672 $key = $this->_formats[$i]->getFontKey();
673 if (isset($fonts[$key])) {
675 $this->_formats[$i]->font_index = $fonts[$key];
679 $fonts[$key] = $index;
680 $this->_formats[$i]->font_index = $index;
682 $font = $this->_formats[$i]->getFont();
696 $hash_num_formats = array();
697 $num_formats = array();
702 $total_formats = count($this->_formats);
703 for ($i=0; $i < $total_formats; $i++)
705 $num_format = $this->_formats[$i]->_num_format;
711 if (!preg_match(
"/^0+\d/",$num_format))
713 if (preg_match(
"/^\d+$/",$num_format)) {
718 if (isset($hash_num_formats[$num_format])) {
720 $this->_formats[$i]->_num_format = $hash_num_formats[$num_format];
724 $hash_num_formats[$num_format] = $index;
725 $this->_formats[$i]->_num_format = $index;
726 array_push($num_formats,$num_format);
733 foreach ($num_formats as $num_format) {
750 for ($i=0; $i <= 14; $i++) {
751 $xf = $format->getXf(
'style');
755 $xf = $format->getXf(
'cell');
759 $total_formats = count($this->_formats);
760 for ($i=0; $i < $total_formats; $i++) {
761 $xf = $this->_formats[$i]->getXf(
'cell');
788 foreach ($this->_sheetnames as $sheetname) {
801 $total_worksheets = count($this->_worksheets);
802 for ($i = 0; $i < $total_worksheets; $i++) {
804 if (isset($this->_worksheets[$i]->print_rowmin))
807 $this->_worksheets[$i]->index,
809 $this->_worksheets[$i]->print_rowmin,
810 $this->_worksheets[$i]->print_rowmax,
811 $this->_worksheets[$i]->print_colmin,
812 $this->_worksheets[$i]->print_colmax
818 $total_worksheets = count($this->_worksheets);
819 for ($i = 0; $i < $total_worksheets; $i++) {
820 $rowmin = $this->_worksheets[$i]->title_rowmin;
821 $rowmax = $this->_worksheets[$i]->title_rowmax;
822 $colmin = $this->_worksheets[$i]->title_colmin;
823 $colmax = $this->_worksheets[$i]->title_colmax;
828 if (isset($rowmin) and isset($colmin)) {
832 $this->_worksheets[$i]->index,
840 elseif (isset($rowmin)) {
843 $this->_worksheets[$i]->index,
851 elseif (isset($colmin)) {
854 $this->_worksheets[$i]->index,
888 $header = pack(
'vv', $record, $length);
889 $data = pack(
'v', $cv);
916 $header = pack(
"vv", $record, $length);
917 $data = pack(
"vvvvvvvvv", $xWn, $yWn, $dxWn, $dyWn,
919 $itabCur, $itabFirst,
920 $ctabsel, $wTabRatio);
935 if ($this->_BIFF_version == 0x0600) {
936 $length = 0x08 + strlen($sheetname);
939 $length = 0x07 + strlen($sheetname);
943 $cch = strlen($sheetname);
945 $header = pack(
"vv", $record, $length);
946 if ($this->_BIFF_version == 0x0600) {
947 $data = pack(
"Vvv", $offset, $grbit, $cch);
950 $data = pack(
"VvC", $offset, $grbit, $cch);
952 $this->
_append($header.$data.$sheetname);
965 $header = pack(
"vv", $record, $length);
966 $data = pack(
"vv", count($this->_worksheets), 0x0104);
979 $total_references = count($this->_parser->_references);
981 $length = 2 + 6 * $total_references;
984 $header = pack(
"vv", $record, $length);
985 $data = pack(
'v', $total_references);
986 for ($i = 0; $i < $total_references; $i++) {
987 $data .= $this->_parser->_references[$i];
1006 $header = pack(
"vv", $record, $length);
1007 $data = pack(
"vCC", $ixfe, $BuiltIn, $iLevel);
1008 $this->
_append($header.$data);
1023 if ($this->_BIFF_version == 0x0600) {
1024 $length = 5 + strlen($format);
1027 elseif ($this->_BIFF_version == 0x0500) {
1028 $length = 3 + strlen($format);
1031 $cch = strlen($format);
1033 $header = pack(
"vv", $record, $length);
1034 if ($this->_BIFF_version == 0x0600) {
1035 $data = pack(
"vvC", $ifmt, $cch, $encoding);
1037 elseif ($this->_BIFF_version == 0x0500) {
1038 $data = pack(
"vC", $ifmt, $cch);
1040 $this->
_append($header.$data.$format);
1055 $header = pack(
"vv", $record, $length);
1056 $data = pack(
"v", $f1904);
1057 $this->
_append($header.$data);
1079 $header = pack(
"vv", $record, $length);
1080 $data = pack(
"v", $cxals);
1081 $this->
_append($header.$data);
1098 $length = 0x02 + strlen($sheetname);
1100 $cch = strlen($sheetname);
1103 $header = pack(
"vv", $record, $length);
1104 $data = pack(
"CC", $cch, $rgch);
1105 $this->
_append($header.$data.$sheetname);
1130 $ixals = $index + 1;
1132 $cchCustMenu = 0x00;
1133 $cchDescription = 0x00;
1134 $cchHelptopic = 0x00;
1135 $cchStatustext = 0x00;
1139 $unknown04 = 0xffff-$index;
1140 $unknown05 = 0x0000;
1141 $unknown06 = 0x0000;
1142 $unknown07 = 0x1087;
1143 $unknown08 = 0x8005;
1145 $header = pack(
"vv", $record, $length);
1146 $data = pack(
"v", $grbit);
1147 $data .= pack(
"C", $chKey);
1148 $data .= pack(
"C", $cch);
1149 $data .= pack(
"v", $cce);
1150 $data .= pack(
"v", $ixals);
1151 $data .= pack(
"v", $itab);
1152 $data .= pack(
"C", $cchCustMenu);
1153 $data .= pack(
"C", $cchDescription);
1154 $data .= pack(
"C", $cchHelptopic);
1155 $data .= pack(
"C", $cchStatustext);
1156 $data .= pack(
"C", $rgch);
1157 $data .= pack(
"C", $unknown03);
1158 $data .= pack(
"v", $unknown04);
1159 $data .= pack(
"v", $unknown05);
1160 $data .= pack(
"v", $unknown06);
1161 $data .= pack(
"v", $unknown07);
1162 $data .= pack(
"v", $unknown08);
1163 $data .= pack(
"v", $index);
1164 $data .= pack(
"v", $index);
1165 $data .= pack(
"v", $rowmin);
1166 $data .= pack(
"v", $rowmax);
1167 $data .= pack(
"C", $colmin);
1168 $data .= pack(
"C", $colmax);
1169 $this->
_append($header.$data);
1195 $ixals = $index + 1;
1197 $cchCustMenu = 0x00;
1198 $cchDescription = 0x00;
1199 $cchHelptopic = 0x00;
1200 $cchStatustext = 0x00;
1204 $unknown02 = 0x002b;
1206 $unknown04 = 0xffff-$index;
1207 $unknown05 = 0x0000;
1208 $unknown06 = 0x0000;
1209 $unknown07 = 0x1087;
1210 $unknown08 = 0x8008;
1212 $header = pack(
"vv", $record, $length);
1213 $data = pack(
"v", $grbit);
1214 $data .= pack(
"C", $chKey);
1215 $data .= pack(
"C", $cch);
1216 $data .= pack(
"v", $cce);
1217 $data .= pack(
"v", $ixals);
1218 $data .= pack(
"v", $itab);
1219 $data .= pack(
"C", $cchCustMenu);
1220 $data .= pack(
"C", $cchDescription);
1221 $data .= pack(
"C", $cchHelptopic);
1222 $data .= pack(
"C", $cchStatustext);
1223 $data .= pack(
"C", $rgch);
1224 $data .= pack(
"C", $unknown01);
1225 $data .= pack(
"v", $unknown02);
1227 $data .= pack(
"C", $unknown03);
1228 $data .= pack(
"v", $unknown04);
1229 $data .= pack(
"v", $unknown05);
1230 $data .= pack(
"v", $unknown06);
1231 $data .= pack(
"v", $unknown07);
1232 $data .= pack(
"v", $unknown08);
1233 $data .= pack(
"v", $index);
1234 $data .= pack(
"v", $index);
1235 $data .= pack(
"v", 0x0000);
1236 $data .= pack(
"v", 0x3fff);
1237 $data .= pack(
"C", $colmin);
1238 $data .= pack(
"C", $colmax);
1240 $data .= pack(
"C", $unknown03);
1241 $data .= pack(
"v", $unknown04);
1242 $data .= pack(
"v", $unknown05);
1243 $data .= pack(
"v", $unknown06);
1244 $data .= pack(
"v", $unknown07);
1245 $data .= pack(
"v", $unknown08);
1246 $data .= pack(
"v", $index);
1247 $data .= pack(
"v", $index);
1248 $data .= pack(
"v", $rowmin);
1249 $data .= pack(
"v", $rowmax);
1250 $data .= pack(
"C", 0x00);
1251 $data .= pack(
"C", 0xff);
1253 $data .= pack(
"C", 0x10);
1254 $this->
_append($header.$data);
1267 $header = pack(
'vv', $record, $length);
1269 $data = pack(
'vv', $this->_country_code, $this->_country_code);
1270 $this->
_append($header.$data);
1283 $length = 2 + 4 * count($aref);
1284 $ccv = count($aref);
1288 foreach($aref as $color)
1290 foreach($color as $byte) {
1291 $data .= pack(
"C",$byte);
1295 $header = pack(
"vvv", $record, $length, $ccv);
1296 $this->
_append($header.$data);
1323 $continue_limit = 8208;
1326 $this->_block_sizes = array();
1329 foreach (array_keys($this->_str_table) as $string) {
1330 $string_length = strlen($string);
1334 $block_length += $string_length;
1337 if ($block_length < $continue_limit) {
1338 $written += $string_length;
1339 $total_offset += $string_length;
1346 while ($block_length >= $continue_limit) {
1351 $space_remaining = $continue_limit - $written - $continue;
1359 if ($space_remaining > $header_length) {
1361 $written += $space_remaining;
1364 $block_length -= $continue_limit + $continue;
1367 $this->_block_sizes[] = $continue_limit;
1372 if ($block_length > 0) {
1382 $this->_block_sizes[] = $written + $continue;
1385 $block_length -= $continue_limit - $space_remaining - $continue;
1393 if ($block_length < $continue_limit) {
1394 $written = $block_length;
1403 if ($written + $continue) {
1404 $this->_block_sizes[] = $written + $continue;
1413 if (!empty($this->_block_sizes)) {
1414 $total_offset += (count($this->_block_sizes) - 1) * 4;
1416 return $total_offset;
1434 $length = 8 + array_sum($this->_block_sizes);
1437 $header = pack(
"vv", $record, $length);
1438 $data = pack(
"VV", $this->_str_total, $this->_str_unique);
1439 $this->
_append($header.$data);
1443 $continue_limit = 8208;
1450 foreach (array_keys($this->_str_table) as $string) {
1452 $string_length = strlen($string);
1459 $block_length += $string_length;
1463 if ($block_length < $continue_limit) {
1465 $written += $string_length;
1473 while ($block_length >= $continue_limit) {
1479 $space_remaining = $continue_limit - $written - $continue;
1485 if ($space_remaining > $header_length) {
1487 $tmp = substr($string, 0, $space_remaining);
1491 $string = substr($string, $space_remaining);
1494 $block_length -= $continue_limit - $continue;
1500 if ($block_length > 0) {
1509 $block_length -= $continue_limit - $space_remaining - $continue;
1514 if (!empty($this->_block_sizes)) {
1516 $length = array_pop($this->_block_sizes);
1518 $header = pack(
'vv', $record, $length);
1520 $header .= pack(
'C', $encoding);
1529 if ($block_length < $continue_limit) {
1532 $written = $block_length;