Geno Takashima - 2008-11-15 15:36:53 -
In reply to message 3 from Federico Itollo
Be careful: is_numeric searches for numeric strings.. so if you want to make it only for NUMBERS, you need to make your own function. I made one that checks whether the given value is integer or float (negative/positive).
You can add this function into excelwriter
function is_number($number) {
if (preg_match('/[^-0-9]/', $number) != preg_match("/^[-0-9]+\\.[0-9]+$/", $number))
return false;
return true;
}
And then modify the line under foreach in the writeLine function to
if ($this->is_date($col) == false && $this->is_number($col) == true) {
fwrite($this->fp,"<td x:num class=xl24 width=64 >$col</td>");
} else {
fwrite($this->fp,"<td class=xl24 width=64 >$col</td>");
}
And the line in writeCol function to
if ($this->is_date($value) == false && $this->is_number($value) == true) {
fwrite($this->fp,"<td x:num class=xl24 width=64 >$value</td>");
} else {
fwrite($this->fp,"<td class=xl24 width=64 >$value</td>");
}
Notice the $this->is_date() part? You can take that out, unless you have dates formatted in the "yyyy-MM-dd" way and you want them to appear as text. Then you need to add the following function too (you can replace the separator '-' if you want to use the function with other stuff):
function is_date($date, $sep = '-') {
if (strlen($date) != 10)
return false;
if (substr($date, 4, 1) != $sep)
return false;
if (substr($date, 7, 1) != $sep)
return false;
return true;
}