468,290 Members | 1,978 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,290 developers. It's quick & easy.

Excel PHP

I am using a set of functions that seem to be pretty common for using
an associative array to write data to an .XLS file. This work fine for
the most part, however I have problems writting a number to Excel on a
Solaris system, whereas it works fine on a Windows system using the
same PHP version (5.05). I have isolated the code to the following
function:

/**
* Excel worksheet cell insertion
* (single-worksheet supported only)
* @access private
* @param (int) $row worksheet row number
(0...65536)
* @param (int) $col worksheet column number
(0..255)
* @param (mixed) $val worksheet row number
*/
function _xlsWriteCell($row, $col, $val)
{
if (is_float($val) || is_int($val))
{
// doubles, floats, integers
$str = pack(str_repeat($this->bin[$this->endian], 5),
0x203, 14, $row, $col, 0x0);
$str .= pack("d", $val);
}
else
{
// everything else is treated as a string
$l = strlen($val);
$str = pack(str_repeat($this->bin[$this->endian], 6),
0x204, 8 + $l, $row, $col, 0x0, $l);
$str .= $val;
}
fwrite($this->fp, $str);
$this->position += strlen($str);
return strlen($str);
}

Specifically it looks like the problem is happening here:

if (is_float($val) || is_int($val))
{
// doubles, floats, integers
$str = pack(str_repeat($this->bin[$this->endian], 5),
0x203, 14, $row, $col, 0x0);
$str .= pack("d", $val);
}

My guess is that where it is doing pack("d", $val); that a DOUBLE is
treated different on a windows versus solaris system. I tried changing
this "d" to other things such as Long, Float, and others, but it just
prints garbage when I do so...

Any ideas on how to get this to write a number properly on Solaris, or
how to interpret the 2 pack statements above to get an idea what
exactly it is doing?

Thanks

Apr 9 '07 #1
1 1709
On Apr 9, 5:55 pm, trp...@gmail.com wrote:
I am using a set of functions that seem to be pretty common for using
an associative array to write data to an .XLS file. This work fine for
the most part, however I have problems writting a number to Excel on a
Solaris system, whereas it works fine on a Windows system using the
same PHP version (5.05). I have isolated the code to the following
function:
Not quite sure of this, but maybe this can help you:

$fExcel=fopen($excelfile, "w");
fwrite($fExcel, "<html><head><STYLE TYPE=\"text/css\">");
fwrite($fExcel, " <!-- .number2dec {mso-number-format: Fixed;} \r
\n");
fwrite($fExcel, " .number0dec {mso-number-format: 0\\;} -->\r\n");
fwrite($fExcel, "</STYLE></head><table border=1>\r\n");

fwrite($fExcel, "<tr><td class=number2dec>1.2

Apr 9 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

13 posts views Thread by Allison Bailey | last post: by
6 posts views Thread by Matthew Wieder | last post: by
14 posts views Thread by pmud | last post: by
22 posts views Thread by Howard Kaikow | last post: by
7 posts views Thread by Alain \Mbuna\ | last post: by
9 posts views Thread by Doug Glancy | last post: by
reply views Thread by NPC403 | last post: by
2 posts views Thread by MrBee | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.