Spreadsheet_Excel_Writer and UTF8

| |
[不指定 2009/02/26 15:49 | by ipaddr ]

After recently working on an application to generate Microsoft Excel documents using a PHP script, I ran into trouble with the PEAR package "Spreadsheet Excel Writer" which didn't correctly display UTF-8 characters . Here is a fix!

You just need to replace the Workbook.php file in the Spreadsheet Excel Writer package with this patched version of the file. For more information on the problem and the patch check out the comments on the bug report page (most of the good stuff is right near the bottom).

Then your spreadsheet generation code would look something like:


$workbook = new Spreadsheet_Excel_Writer();
$workbook->send("file.xls");
$workbook->setVersion(8);
$worksheet =& $workbook->addWorksheet("My worksheet");
$worksheet->setInputEncoding("UTF-8");

// .. add content to spreadsheet here
$workbook->close();




This worked for me with version 0.9.0 of the package and it should also work with 0.9.1. I’d expect the fix to be included in upcoming releases of the package, but until then the above patch works great.

[file]attachment/200902/workbook.rar[/file]

Program | 评论(0) | 引用(0) | 阅读(6297)