Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: ParseExcel:: wackiness

by jmcnamara (Monsignor)
on Oct 05, 2010 at 15:29 UTC ( [id://863623]=note: print w/replies, xml ) Need Help??


in reply to ParseExcel:: wackiness

The data being returned is in Excel's UTF-16 Unicode format.

You will need to specify a Unicode formatter in the parse() method to handle the data. Something like this:

#!/usr/bin/perl use warnings; use strict; use Spreadsheet::ParseExcel; use Spreadsheet::ParseExcel::FmtJapan; my $filename = 'file.xls'; my $parser = Spreadsheet::ParseExcel->new(); my $formatter = Spreadsheet::ParseExcel::FmtJapan->new(); my $workbook = $parser->parse($filename, $formatter); if ( !defined $workbook ) { die "Parsing error: ", $parser->error(), ".\n"; } # Set your output encoding to something like this. binmode STDOUT, ':utf8'; for my $worksheet ( $workbook->worksheets() ) { print "Worksheet name: ", $worksheet->get_name(), "\n\n"; my ( $row_min, $row_max ) = $worksheet->row_range(); my ( $col_min, $col_max ) = $worksheet->col_range(); for my $row ( $row_min .. $row_max ) { for my $col ( $col_min .. $col_max ) { my $cell = $worksheet->get_cell( $row, $col ); next unless $cell; print " Row, Col = ($row, $col)\n"; print " Value = ", $cell->value(), "\n" +; print " Unformatted = ", $cell->unformatted(), "\n" +; print "\n"; } } } __END__

Ignore the fact that the formatter is called FmtJapan, it is also a general purpose Unicode handler.

--
John.

Replies are listed 'Best First'.
Re^2: ParseExcel:: wackiness
by petecm99 (Pilgrim) on Oct 05, 2010 at 15:47 UTC
    Thanks for that, John! I ran into the same thing a few months ago, and merely did the same as misterperl (edited the wackiness out manually).

    Your module has come in handy many times, I appreciate your work...
Re^2: ParseExcel:: wackiness
by misterperl (Friar) on Dec 18, 2012 at 14:34 UTC
    most helpful thanks..

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://863623]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (2)
As of 2026-01-15 03:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your view on AI coding assistants?





    Results (118 votes). Check out past polls.

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.