From 425d7e44fa77d40148a4d377f035ee18de548cca Mon Sep 17 00:00:00 2001 From: Carsten Goetzinger Date: Fri, 27 Jan 2017 13:04:38 +0100 Subject: [PATCH 1/2] Umzug zu gitlab --- README.md | 3 + composer.json | 38 ++ config/autoload.ini | 7 + config/autoload.php | 28 + vendor/biff.php | 322 +++++++++ vendor/fat.php | 53 ++ vendor/font.php | 117 ++++ vendor/mergedcells.php | 34 + vendor/palette.php | 294 +++++++++ vendor/picture.php | 230 +++++++ vendor/xf.php | 238 +++++++ vendor/xls_export.php | 1414 ++++++++++++++++++++++++++++++++++++++++ 12 files changed, 2778 insertions(+) create mode 100644 README.md create mode 100644 composer.json create mode 100644 config/autoload.ini create mode 100644 config/autoload.php create mode 100644 vendor/biff.php create mode 100644 vendor/fat.php create mode 100644 vendor/font.php create mode 100644 vendor/mergedcells.php create mode 100644 vendor/palette.php create mode 100644 vendor/picture.php create mode 100644 vendor/xf.php create mode 100644 vendor/xls_export.php diff --git a/README.md b/README.md new file mode 100644 index 0000000..394cba4 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# xls_export # + +Fork der Erweiterung xls_export aus dem Contao Extension Repository (https://contao.org/de/extension-list/view/xls_export.de.html). Der Fork wurde erzeugt, um die Erweiterung im Composer veröffentlichen zu können. \ No newline at end of file diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..973ce3d --- /dev/null +++ b/composer.json @@ -0,0 +1,38 @@ +{ + "name":"cgo-it/xls_export", + "description":"xls_export extension for the Contao Open Source CMS", + "keywords":["contao", "excel"], + "type":"contao-module", + "license":"GPL", + "authors":[ + { + "name":"cgo IT", + "email":"info@cgo-it.de", + "homepage":"https://cgo-it.de", + "role":"Developer" + } + ], + "support": { + "email": "info@cgo-it.de", + "issues": "https://bitbucket.org/cgo-it/contao-xls_export/issues?status=new&status=open", + "source": "https://bitbucket.org/cgo-it/contao-xls_export/src" + }, + "require":{ + "php":">=5.3", + "contao/core":">=3.0", + "contao-community-alliance/composer-plugin": "~2.0" + }, + "replace": { + "cgo-it/xls_export": "self.version" + }, + "conflict": { + "contao/core": "2.11.*" + }, + "extra":{ + "contao": { + "sources":{ + "":"system/modules/xls_export" + } + } + } +} \ No newline at end of file diff --git a/config/autoload.ini b/config/autoload.ini new file mode 100644 index 0000000..56a51b1 --- /dev/null +++ b/config/autoload.ini @@ -0,0 +1,7 @@ + +;; +; Configure what you want the autoload creator to register +;; +register_namespaces = true +register_classes = true +register_templates = true diff --git a/config/autoload.php b/config/autoload.php new file mode 100644 index 0000000..f64204a --- /dev/null +++ b/config/autoload.php @@ -0,0 +1,28 @@ + 'system/modules/xls_export/vendor/biff.php', + 'fat_class' => 'system/modules/xls_export/vendor/fat.php', + 'xls_font' => 'system/modules/xls_export/vendor/font.php', + 'xls_mergedcells' => 'system/modules/xls_export/vendor/mergedcells.php', + 'xls_palette' => 'system/modules/xls_export/vendor/palette.php', + 'xls_picture' => 'system/modules/xls_export/vendor/picture.php', + 'xls_xf' => 'system/modules/xls_export/vendor/xf.php', + 'xlsexport' => 'system/modules/xls_export/vendor/xls_export.php', +)); diff --git a/vendor/biff.php b/vendor/biff.php new file mode 100644 index 0000000..0d634af --- /dev/null +++ b/vendor/biff.php @@ -0,0 +1,322 @@ +data = array(); + $this->type = $aboftype; + } + + public function append($adatatype, $adatarec) { + $new = array(); + $new["type"] = $adatatype; + $new["data"] = $adatarec; + $this->data[] = $new; + } + + public function clear($aboftype=-1) { + if ($aboftype==-1) { die("Error"); } + $this->type = $aboftype; + $this->data = array(); + return true; + } + + public function fetch() { + $output = ""; + foreach ($this->data as $key => $datarec) { + switch ($datarec["type"]) { + case XLSDATA_BYTE : $output .= pack("C",$datarec["data"]); + $this->size+=1; + break; + + case XLSDATA_SHORT: $output .= pack("v",$datarec["data"]); + $this->size+=2; + break; + + case XLSDATA_LONG : $output .= pack("V",$datarec["data"]); + $this->size+=4; + break; + + case XLSDATA_FLOAT: $output .= pack("d",$datarec["data"]); + $this->size+=8; + break; + + case XLSDATA_DATA32BIT : + $ldata = $datarec["data"]; + $b3 = $ldata & 0xff; + $b2 = ($ldata >> 8) & 0xff; + $b1 = ($ldata >> 16) & 0xff; + $b0 = ($ldata >> 24) & 0xff; + $output .= pack("CCCC",$b0,$b1,$b2,$b3); + $this->size+=4; + break; + + case XLSDATA_STRING: + $output .= pack("C",strlen($datarec["data"])); + $this->size++; + if (strlen($datarec["data"])==0) { + $output .= pack("C",0x00); + $this->size++; + break; + } + + case XLSDATA_STRING1: + $this->size+=strlen($datarec["data"]); + //$output .= pack("C",$datarec["data"]); + $output .= $datarec["data"]; + break; + case XLSDATA_LSTRING: + $output .= pack("v",strlen($datarec["data"])); + $this->size++; + $this->size++; + $this->size+=strlen($datarec["data"]); + //$output .= pack("C",$datarec["data"]); + $output .= $datarec["data"]; + break; + } + } + return pack("vv",$this->bof,$this->size).$output; + } + + public function save($afilehd) { + $this->bof = $this->type; + $this->size = 0; + $tmp = $this->fetch(); + if ($this->size<2080) { + fwrite($afilehd,$tmp); + } + else { + if (defined("BIFFDEBUG")) { + echo "long record - size : ".$this->size."
"; + } + $wcount = $this->size; + $tmptype = $this->type; + $tmp = substr($tmp,4); + $tmparr = str_split($tmp,2076); + if (defined("BIFFDEBUG")) { + echo "create parts : ".count($tmparr)."
"; + } + $tmpout = ""; + foreach ($tmparr as $key => $datapart) { + if (defined("BIFFDEBUG")) { + echo "part ($key) size : ".strlen($datapart)."
"; + } + $tmpout = pack("vv",$tmptype,strlen($datapart)).$datapart; + fwrite($afilehd,$tmpout); + $tmptype = BIFF_CONTINUE; + } + unset($tmparr); + } + return true; + } + + public function workbookxfrecords($afilehd) { + $this->workbookonexfdata($afilehd,0x0000,0x0000,0xfff5,0x00,0x000020c0); + $this->workbookonexfdata($afilehd,0x0001,0x0000,0xfff5,0xf4,0x000020c0); + $this->workbookonexfdata($afilehd,0x0001,0x0000,0xfff5,0xf4,0x000020c0); + $this->workbookonexfdata($afilehd,0x0002,0x0000,0xfff5,0xf4,0x000020c0); + $this->workbookonexfdata($afilehd,0x0002,0x0000,0xfff5,0xf4,0x000020c0); + $this->workbookonexfdata($afilehd,0x0000,0x0000,0xfff5,0xf4,0x000020c0); + $this->workbookonexfdata($afilehd,0x0000,0x0000,0xfff5,0xf4,0x000020c0); + $this->workbookonexfdata($afilehd,0x0000,0x0000,0xfff5,0xf4,0x000020c0); + $this->workbookonexfdata($afilehd,0x0000,0x0000,0xfff5,0xf4,0x000020c0); + $this->workbookonexfdata($afilehd,0x0000,0x0000,0xfff5,0xf4,0x000020c0); + $this->workbookonexfdata($afilehd,0x0000,0x0000,0xfff5,0xf4,0x000020c0); + $this->workbookonexfdata($afilehd,0x0000,0x0000,0xfff5,0xf4,0x000020c0); + $this->workbookonexfdata($afilehd,0x0000,0x0000,0xfff5,0xf4,0x000020c0); + $this->workbookonexfdata($afilehd,0x0000,0x0000,0xfff5,0xf4,0x000020c0); + $this->workbookonexfdata($afilehd,0x0000,0x0000,0xfff5,0xf4,0x000020c0); + $this->workbookonexfdata($afilehd,0x0000,0x0000,0x0001,0x00,0x000020c0); + $this->workbookonexfdata($afilehd,0x0001,0x002b,0xfff5,0xf8,0x000020c0); + $this->workbookonexfdata($afilehd,0x0001,0x0029,0xfff5,0xf8,0x000020c0); + $this->workbookonexfdata($afilehd,0x0001,0x002c,0xfff5,0xf8,0x000020c0); + $this->workbookonexfdata($afilehd,0x0001,0x002a,0xfff5,0xf8,0x000020c0); + $this->workbookonexfdata($afilehd,0x0001,0x0009,0xfff5,0xf8,0x000020c0); + $this->workbookonexfdata($afilehd,0x0000,0x0000,0x0001,0x10,0x000020c0); + $this->workbookonexfdata($afilehd,0x0000,0x0000,0x0001,0x50,0x00000488); + } + + public function workbookonexfdata($afilehd, $fontindex, $formatindex, $xftype, $textorientation, $colorindexs) { + $this->clear(BIFF_XFRECORD); + $this->append(XLSDATA_SHORT,$fontindex); + $this->append(XLSDATA_SHORT,$formatindex); + $this->append(XLSDATA_SHORT,$xftype); + $this->append(XLSDATA_BYTE,0x20); /* alignment + bits mask + 2-0 07H XF_HOR_ALIGN ? Horizontal alignment + 0 General + 1 Left + 2 Centred + 3 Right + 4 Filled + 5 Justified (BIFF4-BIFF8) + 6 Centred across selection (BIFF4-BIFF8) + 7 Distributed (BIFF8, available in Excel 10.0 (Excel XP) and later only) + 3 08H 1 = Text is wrapped at right border + 6-4 70H XF_VERT_ALIGN ? Vertical alignment + 0 Top + 1 Centred + 2 Bottom + 3 Justified (BIFF5-BIFF8) + 4 Distributed (BIFF8, available in Excel 10.0 (Excel XP) and later only) + */ + $this->append(XLSDATA_BYTE,$textorientation); /* + bits mask + 1-0 03H XF_ORIENTATION ? Text orientation + 0 Not rotated + 1 Letters are stacked top-to-bottom, but not rotated + 2 Text is rotated 90 degrees counterclockwise + 3 Text is rotated 90 degrees clockwise + 7-2 FCH XF_USED_ATTRIB ? Used attributes + 0 01H Flag for number format + 1 02H Flag for font + 2 04H Flag for horizontal and vertical alignment, text wrap, indentation, orientation, rotation, and text direction + 3 08H Flag for border lines + 4 10H Flag for background area style + 5 20H Flag for cell protection (cell locked and formula hidden) + */ + $this->append(XLSDATA_LONG,$colorindexs); /* Cell border lines and background area: + Bit Mask Contents + 6-0 0000007FH Colour index for pattern colour + 13-7 00003F80H Colour index for pattern background + 21-16 003F0000H Fill pattern + 24-22 01C00000H Bottom line style + 31-25 FE000000H Colour index for bottom line colour + */ + $this->append(XLSDATA_LONG,0); /* Line styles + Bit Mask Contents + 2-0 00000007H Top line style + 5-3 00000038H Left line style + 8-6 000001C0H Right line style + 15-9 0000FE00H Colour index for top line colour + 22-16 007F0000H Colour index for left line colour + 29-23 3F800000H Colour index for right line colour + */ + $this->save($afilehd); + } + + } +?> \ No newline at end of file diff --git a/vendor/fat.php b/vendor/fat.php new file mode 100644 index 0000000..c25f358 --- /dev/null +++ b/vendor/fat.php @@ -0,0 +1,53 @@ +streamsize = $astreamsize; + $this->rootstorageoffset = $arootstorageoffset; + + if ($this->streamsize>=0x1000) { + $streamsectors = $this->streamsize >> 9; + $streamsectors += (($this->streamsize & 0x1ff)>0 ? 1 : 0); + } + else { + $streamsectors = ($this->rootstorageoffset+0x100) >> 9; + $streamsectors += ((($this->rootstorageoffset+0x100) & 0x1ff)>0 ? 1 : 0); + $streamsectors--; + } + while ($streamsectors>1) { + $this->fatchain[] = count($this->fatchain)+1; // allocate next sector; + $streamsectors--; + } + $this->fatchain[] = 0xfffffffe; // last sector of stream + if ($this->streamsize>=0x1000) { + $this->fatchain[] = 0xfffffffe; // rootstorage , used one sector + } + $this->fatchain[] = 0xfffffffe; // minifat , used one sector + $this->fatchain[] = 0xfffffffe; // directory , used one sector + + $fatsize1 = (count($this->fatchain) >> 7) + (((count($this->fatchain) & 0x7f)>0) ? 1 : 0); + $fatsize0 = $fatsize1; + while ($fatsize1) { + $this->fatchain[] = 0xfffffffd; // fat , used nn sector + $fatsize1--; + } + $this->fatsectorcount = (count($this->fatchain) >> 7)+(((count($this->fatchain) & 0x7f)>0) ? 1 : 0); + if ($this->fatsectorcount!=$fatsize0) { $this->fatchain[] = 0xfffffffd; } + $reqbytes = 128-(count($this->fatchain) & 0x7f); + $fatfill = array_fill(count($this->fatchain),$reqbytes,0xffffffff); + $this->fatchain = array_merge($this->fatchain,$fatfill); + + $output = ""; + $count = 0; + foreach ($this->fatchain as $key => $sectorid) { + $output .= pack("V",$sectorid); + $count += 4; + } + fwrite($afilehd,$output,$count); + } + } +?> \ No newline at end of file diff --git a/vendor/font.php b/vendor/font.php new file mode 100644 index 0000000..d3c1e22 --- /dev/null +++ b/vendor/font.php @@ -0,0 +1,117 @@ +font_array = array(); + $this->append(null); + } + + public function append($params) { + $font["name"] = (isset($params["name"]) ? $params["name"] : XLSFILE_DEFAULT_FONTNAME); + $font["height"] = (isset($params["height"]) ? $params["height"]*20 : XLSFILE_DEFAULT_FONTHEIGHT); + $font["weight"] = (isset($params["weight"]) ? $params["weight"] : XLSFONT_NORMAL); + $font["color"] = (isset($params["color"]) ? $params["color"] : XLSFILE_DEFAULT_FGCOLOR); + $font["underline"] = (isset($params["underline"]) ? $params["underline"] : XLSFONT_UNDERLINE_NONE); + $font["escapement"] = (isset($params["escapement"]) ? $params["escapement"] : XLSFONT_ESCAPE_NONE); + $font["family"] = (isset($params["family"]) ? $params["family"] : XLSFONT_FAMILY_NORMAL); + $font["style"] = (isset($params["style"]) ? $params["style"] : 0x0000); + $font["characterset"] = XLSFILE_CHARACTERSET; + $s = serialize($font); + unset($font); + $fontidx = array_search($s,$this->font_array); + if ($fontidx===false) { + $this->font_array[] = $s; + $fontidx = array_search($s,$this->font_array); + } + if ($fontidx>0) { + $fontidx += 5; // first 5 reserved, +5 for user defined font + } + $fontidx += (($fontidx==4) ? 1 : 0); + return $fontidx; + } + + public function save($filehandle,$xls_biffobject) { + $font0 = unserialize($this->font_array[0]); + $xls_biffobject->clear(BIFF_FONT); + $xls_biffobject->append(XLSDATA_SHORT,$font0["height"]); + $xls_biffobject->append(XLSDATA_SHORT,$font0["style"]); + $xls_biffobject->append(XLSDATA_SHORT,$font0["color"]); + $xls_biffobject->append(XLSDATA_SHORT,$font0["weight"]); + $xls_biffobject->append(XLSDATA_SHORT,$font0["escapement"]); + $xls_biffobject->append(XLSDATA_BYTE,$font0["underline"]); + $xls_biffobject->append(XLSDATA_BYTE,$font0["family"]); + $xls_biffobject->append(XLSDATA_BYTE,$font0["characterset"]); + $xls_biffobject->append(XLSDATA_BYTE,0x0000); + $xls_biffobject->append(XLSDATA_STRING,$font0["name"]); + $repeatdefault = 4; + while ($repeatdefault>0) { + $xls_biffobject->save($filehandle); + $repeatdefault--; + } + $i=0; + while ($i!=count($this->font_array)) { + $font0 = unserialize($this->font_array[$i]); + $xls_biffobject->clear(BIFF_FONT); + $xls_biffobject->append(XLSDATA_SHORT,$font0["height"]); + $xls_biffobject->append(XLSDATA_SHORT,$font0["style"]); + $xls_biffobject->append(XLSDATA_SHORT,$font0["color"]); + $xls_biffobject->append(XLSDATA_SHORT,$font0["weight"]); + $xls_biffobject->append(XLSDATA_SHORT,$font0["escapement"]); + $xls_biffobject->append(XLSDATA_BYTE,$font0["underline"]); + $xls_biffobject->append(XLSDATA_BYTE,$font0["family"]); + $xls_biffobject->append(XLSDATA_BYTE,$font0["characterset"]); + $xls_biffobject->append(XLSDATA_BYTE,0x0000); + $xls_biffobject->append(XLSDATA_STRING,$font0["name"]); + $xls_biffobject->save($filehandle); + $i++; + } + } + } +?> \ No newline at end of file diff --git a/vendor/mergedcells.php b/vendor/mergedcells.php new file mode 100644 index 0000000..c4c94bc --- /dev/null +++ b/vendor/mergedcells.php @@ -0,0 +1,34 @@ +merged_array=array(); + } + + public function merge_cells($arowfirst, $arowlast, $acolfirst, $acollast) { + $this->merged_array[]=array("rowfirst" => $arowfirst, "rowlast" => $arowlast, "colfirst" => $acolfirst, "collast" => $acollast); + } + + public function findpos($arow,$acol) { + foreach ($this->merged_array as $key => $data) { + if ((($arow>=$data["rowfirst"]) && ($arow<=$data["rowlast"])) && (($acol>=$data["colfirst"]) && ($acol<=$data["collast"]))) { + return array("row" => $data["rowfirst"],"col" => $data["colfirst"]); + } + } + return false; + } + + public function save($filehandle,$xls_biffobject) { + $xls_biffobject->clear(BIFF_MERGEDCELLS); + $xls_biffobject->append(XLSDATA_SHORT,count($this->merged_array)); + foreach ($this->merged_array as $key => $data) { + $xls_biffobject->append(XLSDATA_SHORT,$data["rowfirst"]); + $xls_biffobject->append(XLSDATA_SHORT,$data["rowlast"]); + $xls_biffobject->append(XLSDATA_SHORT,$data["colfirst"]); + $xls_biffobject->append(XLSDATA_SHORT,$data["collast"]); + } + $xls_biffobject->save($filehandle); + } + } +?> \ No newline at end of file diff --git a/vendor/palette.php b/vendor/palette.php new file mode 100644 index 0000000..9a1a7f5 --- /dev/null +++ b/vendor/palette.php @@ -0,0 +1,294 @@ + "#f0f8ff", + "antiquewhite" => "#faebd7", + "aqua" => "#00ffff", + "aquamarine" => "#7fffd4", + "azure" => "#f0ffff", + "beige" => "#f5f5dc", + "bisque" => "#ffe4c4", + "black" => "#000000", + "blanchedalmond" => "#ffebcd", + "blue" => "#0000ff", + "blueviolet" => "#8a2be2", + "brown" => "#a52a2a", + "burlywood" => "#deb887", + "cadetblue" => "#5f9ea0", + "chartreuse" => "#7fff00", + "chocolate" => "#d2691e", + "coral" => "#ff7f50", + "cornflowerblue" => "#6495ed", + "cornsilk" => "#fff8dc", + "crimson" => "#dc143c", + "cyan" => "#00ffff", + "darkblue" => "#00008b", + "darkcyan" => "#008b8b", + "darkgoldenrod" => "#b8860b", + "darkgray" => "#a9a9a9", + "darkgrey" => "#a9a9a9", + "darkgreen" => "#006400", + "darkkhaki" => "#bdb76b", + "darkmagenta" => "#8b008b", + "darkolivegreen" => "#556b2f", + "darkorange" => "#ff8c00", + "darkorchid" => "#9932cc", + "darkred" => "#8b0000", + "darksalmon" => "#e9967a", + "darkseagreen" => "#8fbc8f", + "darkslateblue" => "#483d8b", + "darkslategray" => "#2f4f4f", + "darkslategrey" => "#2f4f4f", + "darkturquoise" => "#00ced1", + "darkviolet" => "#9400d3", + "deeppink" => "#ff1493", + "deepskyblue" => "#00bfff", + "dimgray" => "#696969", + "dimgrey" => "#696969", + "dodgerblue" => "#1e90ff", + "firebrick" => "#b22222", + "floralwhite" => "#fffaf0", + "forestgreen" => "#228b22", + "fuchsia" => "#ff00ff", + "gainsboro" => "#dcdcdc", + "ghostwhite" => "#f8f8ff", + "gold" => "#ffd700", + "goldenrod" => "#daa520", + "gray" => "#808080", + "grey" => "#808080", + "green" => "#008000", + "greenyellow" => "#adff2f", + "honeydew" => "#f0fff0", + "hotpink" => "#ff69b4", + "indianred" => "#cd5c5c", + "indigo" => "#4b0082", + "ivory" => "#fffff0", + "khaki" => "#f0e68c", + "lavender" => "#e6e6fa", + "lavenderblush" => "#fff0f5", + "lawngreen" => "#7cfc00", + "lemonchiffon" => "#fffacd", + "lightblue" => "#add8e6", + "lightcoral" => "#f08080", + "lightcyan" => "#e0ffff", + "lightgoldenrodyellow" => "#fafad2", + "lightgray" => "#d3d3d3", + "lightgrey" => "#d3d3d3", + "lightgreen" => "#90ee90", + "lightpink" => "#ffb6c1", + "lightsalmon" => "#ffa07a", + "lightseagreen" => "#20b2aa", + "lightskyblue" => "#87cefa", + "lightslategray" => "#778899", + "lightslategrey" => "#778899", + "lightsteelblue" => "#b0c4de", + "lightyellow" => "#ffffe0", + "lime" => "#00ff00", + "limegreen" => "#32cd32", + "linen" => "#faf0e6", + "magenta" => "#ff00ff", + "maroon" => "#800000", + "mediumaquamarine" => "#66cdaa", + "mediumblue" => "#0000cd", + "mediumorchid" => "#ba55d3", + "mediumpurple" => "#9370d8", + "mediumseagreen" => "#3cb371", + "mediumslateblue" => "#7b68ee", + "mediumspringgreen" => "#00fa9a", + "mediumturquoise" => "#48d1cc", + "mediumvioletred" => "#c71585", + "midnightblue" => "#191970", + "mintcream" => "#f5fffa", + "mistyrose" => "#ffe4e1", + "moccasin" => "#ffe4b5", + "navajowhite" => "#ffdead", + "navy" => "#000080", + "oldlace" => "#fdf5e6", + "olive" => "#808000", + "olivedrab" => "#6b8e23", + "orange" => "#ffa500", + "orangered" => "#ff4500", + "orchid" => "#da70d6", + "palegoldenrod" => "#eee8aa", + "palegreen" => "#98fb98", + "paleturquoise" => "#afeeee", + "palevioletred" => "#d87093", + "papayawhip" => "#ffefd5", + "peachpuff" => "#ffdab9", + "peru" => "#cd853f", + "pink" => "#ffc0cb", + "plum" => "#dda0dd", + "powderblue" => "#b0e0e6", + "purple" => "#800080", + "red" => "#ff0000", + "rosybrown" => "#bc8f8f", + "royalblue" => "#4169e1", + "saddlebrown" => "#8b4513", + "salmon" => "#fa8072", + "sandybrown" => "#f4a460", + "seagreen" => "#2e8b57", + "seashell" => "#fff5ee", + "sienna" => "#a0522d", + "silver" => "#c0c0c0", + "skyblue" => "#87ceeb", + "slateblue" => "#6a5acd", + "slategray" => "#708090", + "slategrey" => "#708090", + "snow" => "#fffafa", + "springgreen" => "#00ff7f", + "steelblue" => "#4682b4", + "tan" => "#d2b48c", + "teal" => "#008080", + "thistle" => "#d8bfd8", + "tomato" => "#ff6347", + "turquoise" => "#40e0d0", + "violet" => "#ee82ee", + "wheat" => "#f5deb3", + "white" => "#ffffff", + "whitesmoke" => "#f5f5f5", + "yellow" => "#ffff00", + "yellowgreen" => "#9acd32"); + + var $palette_array = array( 0x000000, + 0xffffff, + 0xff0000, + 0x00ff00, + 0x0000ff, + 0xffff00, + 0xff00ff, + 0x00ffff, + 0x800000, + 0x008000, + 0x000080, + 0x808000, + 0x800080, + 0x008080, + 0xc0c0c0, + 0x808080, + 0x9999ff, + 0x993366, + 0xffffcc, + 0xccffff, + 0x660066, + 0xff8080, + 0x0066cc, + 0xccccff, + 0x000080, + 0xff00ff, + 0xffff00, + 0x00ffff, + 0x800080, + 0x800000, + 0x008080, + 0x0000ff, + 0x00ccff, + 0xccffff, + 0xccffcc, + 0xffff99, + 0x99ccff, + 0xff99cc, + 0xcc99ff, + 0xffcc99, + 0x3366ff, + 0x33cccc, + 0x99cc00, + 0xffcc00, + 0xff9900, + 0xff6600, + 0x666699, + 0x969696, + 0x003366, + 0x339966, + 0x003300, + 0x333300, + 0x993300, + 0x993366, + 0x333399, + 0xc7c7c7 + ); + public function getcoloridx($acolor) { + if (is_array($acolor)) { + $red = $acolor["red"]; + $green = $acolor["green"]; + $blue = $acolor["blue"]; + return $this->findcolor($red,$green,$blue); + } + else if (!is_numeric($acolor)) { + if ($acolor{0}=="#") { + return $this->findhtmlcolor($acolor); + } + else { + return $this->findnamedcolor($acolor); + } + } + else { + $red = ($acolor & 0x00ff0000) >> 16; + $green = ($acolor & 0x0000ff00) >> 8; + $blue = ($acolor & 0x000000ff); + return $this->findcolor($red,$green,$blue); + } + } + + public function findnamedcolor($colorname) { + if (!isset($this->htmlcolorarray[strtolower($colorname)])) { die("unknown color name."); } + return $this->findhtmlcolor($this->htmlcolorarray[strtolower($colorname)]); + } + + public function findhtmlcolor($htmlcolor) { + $red = hexdec(substr($htmlcolor,1,2)); + $green = hexdec(substr($htmlcolor,3,2)); + $blue = hexdec(substr($htmlcolor,5,2)); + return $this->findcolor($red,$green,$blue); + } + + public function findcolor($ared,$agreen,$ablue) { + $rgbval = 0; + $rgbval = ($ared<<16) | ($agreen << 8) | ($ablue << 0); + // before allocate, check the color in the array + // if found, return colorindex + $colorindex = array_search($rgbval,$this->palette_array); + if ($colorindex===false) { + return $colorindex; + //$colorindex = count($this->palette_array); + //$this->palette_array[] = $rgbval; + } + $colorindex += 8; + return $colorindex; + } + + public function change_color($idx,$color) { + $oldidx = $this->getcoloridx($color); + if ($oldidx!==false) { return $oldidx; } + if (is_array($color)) { + $red = $acolor["red"]; + $green = $acolor["green"]; + $blue = $acolor["blue"]; + $rgbval = ($red<<16) | ($green << 8) | ($blue << 0); + $this->palette_array[$idx-8] = $rgbval; + } + else if (!is_numeric($color)) { + if ($color{0}=="#") { + $rgbval = hexdec(substr($color,1)); + $this->palette_array[$idx-8] = $rgbval; + } + else { + if (!isset($this->htmlcolorarray[strtolower($color)])) { die("unknown color name."); } + $this->palette_array[$idx-8] = hexdec(substr($this->htmlcolorarray[strtolower($color)],1)); + } + } + else { + $this->palette_array[$idx-8] = $color; + } + return $idx; + } + + public function save($filehandle,$xls_biffobject) { + $xls_biffobject->clear(BIFF_PALETTE); + $xls_biffobject->append(XLSDATA_SHORT,count($this->palette_array)); + foreach ($this->palette_array as $key => $color_data) { + $tmp = $color_data<<8; + $xls_biffobject->append(XLSDATA_DATA32BIT,$tmp); + } + $xls_biffobject->save($filehandle); + } + } +?> \ No newline at end of file diff --git a/vendor/picture.php b/vendor/picture.php new file mode 100644 index 0000000..45cb7b1 --- /dev/null +++ b/vendor/picture.php @@ -0,0 +1,230 @@ +picture_array = array(); + $this->filename = $afilename; + + $tmp = explode(".",$afilename); + if (count($tmp)<2) { die("missing filename extension."); } + if (!file_exists($afilename)) { die("file does not exist."); } + + $this->bgcolor = $abgcolor; + $this->bgcolorrgb = $abgcolorrgb; + $this->fgcolor = $afgcolor; + $this->objectid = $aobjectid; + $this->firstrow = $arow; + $this->firstcol = $acol; + } + + function scanimgline($imagehd, $line, $width, $bgcolor) { + for ($x=0; $x!=$width; $x++) { + $colorindex = imagecolorat($imagehd, $x, $line); + $rgb = imagecolorsforindex($imagehd, $colorindex); + if ($rgb["alpha"]!=0) { + $dstR = $bgcolor >> 16 & 0xFF; + $dstG = $bgcolor >> 8 & 0xFF; + $dstB = $bgcolor & 0xFF; + + $rgb["red"] = (($rgb["red"] * (0xFF-$rgb["alpha"])) >> 8) + (($dstR * $rgb["alpha"]) >> 8); + $rgb["green"] = (($rgb["green"] * (0xFF-$rgb["alpha"])) >> 8) + (($dstG * $rgb["alpha"]) >> 8); + $rgb["blue"] = (($rgb["blue"] * (0xFF-$rgb["alpha"])) >> 8) + (($dstB * $rgb["alpha"]) >> 8); + } + $this->picture_array[] = $rgb["blue"]; + $this->picture_array[] = $rgb["green"]; + $this->picture_array[] = $rgb["red"]; + /* + $this->picture_array[] = ($colorindex >> 16) & 0x0ff; + $this->picture_array[] = ($colorindex >> 8) & 0x0ff; + $this->picture_array[] = $colorindex & 0x0ff; + */ + } + if ((count($this->picture_array) & 0x3)!=0) { + $fsize = count($this->picture_array) & 0x3; + $reqbytes = 0x4 - $fsize; + while ($reqbytes>0) { + $this->picture_array[] = 0; + } + } + } + + function loaddata() { + $tmp = explode(".",$this->filename); + $ext = strtolower($tmp[count($tmp)-1]); + switch ($ext) { + case "bmp" : die("Windows BitMaP file not supported."); + break; + case "gif" : $img=imagecreatefromgif($this->filename); + break; + case "jpg" : + case "jpeg" : $img=imagecreatefromjpeg($this->filename); + break; + case "png" : $img=imagecreatefrompng($this->filename); + break; + case "xbm" : $img=imagecreatefromxbm($this->filename); + break; + case "xpm" : $img=imagecreatefromxpm($this->filename); + break; + default : die("Invalid / unknown filetype (extension)."); + break; + } + $this->imagewidth = imagesx($img); + $this->imageheight = imagesy($img); + $y=$this->imageheight; + while ($y>0) { + $y--; + $this->scanimgline($img, $y, $this->imagewidth, $this->bgcolorrgb); + } + imagedestroy($img); + } + + function save($filehandle,$xls_biffobject) { + $xls_biffobject->clear(BIFF_OBJECT); + $xls_biffobject->append(XLSDATA_LONG,1); // one object + $xls_biffobject->append(XLSDATA_SHORT,8); // obj,type = picture + $xls_biffobject->append(XLSDATA_SHORT,$this->objectid); + $xls_biffobject->append(XLSDATA_SHORT,0x0614); + $xls_biffobject->append(XLSDATA_SHORT,$this->firstcol); + $xls_biffobject->append(XLSDATA_SHORT,0); + $xls_biffobject->append(XLSDATA_SHORT,$this->firstrow); + $xls_biffobject->append(XLSDATA_SHORT,0); + $xls_biffobject->append(XLSDATA_SHORT,$this->lastcol); + $xls_biffobject->append(XLSDATA_SHORT,$this->imageright); + $xls_biffobject->append(XLSDATA_SHORT,$this->lastrow); + $xls_biffobject->append(XLSDATA_SHORT,$this->imagebottom); + $xls_biffobject->append(XLSDATA_SHORT,0); + + $xls_biffobject->append(XLSDATA_SHORT,0); + $xls_biffobject->append(XLSDATA_SHORT,0x0005); + $xls_biffobject->append(XLSDATA_SHORT,0); + + $xls_biffobject->append(XLSDATA_BYTE,$this->bgcolor); + $xls_biffobject->append(XLSDATA_BYTE,$this->fgcolor); + $xls_biffobject->append(XLSDATA_BYTE,0); + $xls_biffobject->append(XLSDATA_BYTE,0); + $xls_biffobject->append(XLSDATA_BYTE,8); + $xls_biffobject->append(XLSDATA_BYTE,0xff); + $xls_biffobject->append(XLSDATA_BYTE,1); + $xls_biffobject->append(XLSDATA_BYTE,0); + $xls_biffobject->append(XLSDATA_SHORT,0); + $xls_biffobject->append(XLSDATA_SHORT,0x0009); + //$xls_biffobject->append(XLSDATA_LONG,0x370510b9); + $xls_biffobject->append(XLSDATA_LONG,0x00000000); + $xls_biffobject->append(XLSDATA_SHORT,0); + $xls_biffobject->append(XLSDATA_SHORT,0); + $xls_biffobject->append(XLSDATA_SHORT,0x0001); + $xls_biffobject->append(XLSDATA_LONG,0x0000); + + $s = "Picture".$this->objectid; + $xls_biffobject->append(XLSDATA_STRING,$s); + $xls_biffobject->save($filehandle); + + $xls_biffobject->clear(BIFF_IMAGEDATA); + $xls_biffobject->append(XLSDATA_SHORT,0x0009); + $xls_biffobject->append(XLSDATA_SHORT,0x0001); + $xls_biffobject->append(XLSDATA_LONG,count($this->picture_array)+12); + + if (defined("PICTUREDEBUG")) { + echo "picture size : ".count($this->picture_array)." (".dechex(count($this->picture_array)).")
\n"; + } + $xls_biffobject->append(XLSDATA_LONG,0x0000000c); + $xls_biffobject->append(XLSDATA_SHORT,$this->imagewidth); + $xls_biffobject->append(XLSDATA_SHORT,$this->imageheight); + $xls_biffobject->append(XLSDATA_SHORT,1); + $xls_biffobject->append(XLSDATA_SHORT,24); + + foreach ($this->picture_array as $data) { + $xls_biffobject->append(XLSDATA_BYTE,$data); + } + $xls_biffobject->save($filehandle); + } + } +?> \ No newline at end of file diff --git a/vendor/xf.php b/vendor/xf.php new file mode 100644 index 0000000..6b331d1 --- /dev/null +++ b/vendor/xf.php @@ -0,0 +1,238 @@ +xf_array = array(); + $this->append(array("forced"=>1, "parentxfindex" => 0xffffff, "xftype" => XLSXF_TYPE_PROT_STYLEXF)); + $this->append(array("forced"=>1, "parentxfindex" => 0xffffff, "xftype" => XLSXF_TYPE_PROT_STYLEXF, "flagsforce" => 0xf4, "fontindex" => 1)); + $this->append(array("forced"=>1, "parentxfindex" => 0xffffff, "xftype" => XLSXF_TYPE_PROT_STYLEXF, "flagsforce" => 0xf4, "fontindex" => 1)); + $this->append(array("forced"=>1, "parentxfindex" => 0xffffff, "xftype" => XLSXF_TYPE_PROT_STYLEXF, "flagsforce" => 0xf4, "fontindex" => 2)); + $this->append(array("forced"=>1, "parentxfindex" => 0xffffff, "xftype" => XLSXF_TYPE_PROT_STYLEXF, "flagsforce" => 0xf4, "fontindex" => 2)); + $this->append(array("forced"=>1, "parentxfindex" => 0xffffff, "xftype" => XLSXF_TYPE_PROT_STYLEXF, "flagsforce" => 0xf4)); + $this->append(array("forced"=>1, "parentxfindex" => 0xffffff, "xftype" => XLSXF_TYPE_PROT_STYLEXF, "flagsforce" => 0xf4)); + $this->append(array("forced"=>1, "parentxfindex" => 0xffffff, "xftype" => XLSXF_TYPE_PROT_STYLEXF, "flagsforce" => 0xf4)); + $this->append(array("forced"=>1, "parentxfindex" => 0xffffff, "xftype" => XLSXF_TYPE_PROT_STYLEXF, "flagsforce" => 0xf4)); + $this->append(array("forced"=>1, "parentxfindex" => 0xffffff, "xftype" => XLSXF_TYPE_PROT_STYLEXF, "flagsforce" => 0xf4)); + $this->append(array("forced"=>1, "parentxfindex" => 0xffffff, "xftype" => XLSXF_TYPE_PROT_STYLEXF, "flagsforce" => 0xf4)); + $this->append(array("forced"=>1, "parentxfindex" => 0xffffff, "xftype" => XLSXF_TYPE_PROT_STYLEXF, "flagsforce" => 0xf4)); + $this->append(array("forced"=>1, "parentxfindex" => 0xffffff, "xftype" => XLSXF_TYPE_PROT_STYLEXF, "flagsforce" => 0xf4)); + $this->append(array("forced"=>1, "parentxfindex" => 0xffffff, "xftype" => XLSXF_TYPE_PROT_STYLEXF, "flagsforce" => 0xf4)); + $this->append(array("forced"=>1, "parentxfindex" => 0xffffff, "xftype" => XLSXF_TYPE_PROT_STYLEXF, "flagsforce" => 0xf4)); + $this->append(array("forced"=>1)); + $this->append(array("forced"=>1, "parentxfindex" => 0xffffff, "xftype" => XLSXF_TYPE_PROT_STYLEXF, "flagsforce" => 0xf8, "fontindex" => 1, "formatindex" => 0x2b)); + $this->append(array("forced"=>1, "parentxfindex" => 0xffffff, "xftype" => XLSXF_TYPE_PROT_STYLEXF, "flagsforce" => 0xf8, "fontindex" => 1, "formatindex" => 0x29)); + $this->append(array("forced"=>1, "parentxfindex" => 0xffffff, "xftype" => XLSXF_TYPE_PROT_STYLEXF, "flagsforce" => 0xf8, "fontindex" => 1, "formatindex" => 0x2c)); + $this->append(array("forced"=>1, "parentxfindex" => 0xffffff, "xftype" => XLSXF_TYPE_PROT_STYLEXF, "flagsforce" => 0xf8, "fontindex" => 1, "formatindex" => 0x2a)); + $this->append(array("forced"=>1, "parentxfindex" => 0xffffff, "xftype" => XLSXF_TYPE_PROT_STYLEXF, "flagsforce" => 0xf8, "fontindex" => 1, "formatindex" => 0x09)); + $this->defaultxf = $this->append(array("forced"=>1, "flagsforce" => 0x50, "patternbgcolor" => 0x88, "patterncolor" => 0x08, "fillpattern" => 0)); + } + + public function append($params) { + $xf = array("fontindex" => 0x00, + "formatindex" => 0x00, + "parentxfindex" => 0x0, + "xftype" => XLSXF_TYPE_PROT_CELLLOCKED, + "allign" => XLSXF_VALLIGN_BOTTOM | XLSXF_HALLIGN_GENERAL, + "flags" => 0x00, + "rotate" => XLSXF_TEXTROTATION_NOROTATION, + "patterncolor" => 0x40, + "patternbgcolor" => 0xc0, + "fillpattern" => 0x00, + "bordertop" => XLSXF_BORDER_NOBORDER, + "bordertopcolor" => 0x0000, + "borderbottom" => XLSXF_BORDER_NOBORDER, + "borderbottomcolor" => 0x0000, + "borderleft" => XLSXF_BORDER_NOBORDER, + "borderleftcolor" => 0x0000, + "borderright" => XLSXF_BORDER_NOBORDER, + "borderrightcolor" => 0x0000 + ); + if (is_array($params)) { + foreach ($params as $key => $param) { + switch ($key) { + case "formatindex" : $xf[$key]=$param; + $xf["flags"]=$xf["flags"] | XLSXF_USEDATTRIB_ATRNUM; + break; + + case "fontindex" : $xf[$key]=$param; + $xf["flags"]=$xf["flags"] | XLSXF_USEDATTRIB_ATRFONT; + break; + + case "rotate" : $xf[$key]=$param; + $xf["flags"]=$xf["flags"] | XLSXF_USEDATTRIB_ATRALC; + break; + case "xftype" : + $xf[$key]=$xf[$key] | $param; + break; + + case "parentxfindex" : $xf[$key]=$param; + $xf["flags"]=$xf["flags"] | XLSXF_USEDATTRIB_ATRNUM; + break; + + case "patterncolor" : $xf[$key] = $param; // foreground color definied with font + break; + + case "patternbgcolor" : $xf[$key]=$param; + $xf["patterncolor"]=0x08; + if ($xf["fillpattern"]==0x00) { $xf["fillpattern"]=0x01; } + $xf["flags"]=$xf["flags"] | XLSXF_USEDATTRIB_ATRPAT | XLSXF_USEDATTRIB_ATRALC; + break; + case "fillpattern" : $xf[$key]=$param; + $xf["flags"]=$xf["flags"] | XLSXF_USEDATTRIB_ATRPAT; + break; + + case "hallign" : + $i = $xf["allign"]&0xf8; + $i = $i | $param; + $xf["allign"] = $i; + $xf["flags"]=$xf["flags"] | XLSXF_USEDATTRIB_ATRFONT; + break; + + case "vallign" : $i = $xf["allign"]&0x1f; + $i = $i | $param; + $xf["allign"] = $i; + $xf["flags"]=$xf["flags"] | XLSXF_USEDATTRIB_ATRFONT; + break; + + case "textwrap" : $xf["allign"]=$xf["allign"] | XLSXF_WRAPTEXT; + $xf["flags"]=$xf["flags"] | XLSXF_USEDATTRIB_ATRFONT; + break; + + case "border" : $xf["bordertop"]=$param; + $xf["borderbottom"]=$param; + $xf["borderleft"]=$param; + $xf["borderright"]=$param; + $param=0x0008; // default border color = black + case "bordercolor" : $xf["bordertopcolor"]=$param; + $xf["borderbottomcolor"]=$param; + $xf["borderleftcolor"]=$param; + $xf["borderrightcolor"]=$param; + $xf["flags"]=$xf["flags"] | XLSXF_USEDATTRIB_ATRBDR; + break; + + case "bordertop" : + case "borderbottom" : + case "borderleft" : + case "borderright" : + $xf[$key]=$param; + $colorkey = $key."color"; + if ($xf[$colorkey]==0x0000) { $xf[$colorkey]=0x0009; } + $xf["flags"]=$xf["flags"] | XLSXF_USEDATTRIB_ATRBDR; + break; + case "bordertopcolor" : + case "borderbottomcolor": + case "borderleftcolor": + case "borderrightcolor": + $xf[$key]=$param; + $xf["flags"]=$xf["flags"] | XLSXF_USEDATTRIB_ATRBDR; + break; + } + } + if (count($this->xf_array)==0) { + $xf["flags"] = 0; + } + if ($xf["parentxfindex"]==0xffffff) { + $xf["flags"] = $xf["flags"] & 0xf7; + } + if (isset($params["flagsforce"])) { + $xf["flags"] = $params["flagsforce"]; + } + } + $s = serialize($xf); + $xfindex = array_search($s,$this->xf_array); + if (($xfindex===false) || (isset($params["forced"]))) { + $xfindex = count($this->xf_array); + $this->xf_array[] = $s; + if (defined("XFDEBUG")) { + $xfindex = array_search($s,$this->xf_array); + echo "new XF record , index : $xfindex\n"; + echo "new XF record : $s \n"; + } + } + return $xfindex; + } + + public function save($filehandle,$xls_biffobject) { + foreach ($this->xf_array as $xfindex => $tmp) { + $xfrec = unserialize($tmp); + $xls_biffobject->clear(BIFF_XFRECORD); + $xls_biffobject->append(XLSDATA_SHORT,$xfrec["fontindex"]); + $xls_biffobject->append(XLSDATA_SHORT,$xfrec["formatindex"]); + $i = ($xfrec["parentxfindex"]<<4) | $xfrec["xftype"]; + $xls_biffobject->append(XLSDATA_SHORT,$i); + $xls_biffobject->append(XLSDATA_BYTE,$xfrec["allign"]); + $i = $xfrec["rotate"] | $xfrec["flags"]; + $xls_biffobject->append(XLSDATA_BYTE,$i); + + $i = $xfrec["patternbgcolor"] | ($xfrec["patterncolor"] << 7); + $i = (($i == 0) ? 0x20c0 : $i); // magic number if no colors defined + $i = $i | ($xfrec["fillpattern"] << 16); + $i = $i | ($xfrec["borderbottom"] << 22); + $i = $i | ($xfrec["borderbottomcolor"] << 25); + $xls_biffobject->append(XLSDATA_LONG,$i); + + $i = $xfrec["bordertop"] | ($xfrec["borderleft"] << 3) | ($xfrec["borderright"] << 6); + $i = $i | ($xfrec["bordertopcolor"] << 9) | ($xfrec["borderleftcolor"] << 16) | ($xfrec["borderrightcolor"] << 23); + $xls_biffobject->append(XLSDATA_LONG,$i); + $xls_biffobject->save($filehandle); + } + } + } +?> \ No newline at end of file diff --git a/vendor/xls_export.php b/vendor/xls_export.php new file mode 100644 index 0000000..554e729 --- /dev/null +++ b/vendor/xls_export.php @@ -0,0 +1,1414 @@ + index of $worksheets + // "worksheetname" => data + // + // data struct + // array of $rows + // + // rows struct + // array of $cells + // + // cell struct + // $data, + // type : *xls_string/xls_int/xls_float/xls_expression, + // format, + // font-index : *, + // xf-index : * + + var $xlsfilehandle = null; + var $file_header = null; + var $xlsdocument = null; + var $xlsstreamsize = null; + var $rootstorageoffset = null; + var $xls_bof = null; + var $palette = null; + var $xf = null; + var $xls_bofstart = -1; + var $sheetinformationpos = -1; + var $objectcounter = 1; + + // array struct + // (sheetname, first_row, last_row, first_col, last_col, sheetinfopos, fileoffset, colwidths, rowheights, defcolwidthoffset, rowrecordsoffset) + var $worksheets = null; + + public function __construct() { + $this->xlsdocument = array(); + $this->xls_bof = new xls_bof(0); + $this->palette = new xls_palette(); + $this->font = new xls_font(0); + $this->xf = new xls_xf(0); + } + + public function addworksheet($sheetname) { + if (isset($this->worksheets[$sheetname])) { return false; } + $this->xlsdocument[$sheetname]["document"] = array(); + $this->xlsdocument[$sheetname]["worksheetid"] = count($this->worksheets); + $this->worksheets[] = array("sheetname" => $sheetname, + "first_row" => 0xffffffff, + "last_row" => 0, + "first_col" => 0xffffffff, + "last_col" => 0, + "sheetinfopos" => -1, + "fileoffset" => -1, + "colwidths" => array(), + "rowheights" => array(), + "defcolwidthoffset" => 0xffffffff, + "rowrecordsoffset" => 0xffffffff); + return true; + } + + public function setcolwidth($sheetname, $acolidx, $awidth) { + $sheetid = $this->xlsdocument[$sheetname]["worksheetid"]; + $this->worksheets[$sheetid]["colwidths"][$acolidx] = $awidth; + } + + public function setrowheight($sheetname, $arowidx, $aheight) { + $sheetid = $this->xlsdocument[$sheetname]["worksheetid"]; + $this->worksheets[$sheetid]["rowheights"][$arowidx] = $aheight; + } + + public function merge_cells($sheetname, $firstrow, $lastrow, $firstcol, $lastcol) { + if (defined("MERGEDEBUG")) { + echo "merge cells , sheet : $sheetname , (fr,lr) : (fc,lc) = ($firstrow,$lastrow) : ($firstcol,$lastcol)
\n"; + } + if (!isset($this->xlsdocument[$sheetname]["mergedcells"])) { + $this->xlsdocument[$sheetname]["mergedcells"] = new xls_mergedcells(); + } + $this->xlsdocument[$sheetname]["mergedcells"]->merge_cells($firstrow, $lastrow, $firstcol, $lastcol); + if (defined("MERGEDEBUG")) { + print_r($this->xlsdocument[$sheetname]["mergedcells"]); + } + } + + public function setcell($args) { + if (($this->worksheets==null) || (count($this->worksheets)==0)) { return false; } + if (!isset($args["data"])) { return false; } + $sheetname = (isset($args["sheetname"]) ? $args["sheetname"] : $this->worksheets[0]["sheetname"]); + if (isset($args["row"])) { $row = $args["row"]; } + else { + if (count($this->xlsdocument[$sheetname]["document"])<1) { + $row = 0; + $col = 0; + } + else { $row = count($this->xlsdocument[$sheetname]["document"]); } + } + if (isset($args["col"]) && (!isset($col))) { $col = $args["col"]; } + else { + if (isset($this->xlsdocument[$sheetname]["document"][$row])) { $col = count($this->xlsdocument[$sheetname]["document"][$row]); } + else { $col=0; } + } + /* + if (!isset($this->worksheets[$this->xlsdocument[$sheetname]["worksheetid"]]["colwidths"][$col])) { + $this->setcolwidth($sheetname,$col,XLSFILE_DEFAULT_COLWIDTH); + } + if (!isset($this->worksheets[$this->xlsdocument[$sheetname]["worksheetid"]]["rowheights"][$row])) { + $this->setrowheight($sheetname,$row,XLSFILE_DEFAULT_ROWHEIGHT); + } + */ + if (isset($this->xlsdocument[$sheetname]["mergedcells"])) { + $pos = $this->xlsdocument[$sheetname]["mergedcells"]->findpos($row,$col); + if ($pos!==false) { + if (($pos["row"]!=$row) || ($pos["col"]!=$col)) { return false; } + } + } + $cell = array("type" => CELL_STRING, "xfindex" => -1); + $xfrec = array(); + $fontrec = array(); + + foreach ($args as $key => $param) { + switch ($key) { + case "data" : + case "type" : $cell[$key] = $param; + break; + case "bgcolor" : + case "backgroundcolor" : + case "background-color" : $xfrec["patternbgcolor"]=$param; + break; + case "textrotate" : $xfrec["rotate"]=$param; + break; + case "textwrap" : + case "hallign" : + case "vallign" : + case "bordertop" : + case "borderleft" : + case "borderright" : + case "borderbottom" : + case "bordertopcolor" : + case "borderleftcolor" : + case "borderrightcolor" : + case "borderbottomcolor" : + case "bordercolor" : + case "border" : $xfrec[$key] = $param; + break; + + case "fontname" : $fontrec["name"] = $param; + break; + case "fontheight" : + case "fontsize" : $fontrec["height"] = $param; + break; + case "fontweight" : $fontrec["weight"] = $param; + break; + case "color" : + case "fgcolor" : + case "fontcolor" : $fontrec["color"] = $param; + break; + case "fontstyle" : $fontrec["style"] = $param; + break; + case "fontfamily" : $fontrec["family"] = $param; + break; + case "fontescape" : $fontrec["escape"] = $param; + break; + case "underline" : $fontrec["underline"] = $param; + break; + } + } + if (($cell["type"]==CELL_PICTURE) && (isset($fontrec["color"]))) { + $cell["color"]=$this->palette->getcoloridx($fontrec["color"]); + $cell["xfindex"] = $this->xf->defaultxf; + } + else if ((count($xfrec)>0) || (count($fontrec)>0)) { + $xfcheck = array("patternbgcolor","bordertopcolor","borderleftcolor","borderrightcolor","borderbottomcolor","bordercolor"); + foreach ($xfcheck as $key) { + if (isset($xfrec[$key])) { + $xfrec[$key] = $this->palette->getcoloridx($xfrec[$key]); + } + } + + if (isset($fontrec["color"])) { $fontrec["color"] = $this->palette->getcoloridx($fontrec["color"]); } + + $fontindex = $this->font->append($fontrec); + if (defined("FONTDEBUG")) { + if (count($fontrec)>0) { + echo "fontrec :\n"; + print_r($fontrec); + echo "fontindex : $fontindex\n"; + } + } + if ($fontindex!=0) { + $xfrec["fontindex"] = $fontindex; + } + $xfindex = $this->xf->append($xfrec); + $cell["xfindex"] = $xfindex; + if (defined("CELLINSERTDEBUG")) { + print_r($cell); + } + } + else { + $cell["xfindex"] = $this->xf->defaultxf; + } + + $this->xlsdocument[$sheetname]["document"][$row][$col] = $cell; + $this->worksheets[$this->xlsdocument[$sheetname]["worksheetid"]]["first_row"] = min($row,$this->worksheets[$this->xlsdocument[$sheetname]["worksheetid"]]["first_row"]); + $this->worksheets[$this->xlsdocument[$sheetname]["worksheetid"]]["last_row"] = max($row,$this->worksheets[$this->xlsdocument[$sheetname]["worksheetid"]]["last_row"]); + $this->worksheets[$this->xlsdocument[$sheetname]["worksheetid"]]["first_col"] = min($col,$this->worksheets[$this->xlsdocument[$sheetname]["worksheetid"]]["first_col"]); + $this->worksheets[$this->xlsdocument[$sheetname]["worksheetid"]]["last_col"] = max($col,$this->worksheets[$this->xlsdocument[$sheetname]["worksheetid"]]["last_col"]); + return true; + } + + + public function savefile($afilename) { + if (file_exists($afilename)) { + unlink($afilename); + } + + $this->xlsfilehandle = fopen($afilename,"x+"); + $this->file_headerinit(); + + $this->xls_bofstart = ftell($this->xlsfilehandle); + $this->xls_bof->clear(XLS_BIFF5); + $this->xls_bof->append(XLSDATA_SHORT,0x0500); + $this->xls_bof->append(XLSDATA_SHORT,BIFF_WORKBOOKGLOBALS); + $this->xls_bof->append(XLSDATA_SHORT,0x096c); // build identifier + $this->xls_bof->append(XLSDATA_SHORT,0x07c9); // build year = 1993 + $this->xls_bof->save($this->xlsfilehandle); + + $this->xls_bof->clear(BIFF_INTERFACEHEADER); + $this->xls_bof->save($this->xlsfilehandle); + + $this->xls_bof->clear(BIFF_MENURECORDGROUP); + $this->xls_bof->append(XLSDATA_BYTE,0); + $this->xls_bof->append(XLSDATA_BYTE,0); + $this->xls_bof->save($this->xlsfilehandle); + + $this->xls_bof->clear(BIFF_TOOLBARHEADER); + $this->xls_bof->save($this->xlsfilehandle); + + $this->xls_bof->clear(BIFF_TOOLBAREND); + $this->xls_bof->save($this->xlsfilehandle); + + $this->xls_bof->clear(BIFF_INTERFACEEND); + $this->xls_bof->save($this->xlsfilehandle); + + $this->xls_bof->clear(BIFF_WRITEACCESS); + $s = $this->xls_strpad("APACHE2/PHP-XLS Generator",31); + $this->xls_bof->append(XLSDATA_STRING1,$s); + $this->xls_bof->save($this->xlsfilehandle); + + $this->xls_bof->clear(BIFF_CODEPAGE); + $this->xls_bof->append(XLSDATA_SHORT,0x04e4); + $this->xls_bof->save($this->xlsfilehandle); + + $this->xls_bof->clear(BIFF_FUNCTIONGROUPCOUNT); + $this->xls_bof->append(XLSDATA_SHORT,0x000e); + $this->xls_bof->save($this->xlsfilehandle); + + $this->xls_writeexterninfo(); + + foreach ($this->worksheets as $key => $sheetdata) { + $this->xls_bof->clear(BIFF_DEFINEDNAME); + $this->xls_bof->append(XLSDATA_SHORT,0x0020); // built-in-name + $this->xls_bof->append(XLSDATA_BYTE,0x00); // keyboard shortcut + $this->xls_bof->append(XLSDATA_BYTE,0x01); + $this->xls_bof->append(XLSDATA_SHORT,strlen($sheetdata["sheetname"])+2); + $this->xls_bof->append(XLSDATA_SHORT,$key+1); + $this->xls_bof->append(XLSDATA_SHORT,$key+1); + $this->xls_bof->append(XLSDATA_BYTE,0x00); // length of menu text + $this->xls_bof->append(XLSDATA_BYTE,0x00); // length of description text + $this->xls_bof->append(XLSDATA_BYTE,0x00); // length of help topic text + $this->xls_bof->append(XLSDATA_BYTE,0x00); // length of status bar text + $this->xls_bof->append(XLSDATA_BYTE,0x0c); // ? + $this->xls_bof->append(XLSDATA_BYTE,0x17); // ? + $this->xls_bof->append(XLSDATA_STRING,$sheetdata["sheetname"]); + $this->xls_bof->save($this->xlsfilehandle); + + $this->xls_bof->clear(BIFF_DEFINEDNAME); + $this->xls_bof->append(XLSDATA_SHORT,0x0020); // built-in-name + $this->xls_bof->append(XLSDATA_BYTE,0x00); // keyboard shortcut + $this->xls_bof->append(XLSDATA_BYTE,0x01); + $this->xls_bof->append(XLSDATA_SHORT,0x0015); + $this->xls_bof->append(XLSDATA_SHORT,$key+1); + $this->xls_bof->append(XLSDATA_SHORT,$key+1); + $this->xls_bof->append(XLSDATA_BYTE,0x00); // length of menu text + $this->xls_bof->append(XLSDATA_BYTE,0x00); // length of description text + $this->xls_bof->append(XLSDATA_BYTE,0x00); // length of help topic text + $this->xls_bof->append(XLSDATA_BYTE,0x00); // length of status bar text + $this->xls_bof->append(XLSDATA_BYTE,0x06); // ? + $this->xls_bof->append(XLSDATA_BYTE,0x3b); // ? + $this->xls_bof->append(XLSDATA_SHORT,0xffff-$key); // ? + $this->xls_bof->append(XLSDATA_SHORT,0x0000); // ? + $this->xls_bof->append(XLSDATA_SHORT,0x0000); // ? + $this->xls_bof->append(XLSDATA_SHORT,0x0000); // ? + $this->xls_bof->append(XLSDATA_SHORT,0x0000); // ? + $this->xls_bof->append(XLSDATA_SHORT,$key); + $this->xls_bof->append(XLSDATA_SHORT,$key); + $this->xls_bof->append(XLSDATA_LONG,0xffff0000); // ? + $this->xls_bof->append(XLSDATA_SHORT,0xff00); // ? + + $this->xls_bof->save($this->xlsfilehandle); + } + + $this->xls_bof->clear(BIFF_WINDOWPROTECT); + $this->xls_bof->append(XLSDATA_SHORT,0x0000); + $this->xls_bof->save($this->xlsfilehandle); + + $this->xls_bof->clear(BIFF_PROTECT); + $this->xls_bof->append(XLSDATA_SHORT,0x0000); + $this->xls_bof->save($this->xlsfilehandle); + + $this->xls_bof->clear(BIFF_PASSWORD); + $this->xls_bof->append(XLSDATA_SHORT,0x0000); + $this->xls_bof->save($this->xlsfilehandle); + + $this->xls_bof->clear(BIFF_WINDOW1); + $this->xls_bof->append(XLSDATA_SHORT,0x0000); // Horizontal position of the document window + $this->xls_bof->append(XLSDATA_SHORT,0x0000); // Vertical position of the document window + $this->xls_bof->append(XLSDATA_SHORT,0x0000); // Width of the document window + $this->xls_bof->append(XLSDATA_SHORT,0x0000); // Height of the document window + $this->xls_bof->append(XLSDATA_SHORT,0x0038); // Horz/vert scrollbars + Worksheet tab bar visible + $this->xls_bof->append(XLSDATA_SHORT,0x0000); // active tab bar + $this->xls_bof->append(XLSDATA_SHORT,0x0000); // Index of first visible tab in the worksheet tab bar + $this->xls_bof->append(XLSDATA_SHORT,0x0001); // Number of selected worksheets + $this->xls_bof->append(XLSDATA_SHORT,0x0258); // Width of worksheet tab bar (in 1/1000 of window width). + // The remaining space is used by the horizontal scrollbar. + $this->xls_bof->save($this->xlsfilehandle); + + $this->xls_bof->clear(BIFF_BACKUP); + $this->xls_bof->append(XLSDATA_SHORT,0x0000); // =1 if Excel should save a backup version of the file + $this->xls_bof->save($this->xlsfilehandle); + + $this->xls_bof->clear(BIFF_OBJECTDISPLAYOPTIONS); + $this->xls_bof->append(XLSDATA_SHORT,0x0000); // show all + $this->xls_bof->save($this->xlsfilehandle); + + $this->xls_bof->clear(BIFF_DATEMODE); + $this->xls_bof->append(XLSDATA_SHORT,0x0000); // 0 = Base date is 1899-Dec-31 (the cell value 1 represents 1900-Jan-01) + // 1 = Base date is 1904-Jan-01 (the cell value 1 represents 1904-Jan-02) + $this->xls_bof->save($this->xlsfilehandle); + + $this->xls_bof->clear(BIFF_PRECISION); + $this->xls_bof->append(XLSDATA_SHORT,0x0001); // 0 = Use displayed values; 1 = Use real cell values + $this->xls_bof->save($this->xlsfilehandle); + + $this->xls_bof->clear(BIFF_REFRESHALL); + $this->xls_bof->append(XLSDATA_SHORT,0x0000); // =1 then Refresh All should be done on all external data ranges and PivotTables when loading the workbook (the default is =0) + $this->xls_bof->save($this->xlsfilehandle); + + $this->xls_bof->clear(BIFF_BOOKBOOL); + $this->xls_bof->append(XLSDATA_SHORT,0x0000); + $this->xls_bof->save($this->xlsfilehandle); + + $this->font->save($this->xlsfilehandle,$this->xls_bof); + + $this->xls_workbookformat(); + + $this->xf->save($this->xlsfilehandle,$this->xls_bof); + //$this->xls_bof->workbookxfrecords($this->xlsfilehandle); + + $this->xls_bof->clear(BIFF_STYLEINFORMATION); + $this->xls_bof->append(XLSDATA_SHORT,0x8010); + $this->xls_bof->append(XLSDATA_BYTE,0x03); + $this->xls_bof->append(XLSDATA_BYTE,0xff); + $this->xls_bof->save($this->xlsfilehandle); + + $this->xls_bof->clear(BIFF_STYLEINFORMATION); + $this->xls_bof->append(XLSDATA_SHORT,0x8011); + $this->xls_bof->append(XLSDATA_BYTE,0x06); + $this->xls_bof->append(XLSDATA_BYTE,0xff); + $this->xls_bof->save($this->xlsfilehandle); + + $this->xls_bof->clear(BIFF_STYLEINFORMATION); + $this->xls_bof->append(XLSDATA_SHORT,0x8012); + $this->xls_bof->append(XLSDATA_BYTE,0x04); + $this->xls_bof->append(XLSDATA_BYTE,0xff); + $this->xls_bof->save($this->xlsfilehandle); + + $this->xls_bof->clear(BIFF_STYLEINFORMATION); + $this->xls_bof->append(XLSDATA_SHORT,0x8013); + $this->xls_bof->append(XLSDATA_BYTE,0x07); + $this->xls_bof->append(XLSDATA_BYTE,0xff); + $this->xls_bof->save($this->xlsfilehandle); + + $this->xls_bof->clear(BIFF_STYLEINFORMATION); + $this->xls_bof->append(XLSDATA_SHORT,0x8000); + $this->xls_bof->append(XLSDATA_BYTE,0x00); + $this->xls_bof->append(XLSDATA_BYTE,0xff); + $this->xls_bof->save($this->xlsfilehandle); + + $this->xls_bof->clear(BIFF_STYLEINFORMATION); + $this->xls_bof->append(XLSDATA_SHORT,0x8014); + $this->xls_bof->append(XLSDATA_BYTE,0x05); + $this->xls_bof->append(XLSDATA_BYTE,0xff); + $this->xls_bof->save($this->xlsfilehandle); + + $this->palette->save($this->xlsfilehandle,$this->xls_bof); + + $this->sheetinformationpos = ftell($this->xlsfilehandle); + $this->xls_writesheetinformationlist(); + + $this->xls_bof->clear(XLS_BIFF_EOF); + $this->xls_bof->save($this->xlsfilehandle); + + foreach ($this->worksheets as $sheetkey => $data) { + $this->xls_writesheetdata($sheetkey); + } + $this->xlsstreamsize = ftell($this->xlsfilehandle)-0x0200; + + if ($this->xlsstreamsize>=0x1000) { + $fsize = ftell($this->xlsfilehandle) & 0x01ff; + $reqbytes = 0x0200 - $fsize; + } + else { + $fsize = ftell($this->xlsfilehandle) & 0x003f; + $reqbytes = 0x0040 - $fsize; + } + if ($reqbytes>0) { + $s = str_repeat(chr(0),$reqbytes); + fwrite($this->xlsfilehandle,$s,$reqbytes); + } + + $this->rootstorageoffset=ftell($this->xlsfilehandle); + $this->xls_writerootstorage(); + + if ((ftell($this->xlsfilehandle) & 0x01ff)!=0) { + $fsize = ftell($this->xlsfilehandle) & 0x01ff; + $reqbytes = 0x0200 - $fsize; + if ($reqbytes>0) { + $s = str_repeat(chr(0),$reqbytes); + fwrite($this->xlsfilehandle,$s,$reqbytes); + } + } + + if ($this->xlsstreamsize>=0x1000) { + $rootsecid = $this->rootstorageoffset; + $rootsecid = $rootsecid-0x200; + $rootsecid = $rootsecid>>9; + $rootminisecid = 0; + } + else { + $rootsecid = 0; + $rootminisecid = ($this->rootstorageoffset-0x0200) >> 6; + }; + $this->xls_writeminifat(); + $dirsecid = ftell($this->xlsfilehandle); + $dirsecid = $dirsecid-0x0200; + $dirsecid = $dirsecid>>9; + $this->xls_writedirentry("Root Entry",5,1,0xffffffff,$rootsecid,(($this->xlsstreamsize<0x1000) ? $this->rootstorageoffset-0x0100 : 0x0100)); + $this->xls_writedirentry("Book",2,1,3,0,$this->xlsstreamsize); + $this->xls_writedirentry(chr(5)."DocumentSummaryInformation",2,1,0xffffffff,$rootminisecid,0x48); + $this->xls_writedirentry(chr(5)."SummaryInformation",2,1,2,$rootminisecid+2,0x48); + + $fatsecid = ftell($this->xlsfilehandle); + $fatsecid = $fatsecid-0x0200; + $fatsecid = $fatsecid>>9; + fseek($this->xlsfilehandle,FILE_HEADER_DIRECTORYSTART,SEEK_SET); + fwrite($this->xlsfilehandle,pack("V",$dirsecid),4); + fseek($this->xlsfilehandle,0,SEEK_END); + + $fat = new fat_class($this->xlsfilehandle, $this->xlsstreamsize, $this->rootstorageoffset); + fseek($this->xlsfilehandle,FILE_HEADER_NUMBEROFFATSECTORS,SEEK_SET); + $fatsectorcount = $fat->fatsectorcount; + fwrite($this->xlsfilehandle,pack("V",$fatsectorcount),4); + + fseek($this->xlsfilehandle,FILE_HEADER_FIRSTFATENTRY,SEEK_SET); + while ($fatsectorcount>0) { + fwrite($this->xlsfilehandle,pack("V",$fatsecid),4); + $fatsecid++; + $fatsectorcount--; + } + + fclose($this->xlsfilehandle); + } + + private function file_headerinit() { + // signature + $this->file_header = pack("c*",0xd0, 0xcf, 0x11, 0xe0, 0xa1, 0xb1, 0x1a, 0xe1); + // clsid + $this->file_header .= pack("c*",0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00); + // minor.ver + $this->file_header .= pack("v",0x003e); + // major.ver + $this->file_header .= pack("v",0x0003); + // byteorder + $this->file_header .= pack("v",0xfffe); + // sectorshift + $this->file_header .= pack("v",0x0009); + // minisectorsh + $this->file_header .= pack("v",0x0006); + // reserved + $this->file_header .= pack("vvvvv",0x0000,0x0000,0x0000,0x0000,0x0000); + // fatsectors + $this->file_header .= pack("V",0x00000001); + // dirsectors + $this->file_header .= pack("V",0x00000000); + // signature + $this->file_header .= pack("V",0x00000000); + // ministrm.size + $this->file_header .= pack("V",0x00001000); + // first minifat sector + $this->file_header .= pack("V",0x00000000); + // minifat sectors + $this->file_header .= pack("V",0x00000001); + // dif sectors start + $this->file_header .= pack("V",0xfffffffe); + // dif sectors count + $this->file_header .= pack("V",0x00000000); + // first109fat + $this->file_header .= str_repeat(chr(0xff),436); + + fwrite($this->xlsfilehandle, $this->file_header); + } + + function xls_strpad($astr,$asize) { + $strlength = strlen($astr); + $output = chr($strlength).$astr; + while (strlen($output)!=$asize) { $output .= " "; } + return $output; + } + + private function xls_workbookformat() { + $s = pack("C*",0x1e,0x04,0x14,0x00,0x05,0x00,0x11,0x24,0x23,0x2c,0x23,0x23,0x30); + $s.= pack("C*",0x5f,0x29,0x3b,0x28,0x24,0x23,0x2c,0x23,0x23,0x30,0x29,0x1e,0x04,0x19,0x00,0x06); + $s.= pack("C*",0x00,0x16,0x24,0x23,0x2c,0x23,0x23,0x30,0x5f,0x29,0x3b,0x5b,0x52,0x65,0x64,0x5d); + $s.= pack("C*",0x28,0x24,0x23,0x2c,0x23,0x23,0x30,0x29,0x1e,0x04,0x1a,0x00,0x07,0x00,0x17,0x24); + $s.= pack("C*",0x23,0x2c,0x23,0x23,0x30,0x2e,0x30,0x30,0x5f,0x29,0x3b,0x28,0x24,0x23,0x2c,0x23); + $s.= pack("C*",0x23,0x30,0x2e,0x30,0x30,0x29,0x1e,0x04,0x1f,0x00,0x08,0x00,0x1c,0x24,0x23,0x2c); + $s.= pack("C*",0x23,0x23,0x30,0x2e,0x30,0x30,0x5f,0x29,0x3b,0x5b,0x52,0x65,0x64,0x5d,0x28,0x24); + $s.= pack("C*",0x23,0x2c,0x23,0x23,0x30,0x2e,0x30,0x30,0x29,0x1e,0x04,0x2d,0x00,0x2a,0x00,0x2a); + $s.= pack("C*",0x5f,0x28,0x24,0x2a,0x20,0x23,0x2c,0x23,0x23,0x30,0x5f,0x29,0x3b,0x5f,0x28,0x24); + $s.= pack("C*",0x2a,0x20,0x28,0x23,0x2c,0x23,0x23,0x30,0x29,0x3b,0x5f,0x28,0x24,0x2a,0x20,0x22); + $s.= pack("C*",0x2d,0x22,0x5f,0x29,0x3b,0x5f,0x28,0x40,0x5f,0x29,0x1e,0x04,0x2a,0x00,0x29,0x00); + $s.= pack("C*",0x27,0x5f,0x28,0x2a,0x20,0x23,0x2c,0x23,0x23,0x30,0x5f,0x29,0x3b,0x5f,0x28,0x2a); + $s.= pack("C*",0x20,0x28,0x23,0x2c,0x23,0x23,0x30,0x29,0x3b,0x5f,0x28,0x2a,0x20,0x22,0x2d,0x22); + $s.= pack("C*",0x5f,0x29,0x3b,0x5f,0x28,0x40,0x5f,0x29,0x1e,0x04,0x35,0x00,0x2c,0x00,0x32,0x5f); + $s.= pack("C*",0x28,0x24,0x2a,0x20,0x23,0x2c,0x23,0x23,0x30,0x2e,0x30,0x30,0x5f,0x29,0x3b,0x5f); + $s.= pack("C*",0x28,0x24,0x2a,0x20,0x28,0x23,0x2c,0x23,0x23,0x30,0x2e,0x30,0x30,0x29,0x3b,0x5f); + $s.= pack("C*",0x28,0x24,0x2a,0x20,0x22,0x2d,0x22,0x3f,0x3f,0x5f,0x29,0x3b,0x5f,0x28,0x40,0x5f); + $s.= pack("C*",0x29,0x1e,0x04,0x32,0x00,0x2b,0x00,0x2f,0x5f,0x28,0x2a,0x20,0x23,0x2c,0x23,0x23); + $s.= pack("C*",0x30,0x2e,0x30,0x30,0x5f,0x29,0x3b,0x5f,0x28,0x2a,0x20,0x28,0x23,0x2c,0x23,0x23); + $s.= pack("C*",0x30,0x2e,0x30,0x30,0x29,0x3b,0x5f,0x28,0x2a,0x20,0x22,0x2d,0x22,0x3f,0x3f,0x5f); + $s.= pack("C*",0x29,0x3b,0x5f,0x28,0x40,0x5f,0x29); + fwrite($this->xlsfilehandle,$s); + } + + private function xls_writesheetinformationlist() { + foreach ($this->worksheets as $key => $data) { + $this->xls_writeonesheetinformation($key); + } + } + + private function xls_writeonesheetinformation($sheetid) { + $fpos = ftell($this->xlsfilehandle); + if ($this->worksheets[$sheetid]["sheetinfopos"]!=-1) { + fseek($this->xlsfilehandle,$this->worksheets[$sheetid]["sheetinfopos"],SEEK_SET); + } + $this->xls_bof->clear(BIFF_BOUNDSHEET); + $this->xls_bof->append(XLSDATA_LONG,$this->worksheets[$sheetid]["fileoffset"]); + $this->xls_bof->append(XLSDATA_SHORT,0x0000); + $this->xls_bof->append(XLSDATA_STRING,$this->worksheets[$sheetid]["sheetname"]); + $this->xls_bof->save($this->xlsfilehandle); + if ($this->worksheets[$sheetid]["sheetinfopos"]!=-1) { + fseek($this->xlsfilehandle,$fpos,SEEK_SET); + } + else { $this->worksheets[$sheetid]["sheetinfopos"]=$fpos; } + } + + private function xls_writeexterninfo() { + $this->xls_bof->clear(BIFF_EXTERNALREFERENCESCOUNT); + $this->xls_bof->append(XLSDATA_SHORT,count($this->worksheets)+2); // = sheetcount+2 + $this->xls_bof->save($this->xlsfilehandle); + + foreach ($this->worksheets as $key => $sheetdata) { + $this->xls_bof->clear(BIFF_EXTERNSHEET); + $this->xls_bof->append(XLSDATA_BYTE,strlen($sheetdata["sheetname"])); + $this->xls_bof->append(XLSDATA_BYTE,3); + $this->xls_bof->append(XLSDATA_STRING1,$sheetdata["sheetname"]); + $this->xls_bof->save($this->xlsfilehandle); + } + + $this->xls_bof->clear(BIFF_EXTERNSHEET); + $this->xls_bof->append(XLSDATA_BYTE,0x01); + $this->xls_bof->append(XLSDATA_BYTE,0x3a); + $this->xls_bof->save($this->xlsfilehandle); + + $this->xls_bof->clear(BIFF_EXTERNSHEET); + $this->xls_bof->append(XLSDATA_BYTE,0x01); + $this->xls_bof->append(XLSDATA_BYTE,0x04); + $this->xls_bof->save($this->xlsfilehandle); + } + + public function xls_picturecallback() { + die("done."); + } + + private function xls_writesheetdata($sheetid) { + if (defined("DEBUG")) { + echo "writesheet : $sheetid
"; + } + $rowrecord_filepos = array(); + $rowpos = array(); + + $this->worksheets[$sheetid]["fileoffset"] = ftell($this->xlsfilehandle)-0x0200; + $this->xls_writeonesheetinformation($sheetid); + $this->xls_bof->clear(XLS_BIFF5); + $this->xls_bof->append(XLSDATA_SHORT,0x0500); + $this->xls_bof->append(XLSDATA_SHORT,WORKBOOK_SHEET); + $this->xls_bof->append(XLSDATA_SHORT,0x096c); // build identifier + $this->xls_bof->append(XLSDATA_SHORT,0x07c9); // build year = 1993 + $this->xls_bof->save($this->xlsfilehandle); + + $this->worksheets[$sheetid]["rowrecordsoffset"] = ftell($this->xlsfilehandle)+2+2+4+2+2+4; + + $rowcount = $this->worksheets[$sheetid]["last_row"]-$this->worksheets[$sheetid]["first_row"]; + $dbcellcount = ($rowcount >> 5)+1; + $this->xls_bof->clear(BIFF_INDEX); + $this->xls_bof->append(XLSDATA_LONG,0x00000000); // unused var. + $this->xls_bof->append(XLSDATA_SHORT,$this->worksheets[$sheetid]["first_row"]); + $this->xls_bof->append(XLSDATA_SHORT,$this->worksheets[$sheetid]["last_row"]+1); + $this->xls_bof->append(XLSDATA_LONG,0x00000000); + + $i=0; + while ($i!=$dbcellcount) { + $this->xls_bof->append(XLSDATA_LONG,0xffffffff); + $rowrecord_filepos[$i]=ftell($this->xlsfilehandle)+16+($i<<2); + $i++; + } + + $this->xls_bof->save($this->xlsfilehandle); + + $this->xls_bof->clear(BIFF_CALCMODE); + $this->xls_bof->append(XLSDATA_SHORT,0x0001); + $this->xls_bof->save($this->xlsfilehandle); + + $this->xls_bof->clear(BIFF_CALCCOUNT); + $this->xls_bof->append(XLSDATA_SHORT,0x0064); + $this->xls_bof->save($this->xlsfilehandle); + + $this->xls_bof->clear(BIFF_REFMODE); + $this->xls_bof->append(XLSDATA_SHORT,0x0001); + $this->xls_bof->save($this->xlsfilehandle); + + $this->xls_bof->clear(BIFF_ITERATION); + $this->xls_bof->append(XLSDATA_SHORT,0x0001); + $this->xls_bof->save($this->xlsfilehandle); + + $this->xls_bof->clear(BIFF_DELTA); + $this->xls_bof->append(XLSDATA_BYTE,0xfc); + $this->xls_bof->append(XLSDATA_BYTE,0xa9); + $this->xls_bof->append(XLSDATA_BYTE,0xf1); + $this->xls_bof->append(XLSDATA_BYTE,0xd2); + $this->xls_bof->append(XLSDATA_BYTE,0x4d); + $this->xls_bof->append(XLSDATA_BYTE,0x62); + $this->xls_bof->append(XLSDATA_BYTE,0x50); + $this->xls_bof->append(XLSDATA_BYTE,0x3f); + $this->xls_bof->save($this->xlsfilehandle); + + $this->xls_bof->clear(BIFF_SAVERECALC); + $this->xls_bof->append(XLSDATA_SHORT,0x0001); + $this->xls_bof->save($this->xlsfilehandle); + + $this->xls_bof->clear(BIFF_PRINTHEADERS); + $this->xls_bof->append(XLSDATA_SHORT,0x0000); + $this->xls_bof->save($this->xlsfilehandle); + + $this->xls_bof->clear(BIFF_PRINTGRIDLINES); + $this->xls_bof->append(XLSDATA_SHORT,0x0000); + $this->xls_bof->save($this->xlsfilehandle); + + $this->xls_bof->clear(BIFF_GRIDSET); + $this->xls_bof->append(XLSDATA_SHORT,0x0001); + $this->xls_bof->save($this->xlsfilehandle); + + $this->xls_bof->clear(BIFF_GUTS); + $this->xls_bof->append(XLSDATA_SHORT,0x0000); + $this->xls_bof->append(XLSDATA_SHORT,0x0000); + $this->xls_bof->append(XLSDATA_SHORT,0x0000); + $this->xls_bof->append(XLSDATA_SHORT,0x0000); + $this->xls_bof->save($this->xlsfilehandle); + + $this->xls_bof->clear(BIFF_DEFAULTROWHEIGHT); + $this->xls_bof->append(XLSDATA_SHORT,0x0000); + $this->xls_bof->append(XLSDATA_SHORT,0x012c); + $this->xls_bof->save($this->xlsfilehandle); + + $this->xls_bof->clear(BIFF_COUNTRY); + $this->xls_bof->append(XLSDATA_SHORT,0x0001); // Windows country identifier of the user interface language of Excel + $this->xls_bof->append(XLSDATA_SHORT,0x0001); // Windows country identifier of the system regional settings + $this->xls_bof->save($this->xlsfilehandle); + + $this->xls_bof->clear(BIFF_SHEETPR); + $this->xls_bof->append(XLSDATA_SHORT,0x04c1); /* 0 0001H 0 = Do not show automatic page breaks + 1 = Show automatic page breaks + 4 0010H 0 = Standard sheet + 1 = Dialogue sheet (BIFF5-BIFF8) + 5 0020H 0 = No automatic styles in outlines + 1 = Apply automatic styles to outlines + 6 0040H 0 = Outline buttons above outline group + 1 = Outline buttons below outline group + 7 0080H 0 = Outline buttons left of outline group + 1 = Outline buttons right of outline group + 8 0100H 0 = Scale printout in percent + 1 = Fit printout to number of pages + 9 0200H 0 = Save external linked values (BIFF3-BIFF4 only) + 1 = Do not save external linked values (BIFF3-BIFF4 only) + 10 0400H 0 = Do not show row outline symbols 1 = Show row outline symbols + 11 0800H 0 = Do not show column outline symbols + 1 = Show column outline symbols + 13-12 3000H These flags specify the arrangement of windows. They are stored in BIFF4 only. + 002 = Arrange windows tiled + 012 = Arrange windows horizontal + 102 = Arrange windows vertical + 112 = Arrange windows cascaded + The following flags are valid for BIFF4-BIFF8 only: + 14 4000H 0 = Excel like expression evaluation + 1 = Lotus like expression evaluation + 15 8000H 0 = Excel like formula editing + 1 = Lotus like formula editing + */ + $this->xls_bof->save($this->xlsfilehandle); + + /* + $this->xls_bof->clear(BIFF_PAGEHEADER); + $this->xls_bof->append(XLSDATA_LSTRING,$this->page_header); + $this->xls_bof->save($this->xlsfilehandle); + + $this->xls_bof->clear(BIFF_PAGEFOOTER); + $this->xls_bof->append(XLSDATA_LSTRING,$this->page_footer); + $this->xls_bof->save($this->xlsfilehandle); + */ + /* + $this->xls_bof->clear(BIFF_PAGEHEADER); + $this->xls_bof->append(XLSDATA_LSTRING,""); + $this->xls_bof->save($this->xlsfilehandle); + + $this->xls_bof->clear(BIFF_PAGEFOOTER); + $this->xls_bof->append(XLSDATA_LSTRING,""); + $this->xls_bof->save($this->xlsfilehandle); + */ + $this->xls_bof->clear(BIFF_HCENTER); + $this->xls_bof->append(XLSDATA_SHORT,0x0000); + $this->xls_bof->save($this->xlsfilehandle); + + $this->xls_bof->clear(BIFF_VCENTER); + $this->xls_bof->append(XLSDATA_SHORT,0x0000); + $this->xls_bof->save($this->xlsfilehandle); + + $this->xls_bof->clear(BIFF_LEFTMARGIN); + $this->xls_bof->append(XLSDATA_BYTE,0x00); + $this->xls_bof->append(XLSDATA_BYTE,0x00); + $this->xls_bof->append(XLSDATA_BYTE,0x00); + $this->xls_bof->append(XLSDATA_BYTE,0x00); + $this->xls_bof->append(XLSDATA_BYTE,0x00); + $this->xls_bof->append(XLSDATA_BYTE,0x00); + $this->xls_bof->append(XLSDATA_BYTE,0xf0); + $this->xls_bof->append(XLSDATA_BYTE,0x3f); + $this->xls_bof->save($this->xlsfilehandle); + + $this->xls_bof->clear(BIFF_RIGHTMARGIN); + $this->xls_bof->append(XLSDATA_BYTE,0x00); + $this->xls_bof->append(XLSDATA_BYTE,0x00); + $this->xls_bof->append(XLSDATA_BYTE,0x00); + $this->xls_bof->append(XLSDATA_BYTE,0x00); + $this->xls_bof->append(XLSDATA_BYTE,0x00); + $this->xls_bof->append(XLSDATA_BYTE,0x00); + $this->xls_bof->append(XLSDATA_BYTE,0xf0); + $this->xls_bof->append(XLSDATA_BYTE,0x3f); + $this->xls_bof->save($this->xlsfilehandle); + + $this->xls_bof->clear(BIFF_TOPMARGIN); + $this->xls_bof->append(XLSDATA_BYTE,0xab); + $this->xls_bof->append(XLSDATA_BYTE,0xaa); + $this->xls_bof->append(XLSDATA_BYTE,0xaa); + $this->xls_bof->append(XLSDATA_BYTE,0xaa); + $this->xls_bof->append(XLSDATA_BYTE,0xaa); + $this->xls_bof->append(XLSDATA_BYTE,0xaa); + $this->xls_bof->append(XLSDATA_BYTE,0xfa); + $this->xls_bof->append(XLSDATA_BYTE,0x3f); + $this->xls_bof->save($this->xlsfilehandle); + + $this->xls_bof->clear(BIFF_BOTTOMMARGIN); + $this->xls_bof->append(XLSDATA_BYTE,0xab); + $this->xls_bof->append(XLSDATA_BYTE,0xaa); + $this->xls_bof->append(XLSDATA_BYTE,0xaa); + $this->xls_bof->append(XLSDATA_BYTE,0xaa); + $this->xls_bof->append(XLSDATA_BYTE,0xaa); + $this->xls_bof->append(XLSDATA_BYTE,0xaa); + $this->xls_bof->append(XLSDATA_BYTE,0xfa); + $this->xls_bof->append(XLSDATA_BYTE,0x3f); + $this->xls_bof->save($this->xlsfilehandle); + + $this->xls_bof->clear(BIFF_PAGESETUP); + $this->xls_bof->append(XLSDATA_SHORT,0x0000); /* Paper size + 0 Undefined + 1 Letter 81/2½ × 11½ + 2 Letter small 81/2½ × 11½ + 3 Tabloid 11½ × 17½ + 4 Ledger 17½ × 11½ + 5 Legal 81/2½ × 14½ + 6 Statement 51/2½ × 81/2½ + 7 Executive 71/4½ × 101/2½ + 8 A3 297mm × 420mm + 9 A4 210mm × 297mm + 10 A4 small 210mm × 297mm + 11 A5 148mm × 210mm + 12 B4 (JIS) 257mm × 364mm + 13 B5 (JIS) 182mm × 257mm + 14 Folio 81/2½ × 13½ + 15 Quarto 215mm × 275mm + 16 10×14 10½ × 14½ + 17 11×17 11½ × 17½ + 18 Note 81/2½ × 11½ + 19 Envelope #9 37/8½ × 87/8½ + 20 Envelope #10 41/8½ × 91/2½ + 21 Envelope #11 41/2½ × 103/8½ + 22 Envelope #12 43/4½ × 11½ + 23 Envelope #14 5½ × 111/2½ + 24 C 17½ × 22½ + 25 D 22½ × 34½ + 26 E 34½ × 44½ + 27 Envelope DL 110mm × 220mm + 28 Envelope C5 162mm × 229mm + 29 Envelope C3 324mm × 458mm + 30 Envelope C4 229mm × 324mm + 31 Envelope C6 114mm × 162mm + 32 Envelope C6/C5 114mm × 229mm + 33 B4 (ISO) 250mm × 353mm + 34 B5 (ISO) 176mm × 250mm + 35 B6 (ISO) 125mm × 176mm + 36 Envelope Italy 110mm × 230mm + 37 Envelope Monarch 37/8½ × 71/2½ + 38 63/4 Envelope 35/8½ × 61/2½ + 39 US Standard Fanfold 147/8½ × 11½ + 40 German Std. Fanfold 81/2½ × 12½ + 41 German Legal Fanfold 81/2½ × 13½ + 42 B4 (ISO) 250mm × 353mm + 43 Japanese Postcard 100mm × 148mm + 44 9×11 9½ × 11½ + 45 10×11 10½ × 11½ + 46 15×11 15½ × 11½ + 47 Envelope Invite 220mm × 220mm + 48 Undefined + 49 Undefined + 50 Letter Extra 91/2½ × 12½ + 51 Legal Extra 91/2½ × 15½ + 52 Tabloid Extra 1111/16½ × 18½ + 53 A4 Extra 235mm × 322mm + 54 Letter Transverse 81/2½ × 11½ + 55 A4 Transverse 210mm × 297mm + 56 Letter Extra Transv. 91/2½ × 12½ + 57 Super A/A4 227mm × 356mm + 58 Super B/A3 305mm × 487mm + 59 Letter Plus 812½ × 1211/16½ + 60 A4 Plus 210mm × 330mm + 61 A5 Transverse 148mm × 210mm + 62 B5 (JIS) Transverse 182mm × 257mm + 63 A3 Extra 322mm × 445mm + 64 A5 Extra 174mm × 235mm + 65 B5 (ISO) Extra 201mm × 276mm + 66 A2 420mm × 594mm + 67 A3 Transverse 297mm × 420mm + 68 A3 Extra Transverse 322mm × 445mm + 69 Dbl. Japanese Postcard 200mm × 148mm + 70 A6 105mm × 148mm + 71 + 72 + 73 + 74 + 75 Letter Rotated 11½ × 81/2½ + 76 A3 Rotated 420mm × 297mm + 77 A4 Rotated 297mm × 210mm + 78 A5 Rotated 210mm × 148mm + 79 B4 (JIS) Rotated 364mm × 257mm + 80 B5 (JIS) Rotated 257mm × 182mm + 81 Japanese Postcard Rot. 148mm × 100mm + 82 Dbl. Jap. Postcard Rot. 148mm × 200mm + 83 A6 Rotated 148mm × 105mm + 84 + 85 + 86 + 87 + 88 B6 (JIS) 128mm × 182mm + 89 B6 (JIS) Rotated 182mm × 128mm + 90 12×11 12½ × 11½ + */ + $this->xls_bof->append(XLSDATA_SHORT,0x0024); // scaling factor in percent + $this->xls_bof->append(XLSDATA_SHORT,0x0001); // start page number + $this->xls_bof->append(XLSDATA_SHORT,0x0001); // Fit worksheet width to this number of pages (0 = use as many as needed) + $this->xls_bof->append(XLSDATA_SHORT,0x0001); // Fit worksheet height to this number of pages (0 = use as many as needed) + $this->xls_bof->append(XLSDATA_SHORT,0x0146); /* Print options + bit mask + 0 0001H 0 = Print pages in columns + 1 = Print pages in rows + 1 0002H 0 = Landscape + 1 = Portrait + 2 0004H 1 = Paper size, scaling factor, paper orientation (portrait/landscape),print resolution and number of copies are not initialised + 3 0008H 0 = Print coloured + 1 = Print black and white + 4 0010H 0 = Default print quality + 1 = Draft quality + 5 0020H 0 = Do not print cell notes + 1 = Print cell notes + 6 0040H 0 = Use paper orientation (portrait/landscape) flag above1 + 1 = Use default paper orientation(landscape for chart sheets,portrait otherwise) + 7 0080H 0 = Automatic page numbers + 1 = Use start page number above The following flags are valid for BIFF8 only: + 9 0200H 0 = Print notes as displayed + 1 = Print notes at end of sheet + 11-10 0C00H 002 = Print errors as displayed + 012 = Do not print errors + 102 = Print errors as ?--? + 112 = Print errors as ?#N/A? + */ + $this->xls_bof->append(XLSDATA_SHORT,0x0033); // Print resolution in dpi + $this->xls_bof->append(XLSDATA_SHORT,0xff00); // Vertical print resolution in dpi + $this->xls_bof->append(XLSDATA_LONG,0x33333333); // Header margin + $this->xls_bof->append(XLSDATA_LONG,0x3fd33333); // Header margin + $this->xls_bof->append(XLSDATA_LONG,0x33333333); // Footer margin + $this->xls_bof->append(XLSDATA_LONG,0x3fd33333); // Footer margin + $this->xls_bof->append(XLSDATA_SHORT,0x00ff); // Number of copies to print + $this->xls_bof->save($this->xlsfilehandle); + + $this->xls_writeexterninfo(); + + $this->xls_bof->clear(BIFF_DEFCOLWIDTH); + $this->xls_bof->append(XLSDATA_SHORT,0x0008); + $this->xls_bof->save($this->xlsfilehandle); + + $i=-1; + while ($i<$this->worksheets[$sheetid]["last_col"]) { + $i++; + if (isset($this->worksheets[$sheetid]["colwidths"][$i])) { + $this->xls_bof->clear(BIFF_COLINFO); + $this->xls_bof->append(XLSDATA_SHORT,$i); // Index to first column in the range + $this->xls_bof->append(XLSDATA_SHORT,$i); // Index to last column in the range + $this->xls_bof->append(XLSDATA_SHORT,$this->worksheets[$sheetid]["colwidths"][$i]); // Width of the columns in 1/256 of the width of the zero character, using default font (first FONT record in the file) + $this->xls_bof->append(XLSDATA_SHORT,$this->xf->defaultxf); + //$this->xls_bof->append(XLSDATA_SHORT,(($i<=$this->worksheets[$sheetid]["first_col"]) ? 0x0002 : 0x0000)); + $this->xls_bof->append(XLSDATA_SHORT,0x0002); + /* Offset Bits Mask Option Name Contents + 0 0 01h fHidden =1 if the column range is hidden + 7-1 FEh (unused) + 1 2-0 07h iOutLevel Outline level of column range + 3 08h (Reserved) Reserved; must be 0 (zero) + 4 10h fCollapsed =1 if the column range is collapsed in outlining + 7-5 E0h (Reserved) Reserved; must be 0 (zero) + */ + $this->xls_bof->append(XLSDATA_SHORT,0x0000); // Not used + $this->xls_bof->save($this->xlsfilehandle); + } + } + + $this->xls_bof->clear(BIFF_DIMENSIONS); + $this->xls_bof->append(XLSDATA_SHORT,0x0000); // first row + $this->xls_bof->append(XLSDATA_SHORT,$this->worksheets[$sheetid]["last_row"]+1); // last used row + 1 + $this->xls_bof->append(XLSDATA_SHORT,0x0000); // first col + $this->xls_bof->append(XLSDATA_SHORT,$this->worksheets[$sheetid]["last_col"]+1); // last used col + 1 + $this->xls_bof->append(XLSDATA_SHORT,0x0000); // not used + $this->xls_bof->save($this->xlsfilehandle); + + $rowrecord_count = 0; + $i=0; + $sheetdata = &$this->xlsdocument[$this->worksheets[$sheetid]["sheetname"]]["document"]; + if (count($sheetdata)>1) { + ksort ($sheetdata,SORT_NUMERIC); + } + + while ($i<$this->worksheets[$sheetid]["last_row"]+1) { + $j=0; + $rowrecord_start = ftell($this->xlsfilehandle); + while (($j!=32) && ($i<$this->worksheets[$sheetid]["last_row"]+1)) { + if (isset($sheetdata[$i])) { + if (@isset($this->worksheets[$sheetid]["rowheights"][$i])) { + $this->xls_bof->clear(BIFF_ROW); + $this->xls_bof->append(XLSDATA_SHORT,$i); // row no. + $this->xls_bof->append(XLSDATA_SHORT,0x0000); // first defined column + $this->xls_bof->append(XLSDATA_SHORT,$this->worksheets[$sheetid]["last_col"]+1); // last defined column +1 + $this->xls_bof->append(XLSDATA_SHORT,$this->worksheets[$sheetid]["rowheights"][$i]); // row height + $this->xls_bof->append(XLSDATA_SHORT,0x0000); // Used by Excel to optimize loading the file; if you are creating a BIFF file, set irwMac to 0. + $this->xls_bof->append(XLSDATA_SHORT,0x0000); // reserved + $this->xls_bof->append(XLSDATA_BYTE,($this->worksheets[$sheetid]["rowheights"][$i]==0xff ? 0 : 0x40)); // see options @ offset 0 + $this->xls_bof->append(XLSDATA_BYTE,0x01); /* options + Offset Bits Mask Name Contents + 0 2?0 07h iOutLevel Outline level of the row + 3 08h (Reserved) + 4 10h fCollapsed =1 if the row is collapsed in outlining + 5 20h fDyZero =1 if the row height is set to 0 (zero) + 6 40h fUnsynced =1 if the font height and row height are not compatible + 7 80h fGhostDirty =1 if the row has been formatted, even if it contains all blank cells + 1 7?0 FFh (Reserved) ???? + */ + $this->xls_bof->append(XLSDATA_SHORT,0x000f); /* If fGhostDirty=1 (see grbit field), this is the index to the XF record for the row. + Otherwise, this field is undefined. + Note: ixfe uses only the low-order 12 bits of the field (bits 11?0). + Bit 12 is fExAsc, bit 13 is fExDsc, and bits 14 and 15 are reserved. + fExAsc and fExDsc are set to true if the row has a thick border on top or on bottom, + respectively. + */ + $this->xls_bof->save($this->xlsfilehandle); + } + } + $i++; + $j++; + } + $i=$i-$j; + $j=0; + $rowpos = array(); + while (($j!=32) && ($i<$this->worksheets[$sheetid]["last_row"]+1)) { + if (isset($sheetdata[$i])) { + $rowpos[]=ftell($this->xlsfilehandle); + $rowdata = &$sheetdata[$i]; + if (count($rowdata)>1) { + ksort($rowdata,SORT_NUMERIC); + } + foreach ($rowdata as $cellid => $celldata) { + switch ($celldata["type"]) { + case CELL_STRING : + $this->xls_bof->clear(BIFF_LABEL); + $this->xls_bof->append(XLSDATA_SHORT,$i); // rowid. + $this->xls_bof->append(XLSDATA_SHORT,$cellid); // cellid + $this->xls_bof->append(XLSDATA_SHORT,$celldata["xfindex"]); // XF index. + $this->xls_bof->append(XLSDATA_LSTRING,$celldata["data"]); + $this->xls_bof->save($this->xlsfilehandle); + break; + case CELL_FLOAT : + $this->xls_bof->clear(BIFF_NUMBER); + $this->xls_bof->append(XLSDATA_SHORT,$i); // rowid. + $this->xls_bof->append(XLSDATA_SHORT,$cellid); // cellid + $this->xls_bof->append(XLSDATA_SHORT,$celldata["xfindex"]); // XF index. + $this->xls_bof->append(XLSDATA_FLOAT,floatval($celldata["data"])); + $this->xls_bof->save($this->xlsfilehandle); + break; + + case CELL_PICTURE : + if (defined("PICTUREDEBUG")) { + echo "picture inserted
\n"; + } + $bgcolor = (isset($celldata["bgcolor"]) ? $celldata["bgcolor"] : 9); + $fgcolor = (isset($celldata["color"]) ? $celldata["color"] : 9); + $bgcolorrgb = $this->palette->palette_array[$bgcolor-8]; + $picture = new xls_picture($celldata["data"],$bgcolor,$fgcolor,$bgcolorrgb,$this->objectcounter,$i,$cellid); + $picture->loaddata(); + + $imageheight = ($picture->imageheight << 4)+$picture->imageheight; + $imagewidth = ($picture->imagewidth << 5)+$picture->imagewidth; + //$imageheight = intval(round($picture->imageheight*18)); + //$imagewidth = intval(round($picture->imagewidth*36)); + + $picture->lastrow = $i; + $picture->lastcol = $cellid; + $rcnt = $i; + $ok = false; + if (defined("PICTUREDEBUG")) { + echo "calc. space
\n"; + echo "start row : ".$picture->firstrow."
\n"; + } + + while (!$ok) { + $tmprowheight = (isset($this->worksheets[$sheetid]["rowheights"][$rcnt]) ? $this->worksheets[$sheetid]["rowheights"][$rcnt] : XLSFILE_DEFAULT_ROWHEIGHT); + if (defined("PICTUREDEBUG")) { + echo "?last row : ".$picture->lastrow." , picture height : $imageheight , tmpheight : $tmprowheight
\n"; + } + if ($tmprowheight>=$imageheight) { + if (defined("PICTUREDEBUG")) { + echo "height calc. finish
\n"; + } + $picture->imagebottom = $imageheight; + $ok=true; + continue; + } + else { + $picture->lastrow++; + $imageheight -= ($tmprowheight+18); + $rcnt++; + } + } + + if (defined("PICTUREDEBUG")) { + echo "calc. space
\n"; + echo "start row : ".$picture->firstcol."
\n"; + } + + $ccnt = $cellid; + $ok = false; + while (!$ok) { + $tmpcolwidth = (isset($this->worksheets[$sheetid]["colwidths"][$ccnt]) ? $this->worksheets[$sheetid]["colwidths"][$ccnt] : XLSFILE_DEFAULT_COLWIDTH); + if (defined("PICTUREDEBUG")) { + echo "?last row : ".$picture->lastcol." , picture width : $imagewidth , tmpwidth : $tmpcolwidth
\n"; + } + if ($tmpcolwidth>=$imagewidth) { + if (defined("PICTUREDEBUG")) { + echo "width calc. finish
\n"; + } + $ok=true; + $picture->imageright = $imagewidth; + } + else { + $picture->lastcol++; + $imagewidth -= ($tmpcolwidth+36); + $ccnt++; + } + } + /* + $picture->imagebottom = intval(round($imageheight*($tmprowheight/1024))); + $picture->imageright = intval(round($imagewidth*($tmpcolwidth/1024))); + */ + $picture->imagebottom = $imageheight / $tmprowheight * 256; + $picture->imageright = $imagewidth / $tmpcolwidth * 1024; + + $picture->save($this->xlsfilehandle, $this->xls_bof); + unset($picture); + $this->objectcounter++; + break; + + default : die("Unknown cell data type"); + } + } + } + $i++; + $j++; + } + $filepos_backup = ftell($this->xlsfilehandle); + fseek($this->xlsfilehandle,$rowrecord_filepos[$rowrecord_count],SEEK_SET); + $s = pack("V",$filepos_backup-0x0200); + fwrite($this->xlsfilehandle,$s); + fseek($this->xlsfilehandle,$filepos_backup,SEEK_SET); + + + $this->xls_bof->clear(BIFF_DBCELL); + $this->xls_bof->append(XLSDATA_LONG,$filepos_backup-$rowrecord_start); + $this->xls_bof->append(XLSDATA_SHORT,($rowpos[0]-$rowrecord_start)-0x14); + foreach ($rowpos as $key => $data) { + if ($key==count($rowpos)-1) { + break; + } + $offset = $rowpos[0]-$data; + $this->xls_bof->append(XLSDATA_SHORT,$offset); + } + $this->xls_bof->save($this->xlsfilehandle); + unset($rowpos); + $rowrecord_count++; + } + $this->xls_bof->clear(BIFF_WINDOW2); + $sheetopt = ($sheetid==0 ? 0x06b6 : 0x00b6); + $this->xls_bof->append(XLSDATA_SHORT,$sheetopt); /* Bit Mask Contents + 0 0001H 0 = Show formula results 1 = Show formulas + 1 0002H 0 = Do not show grid lines 1 = Show grid lines + 2 0004H 0 = Do not show sheet headers 1 = Show sheet headers + 3 0008H 0 = Panes are not frozen 1 = Panes are frozen (freeze) + 4 0010H 0 = Show zero values as empty cells 1 = Show zero values + 5 0020H 0 = Manual grid line colour 1 = Automatic grid line colour + 6 0040H 0 = Columns from left to right 1 = Columns from right to left + 7 0080H 0 = Do not show outline symbols 1 = Show outline symbols + 8 0100H 0 = Keep splits if pane freeze is removed 1 = Remove splits if pane freeze is removed + 9 0200H 0 = Sheet not selected 1 = Sheet selected (BIFF5-BIFF8) + 10 0400H 0 = Sheet not active 1 = Sheet active (BIFF5-BIFF8) + 11 0800H 0 = Show in normal view 1 = Show in page break preview (BIFF8) + */ + $this->xls_bof->append(XLSDATA_SHORT,0x0000); // Index to first visible row + $this->xls_bof->append(XLSDATA_SHORT,0x0000); // Index to first visible column + $this->xls_bof->append(XLSDATA_LONG,0x00000040); // Grid line RGB colour + $this->xls_bof->save($this->xlsfilehandle); + + $this->xls_bof->clear(BIFF_SELECTION); + $this->xls_bof->append(XLSDATA_BYTE,0x03); + $this->xls_bof->append(XLSDATA_SHORT,$this->worksheets[$sheetid]["first_row"]); // Index to row of the active cell + $this->xls_bof->append(XLSDATA_SHORT,$this->worksheets[$sheetid]["first_col"]); // Index to column of the active cell + $this->xls_bof->append(XLSDATA_SHORT,0x0000); // Index into the following cell range list to the entry that contains the active cell + $this->xls_bof->append(XLSDATA_SHORT,0x0001); + $this->xls_bof->append(XLSDATA_SHORT,0); // $this->worksheets[$sheetid]["first_row"] + $this->xls_bof->append(XLSDATA_SHORT,0); // $this->worksheets[$sheetid]["last_row"] + $this->xls_bof->append(XLSDATA_BYTE,0); // $this->worksheets[$sheetid]["last_col"] + $this->xls_bof->append(XLSDATA_BYTE,0); // $this->worksheets[$sheetid]["last_col"] + $this->xls_bof->save($this->xlsfilehandle); + + if (isset($this->xlsdocument[$this->worksheets[$sheetid]["sheetname"]]["mergedcells"])) { + $this->xlsdocument[$this->worksheets[$sheetid]["sheetname"]]["mergedcells"]->save($this->xlsfilehandle, $this->xls_bof); + } + + $this->xls_bof->clear(BIFF_SHEETPROTECTION); + $this->xls_bof->append(XLSDATA_SHORT,BIFF_SHEETPROTECTION); + $this->xls_bof->append(XLSDATA_BYTE,0x00); // not used + $this->xls_bof->append(XLSDATA_BYTE,0x00); // not used + $this->xls_bof->append(XLSDATA_BYTE,0x00); // not used + $this->xls_bof->append(XLSDATA_BYTE,0x00); // not used + $this->xls_bof->append(XLSDATA_BYTE,0x00); // not used + $this->xls_bof->append(XLSDATA_BYTE,0x00); // not used + $this->xls_bof->append(XLSDATA_BYTE,0x00); // not used + $this->xls_bof->append(XLSDATA_BYTE,0x00); // not used + $this->xls_bof->append(XLSDATA_BYTE,0x00); // not used + $this->xls_bof->append(XLSDATA_BYTE,0x00); // not used + + $this->xls_bof->append(XLSDATA_BYTE,0x02); // unknown data + $this->xls_bof->append(XLSDATA_BYTE,0x00); // unknown data + $this->xls_bof->append(XLSDATA_BYTE,0x01); // unknown data + $this->xls_bof->append(XLSDATA_BYTE,0xff); // unknown data + $this->xls_bof->append(XLSDATA_BYTE,0xff); // unknown data + $this->xls_bof->append(XLSDATA_BYTE,0xff); // unknown data + $this->xls_bof->append(XLSDATA_BYTE,0xff); // unknown data + $this->xls_bof->append(XLSDATA_SHORT,0x4400); // ??? + $this->xls_bof->append(XLSDATA_SHORT,0x0000); // not used + $this->xls_bof->save($this->xlsfilehandle); + + + $this->xls_bof->clear(XLS_BIFF_EOF); + $this->xls_bof->save($this->xlsfilehandle); + } + + private function xls_writeminifat() { + $minifat_start = ftell($this->xlsfilehandle); + $minifat_sectorid = pack("V",($minifat_start-0x0200)/0x0200); + if ($this->xlsstreamsize>=0x1000) { + $s = pack("V",0x00000001); + $s .= pack("V",0xfffffffe); + $s .= pack("V",0x00000003); + $s .= pack("V",0xfffffffe); + $s = str_pad($s,512,chr(0xff)); + fwrite($this->xlsfilehandle,$s,512); + } + else { + $s = ""; + $scount = $this->xlsstreamsize >> 6; + $scount+= (($this->xlsstreamsize & 0x3f)>0 ? 1 : 0); + $scount--; + for ($i=0; $i!=$scount; $i++) { + $s .= pack ("V",$i+1); + } + $scount++; + $s .= pack("V",0xfffffffe); + $scount++; + $s .= pack("V",$scount); + $scount++; + $s .= pack("V",0xfffffffe); + $scount++; + $s .= pack("V",$scount); + $scount++; + $s .= pack("V",0xfffffffe); + $s = str_pad($s,512,chr(0xff)); + fwrite($this->xlsfilehandle,$s,512); + } + $fpos = ftell($this->xlsfilehandle); + fseek($this->xlsfilehandle,0x003c,SEEK_SET); + fwrite($this->xlsfilehandle,$minifat_sectorid,4); + fseek($this->xlsfilehandle,$fpos,SEEK_SET); + } + + private function xls_writerootstorage() { + $s=""; + $s.=pack("C*",0xfe,0xff,0x00,0x00,0x04,0x0a,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00); + $s.=pack("C*",0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x02,0xd5,0xcd,0xd5); + $s.=pack("C*",0x9c,0x2e,0x1b,0x10,0x93,0x97,0x08,0x00,0x2b,0x2c,0xf9,0xae,0x30,0x00,0x00,0x00); + $s.=pack("C*",0x18,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x10,0x00,0x00,0x00); + $s.=pack("C*",0x02,0x00,0x00,0x00,0xe4,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00); + $s.=pack("C*",0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00); + $s.=pack("C*",0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00); + $s.=pack("C*",0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00); + $s.=pack("C*",0xfe,0xff,0x00,0x00,0x04,0x0a,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00); + $s.=pack("C*",0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0xe0,0x85,0x9f,0xf2); + $s.=pack("C*",0xf9,0x4f,0x68,0x10,0xab,0x91,0x08,0x00,0x2b,0x27,0xb3,0xd9,0x30,0x00,0x00,0x00); + $s.=pack("C*",0x18,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x10,0x00,0x00,0x00); + $s.=pack("C*",0x02,0x00,0x00,0x00,0xe4,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00); + $s.=pack("C*",0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00); + $s.=pack("C*",0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00); + $s.=pack("C*",0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00); + fwrite($this->xlsfilehandle,$s,256); + } + +/* +struct StructuredStorageDirectoryEntry { + // [offset from start in bytes, length in bytes] + BYTE _ab[32*sizeof(WCHAR)]; // [000H,64] 64 bytes. The Element name in Unicode, padded with zeros to fill this byte array + WORD _cb; // [040H,02] Length of the Element name in characters, not bytes + BYTE _mse; // [042H,01] Type of object: value taken from the STGTY enumeration + STGTY_INVALID = 0, + STGTY_STORAGE = 1, + STGTY_STREAM = 2, + STGTY_LOCKBYTES = 3, + STGTY_PROPERTY = 4, + STGTY_ROOT = 5, + BYTE _bflags; // [043H,01] Value taken from DECOLOR enumeration. + DE_RED = 0, + DE_BLACK = 1, + SID _sidLeftSib; // [044H,04] SID of the left-sibling of this entry in the directory tree + SID _sidRightSib; // [048H,04] SID of the right-sibling of this entry in the directory tree + SID _sidChild; // [04CH,04] SID of the child acting as the root of all the children of this element (if _mse=STGTY_STORAGE) + GUID _clsId; // [050H,16] CLSID of this storage (if _mse=STGTY_STORAGE) + DWORD _dwUserFlags; // [060H,04] User flags of this storage (if _mse=STGTY_STORAGE) + TIME_T _time[2]; // [064H,16] Create/Modify time-stamps (if _mse=STGTY_STORAGE) + SECT _sectStart; // [074H,04] starting SECT of the stream (if _mse=STGTY_STREAM) + ULONG _ulSize; // [078H,04] size of stream in bytes (if _mse=STGTY_STREAM) + DFPROPTYPE _dptPropType; // [07CH,02] Reserved for future use. Must be zero. +}; +*/ + private function xls_writedirentry($adirname,$adirtype,$adecolor,$arightchild,$asectorid,$asize) { + $dirname = ""; + for ($i=0; $ixlsfilehandle,$dirname,64); + fwrite($this->xlsfilehandle,pack("v",$namelen)); + fwrite($this->xlsfilehandle,pack("C",$adirtype)); + fwrite($this->xlsfilehandle,pack("C",$adecolor)); + fwrite($this->xlsfilehandle,pack("V",0xffffffff)); + fwrite($this->xlsfilehandle,pack("V",$arightchild)); + fwrite($this->xlsfilehandle,pack("V",($adirname=="Root Entry" ? 0x00000001 : 0xffffffff))); + $s = str_repeat(chr(0),16); + fwrite($this->xlsfilehandle,$s,16); + fwrite($this->xlsfilehandle,pack("V",0x00000000)); + fwrite($this->xlsfilehandle,$s,16); + fwrite($this->xlsfilehandle,pack("V",$asectorid)); + fwrite($this->xlsfilehandle,pack("V",$asize)); + fwrite($this->xlsfilehandle,pack("v",0x0000)); + fwrite($this->xlsfilehandle,pack("v",0x0000)); + } + + public function sendfile($afilename) { + // 2009-10-22 - modified by Helmut Schottmüller + // Change path to TYPOlight temp dir + $currentdir = getcwd(); + chdir(TL_ROOT . '/system/tmp'); + // 2009-10-22 - end modification + $tmpname = "tmp".date("YmdHi").".xls"; + $this->savefile($tmpname); + header("Content-Type:application/force-download"); + $headerfilename=sprintf("Content-Disposition: attachment; filename=%s",$afilename); + header($headerfilename); + header("Content-Transfer-Encoding: binary"); + $dlfilesize = filesize($tmpname); + header("Content-Length: ".$dlfilesize); + @readfile($tmpname,$afilename); + unlink($tmpname); + // 2009-10-22 - modified by Helmut Schottmüller + // Change path back to current dir + chdir($currentdir); + // 2009-10-22 - end modification + } + + // additional getters + // 2010-02-02 - modified by Helmut Schottmüller, methods by Georg Rehfeld + /** + * Returns the width of the given column. + * + * The return value is in terms of 256 times the width of the 0 (zero) character in + * the default font (the first one defined). When devided by 256 it is + * roughly comparable to CSS 'en' units. + */ + public function getcolwidth($sheetname, $acolidx) { + $sheetid = $this->xlsdocument[$sheetname]["worksheetid"]; + if (isset($this->worksheets[$sheetid]["colwidths"][$acolidx])) + { + return $this->worksheets[$sheetid]["colwidths"][$acolidx]; + } + return XLSFILE_DEFAULT_COLWIDTH; // 0x0924 = 2340 = 9.14 en ? + } + + /** + * Returns the height of the given row. + * + * The return value is in terms of 256 times the width of the 0 (zero) character in + * the default font (the first one defined). When devided by 256 it is + * roughly comparable to CSS 'en' units. + * + * @TODO: there seems to be a need for some scale factor, when used with cw/ccw text? + */ + public function getrowheight($sheetname, $arowidx) { + $sheetid = $this->xlsdocument[$sheetname]["worksheetid"]; + if (isset($this->worksheets[$sheetid]["rowheights"][$arowidx])) + { + return $this->worksheets[$sheetid]["rowheights"][$arowidx]; + } + return XLSFILE_DEFAULT_ROWHEIGHT; // 0x012c = 300 = 1.17 en ? + } + // 2010-02-02 - end modification + +} +?> From 33e1627fc26df04615a199d638a0b1d6717c1456 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carsten=20G=C3=B6tzinger?= Date: Fri, 26 Jan 2018 03:47:07 +0000 Subject: [PATCH 2/2] Add license --- LICENSE | 674 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 674 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..b8c80c2 --- /dev/null +++ b/LICENSE @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + xls_export + Copyright (C) 2018 contao + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + xls_export Copyright (C) 2018 contao + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +.