in reply to What to do when converting Excel-supplied data to Unicode
Then, when you parse the file, you do something like this:package My::Excel::FmtUTF8; use strict; use base 'Spreadsheet::ParseExcel::FmtDefault'; use Encode qw(decode); # the super-class isn't very friendly to sub-classing, so we have to o +verride this to make # sure it's blessed into the right class sub new { my $class = shift; return bless {}, $class; } # the only other method we need to override... sub TextFmt { my ($self,$data,$encoding) = @_; # Spreadsheet::ParseExcel will pass in the encoding to us! # or, it passes nothing in if it's iso-8859-1 $encoding ||= 'iso-8859-1'; # we perform the decoding in a "fatal" manner so that if it fai +ls, # we'll just pass the data back as-is my $decoded = eval { decode($encoding,$data,1) } || $data; return $decoded; }
That seemed to work for all the non-ASCII data that I had to deal with. Hopefully it will work for you too! :-)my $parser = Spreadsheet::ParseExcel->new(); my $data = $parser->Parse( $excel_file_name, My::Excel::FmtUTF8->new() );
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: What to do when converting Excel-supplied data to Unicode
by davis (Vicar) on May 23, 2006 at 13:56 UTC | |
by bpphillips (Friar) on May 23, 2006 at 15:39 UTC | |
Re^2: What to do when converting Excel-supplied data to Unicode
by ITFinanceGuy (Initiate) on Feb 20, 2009 at 22:53 UTC | |
by davis (Vicar) on Feb 20, 2009 at 23:03 UTC | |
by ITFinanceGuy (Initiate) on Feb 20, 2009 at 23:33 UTC | |
by Anonymous Monk on Feb 24, 2009 at 16:50 UTC | |
by ITFinanceGuy (Initiate) on Feb 23, 2009 at 22:55 UTC |