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

I have abandoned my silly script from before since I found there is an xls2csv function in the Spreadsheet::XLSX::Utility module. Thanks for putting up with the previous post.

Question: I'm trying to call the xls2csv function from this module but it is unexported. How does one do this properly? Right now I'm getting the error: "Tk::Error: Undefined subroutine &main::xls2csv called at name of my script.pl line 33."

I found what I thought was an answer on the Web so I tried defining the function as "Spreadsheet::XLSX::Utility::xls2csv" but that gave me basically the same error:"Tk::Error: Undefined subroutine &Spreadsheet::XLSX::Utility::xls2csv name of my script.pl line 33.

Thanks in advance. Short script is below.

#!/usr/local/bin/perl use Spreadsheet::XLSX::Utility2007; use Tk; my $mw = new MainWindow; my $mbar = $mw -> Menu(); $mw -> configure(-menu => $mbar); my $file = $mbar -> cascade(-label=>"File", -underline=>0, -tearoff => + 0); $file -> checkbutton(-label =>"Open", -underline => 0, -command => [\&menuopenClicked, "Open"]); $file -> command(-label =>"Save", -underline => 0, -command => [\&menusavedClicked, "Save"]); $file -> separator(); $file -> command(-label =>"Exit", -underline => 1, -command => sub { exit } ); MainLoop; sub menuopenClicked { my $typesopen = [ ['Excel 2007 files', '.xlsx'], ['All files', '*'],]; my $mainfilepath = $mw->getOpenFile(-filetypes => $typesop +en, -defaultextension => '.xlsx'); my $sFileName = $mainfilepath ; my $sRegion = '1-A1:G:110' ; my $iRotate = 1; my $sCsvTxt = xls2csv($sFileName, $sRegion, $iRotate); sub menusavedClicked { my $typesaved = [ ['Excel 2007 files', '.xlsx'], ['All files', '*'],]; my $saved = $mw->getSaveFile(-filetypes => $typessaved, -defaultextension => '.csv'); open($saved, "> $saved") || die "Can't create <$saved> for output!\n"; print ($saved $sCsvTxt) if $saved; close $saved; }}

Replies are listed 'Best First'.
Re: How Do You Call a Non-Exported Function from a Module?
by almut (Canon) on Apr 10, 2009 at 22:20 UTC
Re: How Do You Call a Non-Exported Function from a Module?
by FunkyMonk (Bishop) on Apr 10, 2009 at 22:24 UTC
    I've never used this module, but it looks like the documentation is wrong. If you look at the source, you'll see the the package is called Spreadsheet::XLSX::Utility2007, not Spreadsheet::XLSX::Utility. I think you should be able to use
    use Spreadsheet::XLSX::Utility2007 qw(ExcelFmt ExcelLocaltime Localtim +eExcel xls2csv);

    instead

      Then you'd think that use Spreadsheet::XLSX::Utility ...; would give an error long before reaching the call to xls2csv.
        Yes I would.

        The synopsis for Spreadsheet::XLSX::Utility2007 starts wth

        use Spreadsheet::XLSX::Utility qw(ExcelFmt ExcelLocaltime LocaltimeExc +el);

        but the source code in http://cpansearch.perl.org/src/DMOW/Spreadsheet-XLSX-0.1/lib/Spreadsheet/XLSX/Utility2007.pm says

        package Spreadsheet::XLSX::Utility2007; #some stuff @EXPORT_OK = qw(ExcelFmt LocaltimeExcel ExcelLocaltime col2int int2col + sheetRef xls2csv);

        So, no, I don't know why the OP didn't get a "Can't locate ... in @INC" error :(

Re: How Do You Call a Non-Exported Function from a Module?
by ikegami (Patriarch) on Apr 10, 2009 at 22:12 UTC
    Like the message says, there's is no such sub in that namespace.

    And since I can't find such a module, I can't guess as to why you think there should be.