Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 require_once('PEAR.php');
00036
00054 class Spreadsheet_Excel_Writer_BIFFwriter extends PEAR
00055 {
00060 var $_BIFF_version = 0x0500;
00061
00066 var $_byte_order;
00067
00072 var $_data;
00073
00078 var $_datasize;
00079
00085 var $_limit;
00086
00092 function Spreadsheet_Excel_Writer_BIFFwriter()
00093 {
00094 $this->_byte_order = '';
00095 $this->_data = '';
00096 $this->_datasize = 0;
00097 $this->_limit = 2080;
00098
00099 $this->_setByteOrder();
00100 }
00101
00108 function _setByteOrder()
00109 {
00110
00111 $teststr = pack("d", 1.2345);
00112 $number = pack("C8", 0x8D, 0x97, 0x6E, 0x12, 0x83, 0xC0, 0xF3, 0x3F);
00113 if ($number == $teststr) {
00114 $byte_order = 0;
00115 }
00116 elseif ($number == strrev($teststr)){
00117 $byte_order = 1;
00118 }
00119 else {
00120
00121 return $this->raiseError("Required floating point format ".
00122 "not supported on this platform.");
00123 }
00124 $this->_byte_order = $byte_order;
00125 }
00126
00133 function _prepend($data)
00134 {
00135 if (strlen($data) > $this->_limit) {
00136 $data = $this->_addContinue($data);
00137 }
00138 $this->_data = $data.$this->_data;
00139 $this->_datasize += strlen($data);
00140 }
00141
00148 function _append($data)
00149 {
00150 if (strlen($data) > $this->_limit) {
00151 $data = $this->_addContinue($data);
00152 }
00153 $this->_data = $this->_data.$data;
00154 $this->_datasize += strlen($data);
00155 }
00156
00165 function _storeBof($type)
00166 {
00167 $record = 0x0809;
00168
00169
00170
00171 if ($this->_BIFF_version == 0x0500) {
00172 $length = 0x0008;
00173 $unknown = '';
00174 $build = 0x096C;
00175 $year = 0x07C9;
00176 }
00177 elseif ($this->_BIFF_version == 0x0600) {
00178 $length = 0x0010;
00179 $unknown = pack("VV", 0x00000041, 0x00000006);
00180 $build = 0x0DBB;
00181 $year = 0x07CC;
00182 }
00183 $version = $this->_BIFF_version;
00184
00185 $header = pack("vv", $record, $length);
00186 $data = pack("vvvv", $version, $type, $build, $year);
00187 $this->_prepend($header.$data.$unknown);
00188 }
00189
00195 function _storeEof()
00196 {
00197 $record = 0x000A;
00198 $length = 0x0000;
00199 $header = pack("vv", $record, $length);
00200 $this->_append($header);
00201 }
00202
00215 function _addContinue($data)
00216 {
00217 $limit = $this->_limit;
00218 $record = 0x003C;
00219
00220
00221
00222 $tmp = substr($data, 0, 2).pack("v", $limit-4).substr($data, 4, $limit - 4);
00223
00224 $header = pack("vv", $record, $limit);
00225
00226
00227 for($i = $limit; $i < strlen($data) - $limit; $i += $limit)
00228 {
00229 $tmp .= $header;
00230 $tmp .= substr($data, $i, $limit);
00231 }
00232
00233
00234 $header = pack("vv", $record, strlen($data) - $i);
00235 $tmp .= $header;
00236 $tmp .= substr($data,$i,strlen($data) - $i);
00237
00238 return $tmp;
00239 }
00240 }
00241 ?>