Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Help with Excel::Table

by Athanasius (Archbishop)
on Sep 25, 2020 at 15:08 UTC ( [id://11122206]=note: print w/replies, xml ) Need Help??


in reply to Help with Excel::Table

Hello BernieC,

It looks like there’s a mismatch between (1) the regular expression used to separate directory and filename, and (2) the actual input. The regex /(.*)\/(.*)/ splits on a forward slash, but the input contains either a backslash (from the error message) or no slash at all (from the specified input: getWB("D:myexcel.xlsx")).

It’s safer to use the core module File::Basename here:

my ($dir, $excel) = fileparse($_[0]);

Whether this is your real problem, I don’t know, but at the least it’ll remove one layer of possible confusion as you seek to debug the problem. In that case, the monks will require more information — preferably in the form of an SSCCE — to be able to assist with the debugging process.

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Replies are listed 'Best First'.
Re^2: Help with Excel::Table
by BernieC (Pilgrim) on Sep 25, 2020 at 20:19 UTC
    The forward slash to backslash is the way things work on windows -- I always use forward slashes in path names and Perl happily flips them to backslashes when it talks to the windows. The program {as y'all will see} shows what the parse returned and that's exactly right. I put in the 'open' to double-check that the hardwired excel path was correct.

    I neglected to include that this is with Strawberry Perl running on a win10/64 system. Here's the little test program:

    #!/usr/bin/perl use v5.10 ; use strict; use warnings ; use Excel::Table ; use constant WORKBOOK => "d:/desktop/testWB.xlsx" ; # test if the path works open(P, "<", WORKBOOK) or die "Can't find the workbook: $!\n" ; close P ; my $xs = getWB(WORKBOOK) ; exit ; sub getWB { my ($dir, $wb) = $_[0] =~ /(.*)\/(.*)/ ; say "Directory is $dir" ; say "Excel file is $wb" ; my $xs = Excel::Table->new(dir => $dir) ; $xs->open($wb) ; return $xs ; }
    I don't know how to upload the Excel worksheet that the file needs {anything will do, since I am only trying to open it and {for the nonce} don't care about whats *in* the file}, but when I run the program I get.
    d:\Desktop>testWb.pl Directory is d:/desktop Excel file is testWB.xlsx Log4perl: Seems like no initialization happened. Forgot to call init() +?

      Thanks for the SSCCE. As toolic says, the error (really just a warning) message appears to relate to Log::Log4perl; the Excel workbook is being opened correctly.

      The example code in the SYNOPSIS section of the documentation for Excel::Table doesn’t seem to work for me. If you have difficulty using this module, you’ll probably be better off directly using Spreadsheet::XLSX — which you already have, since it’s used by Excel::Table!

      Cheers,

      Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

        Thanks for the update. It hadn't occurred to me that the "warning" was nothing, I guess it'd be a bug in Excel::Table -- it isn't calling the log4perl->init {or easy_init()} What attracted me to Excel::Table is that it does exactly what I want: turns workshets into arrays. I'll investigate Spreadsheet::XLSX. Thanks!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (6)
As of 2024-04-18 21:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found