|
[text/plain 1.2k]
Hi,
WriteExcel make broken xls file if utf8 string used in formulas.
How to repeat:
Spreadsheet::WriteExcel->new(\*STDOUT)
->addworksheet()
->write_formula("A1", qq!="\x{43c}\x{430}\x{43c}\x{430}"!);
Suggested fix:
diff -U 7 -F '^sub ' -r
Spreadsheet-WriteExcel-2.20.orig/lib/Spreadsheet/WriteExcel/Formula.pm
Spreadsheet-WriteExcel-2.20/lib/Spreadsheet/WriteExcel/Formula.pm
---
Spreadsheet-WriteExcel-2.20.orig/lib/Spreadsheet/WriteExcel/Formula.pm
2007-10-30 20:52:45.584613634 +0300
+++ Spreadsheet-WriteExcel-2.20/lib/Spreadsheet/WriteExcel/Formula.pm
2007-10-30 20:55:05.152679214 +0300
@@ -515,14 +515,23 @@ sub _convert_string {
$str =~ s/""/"/g; # Substitute Excel's escaped double quote "" for "
my $length = length($str);
# TODO string length
die "String in formula has more than 255 chars\n" if $length > 255;
+ # encode utf strings
+ if ($] >= 5.008) {
+ require Encode;
+ if (Encode::is_utf8($str)) {
+ $encoding = 1;
+ $str = Encode::encode("UTF-16LE", $str);
+ }
+ }
+
return pack("CCC", $ptg{ptgStr}, $length, $encoding) . $str;
}
###############################################################################
#
# _convert_ref2d()
|