Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi

I am trying to open Excel and ODS files with longnames paths (and possibly not Latin characters) on Windows. I use Win32::LongPath::openL to open the files. For XLS I then use Spreadsheet::ParseExcel. This works fine. For ODS I use Spreadsheet::Read. This doesn't work.

use Spreadsheet::Read; use Spreadsheet::ParseExcel; my $InputFile; Win32::LongPath::openL (\$InputFileReadable, '<', $InputFile); #opening XLS my $parser = Spreadsheet::ParseExcel->new(); my $workbook = $parser->parse($InputFileReadable); if ( defined $workbook ) { print "I could read the XLS file\n"; } #opening ODS my $workbook2 = ReadData ($InputFileReadable); if ( defined $workbook2 ) { print "I could read the ODS file\n"; }

Why is $workbook2 always undefined?

Replies are listed 'Best First'.
Re: Spreadsheet::Read Win32::LongPath::openL
by vr (Curate) on Dec 09, 2018 at 18:20 UTC

    It seems to have nothing to do with long paths or non-latin characters:

    use strict; use warnings; use feature 'say'; use Spreadsheet::Read; use Spreadsheet::ParseExcel; open my $h, '<', '1.ods'; # this file exists Spreadsheet::ParseExcel-> new-> parse( $h ); #### say 'eof' if eof $h; say 'ok' if defined ReadData( $h );

    says 'eof'. But if line marked with '###' is commented out, the output is

    Sorry, references as input are not (yet) supported by Spreadsheet::Rea +dSXC at xl.pl line 11.

    So, the reason that you can't supply filehandles to Spreadsheet::ReadSXC is because it doesn't support them. And there was no proper error reported for your example, because of this line -- and that line wasn't reached.

    Copying to a temporary safely named file can solve it:

    use strict;
    use warnings;
    use feature 'say';
    use utf8;
    use Spreadsheet::Read;
    use File::Temp;
    use Win32::LongPath;
    
    my $tmp = File::Temp-> new( SUFFIX => '.ods' )-> filename;
    
    copyL 'проверка.ods', $tmp;                 # this file exists
    
    say 'ok' if defined ReadData( $tmp );
    
    

      Thank you very much for the explanation. Good to know that Spreadsheet::ReadSXC does not accept filehandles. Your suggested solution works perfectly. Easy and efficient!

Re: Spreadsheet::Read Win32::LongPath::openL
by Tux (Canon) on Dec 09, 2018 at 16:47 UTC

    Can you add , debug => 9 to the ReadData (...) call to see where things actually fail?

    It'll also show you what parser is used to read the .ods file. That should be Spreadsheet::ReadSXC. If you do not have that installed, Spreadsheet::Read is unable to parse .ods files, whatever name or path you use.


    Enjoy, Have FUN! H.Merijn