Fix charset and number format issues

This commit is contained in:
Chris Graham 2015-03-30 22:07:37 +01:00
parent b546f51efd
commit bef2b4647c
2 changed files with 22 additions and 2 deletions

View File

@ -149,7 +149,7 @@ EOD;
if (empty($cellValue)) { if (empty($cellValue)) {
$data .= '/>' . PHP_EOL; $data .= '/>' . PHP_EOL;
} else { } else {
if (trim($cellValue, '0123456789.') == '' /*similar to is_numeric without having PHPs regular quirkiness*/) { if (trim($cellValue, '-0123456789.') == '' /*similar to is_numeric without having PHPs regular quirkiness*/) {
$data .= '><v>' . $cellValue . '</v></c>' . PHP_EOL; $data .= '><v>' . $cellValue . '</v></c>' . PHP_EOL;
} else { } else {
if ($this->shouldUseInlineStrings) { if ($this->shouldUseInlineStrings) {

View File

@ -115,6 +115,26 @@ class XLS extends AbstractWriter
$value = substr($value, 0, 255); $value = substr($value, 0, 255);
} }
// We are doing simple Western European encoding (utf-8 storage in BIFF-5 is very complex)
if (function_exists('utf8_decode')) {
$test = @utf8_decode($value);
if (is_string($test)) {
$value = $test;
}
}
elseif (function_exists('iconv')) {
$test = @iconv('utf-8', 'iso-8859-1' . '//TRANSLIT', $value);
if (is_string($test)) {
$value = $test;
}
}
elseif (function_exists('mb_convert_encoding')) {
$test = @mb_convert_encoding($value, 'iso-8859-1', 'utf-8');
if (is_string($test)) {
$value = $test;
}
}
$length = strlen($value); $length = strlen($value);
$wasWriteSuccessful = true; $wasWriteSuccessful = true;
$wasWriteSuccessful = $wasWriteSuccessful && fwrite($this->filePointer, pack("ssssss", 0x204, 8 + $length, $this->row, $this->col, 0x0, $length)); $wasWriteSuccessful = $wasWriteSuccessful && fwrite($this->filePointer, pack("ssssss", 0x204, 8 + $length, $this->row, $this->col, 0x0, $length));
@ -144,7 +164,7 @@ class XLS extends AbstractWriter
$this->home(); $this->home();
foreach ($dataRow as $cell) { foreach ($dataRow as $cell) {
if (trim($cell, '0123456789.') == '' /*similar to is_numeric without having PHPs regular quirkiness*/) { if ($cell != '' && trim($cell, '-0123456789.') == '' /*similar to is_numeric without having PHPs regular quirkiness*/) {
$wasWriteSuccessful = $wasWriteSuccessful && $this->number($cell); $wasWriteSuccessful = $wasWriteSuccessful && $this->number($cell);
} else } else
{ {