Merge changes for CSV Writer excel compatibility from 1.x develop branch

This commit is contained in:
Mark Baker 2013-08-17 13:20:41 +01:00
parent d38ddb1c8d
commit 186302db5d

View File

@ -115,10 +115,11 @@ class Writer_CSV extends Writer_Abstract implements Writer_IWriter {
} }
if ($this->_excelCompatibility) { if ($this->_excelCompatibility) {
// Write the UTF-16LE BOM code fwrite($fileHandle, "\xEF\xBB\xBF"); // Enforce UTF-8 BOM Header
fwrite($fileHandle, "\xFF\xFE"); // Excel uses UTF-16LE encoding $this->setEnclosure('"'); // Set enclosure to "
$this->setEnclosure(); // Default enclosure is " $this->setDelimiter(";"); // Set delimiter to a semi-colon
$this->setDelimiter("\t"); // Excel delimiter is a TAB $this->setLineEnding("\r\n");
fwrite($fileHandle, 'sep=' . $this->getDelimiter() . $this->_lineEnding);
} elseif ($this->_useBOM) { } elseif ($this->_useBOM) {
// Write the UTF-8 BOM code // Write the UTF-8 BOM code
fwrite($fileHandle, "\xEF\xBB\xBF"); fwrite($fileHandle, "\xEF\xBB\xBF");
@ -301,11 +302,7 @@ class Writer_CSV extends Writer_Abstract implements Writer_IWriter {
$line .= $this->_lineEnding; $line .= $this->_lineEnding;
// Write to file // Write to file
if ($this->_excelCompatibility) { fwrite($pFileHandle, $line);
fwrite($pFileHandle, mb_convert_encoding($line,"UTF-16LE","UTF-8"));
} else {
fwrite($pFileHandle, $line);
}
} else { } else {
throw new Writer_Exception("Invalid data row passed to CSV writer."); throw new Writer_Exception("Invalid data row passed to CSV writer.");
} }