Spreadsheet::WriteExcel requires Unicode characters to be in Perl's UTF8 format. So you will need to convert them from the encoding that you are reading them in to UTF8 (perhaps using Encode) before writing them back to a WriteExcel file.
I don't have an example for cp1250 but here is an example with cp1251.
See also the Unicode section of the Spreadsheet::WriteExcel docs.
--
John.
| [reply] |
It sounds like most of the tools on your system are assuming a single-byte encoding (cp1250) for Slovenian text. If your perl script is somehow turning your spreadsheet data to utf8 strings, you would need to make sure it gets converted back to cp1250 so that the data will be coherent in the other tools that use (and display) the data.
You haven't shown any code, so I'm not sure what to recommend, but somewhere you're likely going to want to do something like this:
use Encode;
...
# assuming $data is a scalar containing a utf8 string:
$data = encode( "cp1250", $data );
# now it contains a cp1250 string
# (utf8 flag is off, and characters are single-byte)
(updated to show that you have to "use Encode" in order to apply the "decode()" function)
... or maybe something like this:
open( OUT, ">:encoding(cp1250)", "output.txt" ) or die "output.txt: $!
+\n";
# assuming $data contains a utf8 string:
print OUT $data;
# the string gets converted to cp1250 before being written to the file
# (no need to "use Encode" in this case)
| [reply] [d/l] [select] |
| [reply] |
...
my @Test;
my $Test;
@Test=encode("cp1250",@Test);
...
So you must have misunderstood what I meant. Anyway, since your script includes use encoding "cp1250"; I gather that you wrote your script with a text editor that saves the file in that encoding. That should be fine, but it means that the quoted strings with accented characters are being treated internally in perl as utf8 strings (because that's what use encoding is supposed to do -- read the output of perldoc encoding).
So if you want these characters to be stored in the Excel file as cp1250 characters, I think you need to do your "write" calls like this:
use Encode;
...
$SheetOut->write(0,0, encode( "cp1250", "Čč" );
$SheetOut->write(0,1, encode( "cp1250", "Šš" );
$SheetOut->write(0,2, encode( "cp1250", "Žž" );
...
What happens in that case is: (1) your text editor saves the script as a cp1250-encoded text file, (2) when perl.exe reads the script to execute it, it sees use encoding "cp1250" and converts the special characters to its normal internal utf8 encoding (so that "character semantics" will work in the normal way), (3) then when those "write() functions are called, the Encode::encode function turns the utf8 strings back into cp1250 for storage in the Excel file.
At least, I think that's what should happen. Give it a try.
(update: the snippet I posted above is showing numeric character entities for some of the characters -- that was not intentional, but I'm not going to try to fix it -- you know which characters are supposed to be there.) | [reply] [d/l] [select] |