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);
}
}
?>