|
Posted by Al on November 20, 2006, 5:24 pm
Please log in for more thread options
thanks guys.. very helpful. thanks also for referring me to that good
Unicode tutorial.
Adding this line to my perl program did the trick:
binmode STDOUT, ":utf8";
I had to do similar with the Filehandle of the file I write to.
Then, with TextWrangler, if I open that resulting file in UTF-8 mode,
it looks perfect, accent marks and all.
I'm using Perl 5.8.6 on Mac OS X
thanks so much!
A
H=2EMerijn Brand wrote:
>
> > I'm using the Spreadsheet::Read module (which works quite well
> > generally). I have some spreadsheets with special characters like an
> > accented e (=E9). I'm having some trouble processing these characters.
> > I haven't dealt much with these type of characters in this context in
> > the past. The accented e's are coming out like "?".
>
> That is based on both encoding and the font you use on the terminal.
> By default, Spreadsheet::Read does not change the encoding, which means
> that if the fields are encoded in Unicode (utf8), you should take action
> in your script to output Unicode.
>
> Read http://search.cpan.org/~rgarcia/perl-5.9.4/pod/perlunitut.pod
>
> Summary, if your terminal is capable of dealing with UTF8 (like a
> recent X11R6 xterm with utf8 enabled and font *-iso10646-1), then
> adding
>
> binmode STDOUT, ":utf8";
>
> will probably suffice. If your terminal is iso8859-*, which also
> supports the e-acute, then you will have to take appropriate actions
>
> I think that the csv file is OK already. Try opening it in whatever
> unicode enabled editor (I think both M$Word and M$Excel will do here)
> and see how it looks
>
> > My spreadsheet has cells A1, A2 and A3 set to Cafe like the following:
> > in A1, excel automatically made the accented e, in A2, i pressed Option
> > e e for the accented e, and A3, I undid the special e to make it a
> > regular e
> >
> > A1:A3
> > ---------
> > Caf=E9
> > Caf=E9
> > Cafe
> >
> > This is my program
> > ------------------------------
> > use Spreadsheet::Read;
> >
> > my $ref =3D ReadData('special_char_test.xls');
> >
> > my $cell1 =3D $ref->[1];
> > my $cell2 =3D $ref->[1][1][2]; #try different way
> > my $cell3 =3D $ref->[1][1][3];
> >
> > print "Cell A1: $cell1\n";
> > print "Cell A2: $cell2\n";
> > print "Cell A3: $cell3\n";
> >
> > Output (standard out):
> > -------------------
> > Cell A1: Caf?
> > Cell A2: Caf?
> > Cell A3: Cafe
> >
> > What can I do so that the accented e prints correctly or so the correct
> > format can be saved to a csv file?
> > Thanks.
|