Loading ...
Sorry, an error occurred while loading the content.
 

Re: [PBML] Reading Excel files

Expand Messages
  • Peter Dominey
    Hi, I just recently did some code for a customer that needed to bring in information from an Excel s/sheet. I used the module Spreadsheet . Here s a piece of
    Message 1 of 2 , Jun 2 6:15 AM
      Hi,

      I just recently did some code for a customer that needed to bring in
      information from an Excel s/sheet. I used the module 'Spreadsheet'. Here's
      a piece of the code reading it in:

      ...."
      use Spreadsheet::ParseExcel;

      my $oExcel = new Spreadsheet::ParseExcel;
      my $oBook = $oExcel->Parse($ARGV[0]);
      my($iR, $iC, $oWkS, $oWkC);

      print "Working from FILE : ", $oBook->{File} , "\n";
      print " COUNT : ", $oBook->{SheetCount} , "\n";
      print " AUTHOR: ", $oBook->{Author} , "\n" if defined
      $oBook->{Author};
      print " Number of somethings: ", $oWkS->{RowCount}, "\n";
      print "\n";

      for(my $iSheet=0; $iSheet lt $oBook->{SheetCount} ; $iSheet++){
      $oWkS = $oBook->{Worksheet}[$iSheet];
      for(my $iR = $oWkS->{MinRow} ; defined $oWkS->{MaxRow} && $iR <= $oWkS->{MaxRow} ; $iR++){
      for(my $iC = $oWkS->{MinCol} ; defined $oWkS->{MaxCol} &&
      $iC <= $oWkS->{MaxCol} ; $iC++) {
      $oWkC = $oWkS->{Cells}[$iR][$iC];
      $airbill = $oWkC->Value;
      if ( $something =~ /^(\d+\.?\d*|\.\d+)$/ ){
      print "( $iR , $iC ) =>", $oWkC->Value, "\n",
      ..........."

      Hope this is of some help

      Thanks

      Peter


      On Thu, 2 Jun 2005, rhug505456 wrote:

      > Greetings,
      >
      > I am trying to read an Excel file. My environment is Windows XP -
      > SP2 and Excel is from Office 2003. I have taken the code from the
      > Active State Website, and am trying to read a file called
      > text1.xls. I get an error message:
      >
      > Win32::OLE(0.1701}error 0x800a03ec
      > in METHOD/PROPERTYGET "Open" at win32excel.pl line 10
      >
      > This is the code:
      >
      > #!/usr/bin/perl -w
      >
      > use strict;
      > use Win32::OLE qw(in with);
      > use Win32::OLE::Const 'Microsoft Excel';
      > $Win32::OLE::Warn = 3; # die on
      > errors...
      > my $Excel = Win32::OLE->GetActiveObject('Excel.Application')
      > || Win32::OLE->new('Excel.Application', 'Quit'); # get already
      > active Excel
      > # application
      > or open new
      > my $Book = $Excel->Workbooks->Open("test1.xls"); # open Excel file
      > my $Sheet = $Book->Worksheets(1); # select
      > worksheet number 1
      > my $array = $Sheet->Range("A8:B9")->{'Value'}; # get the
      > contents
      > $Book->Close;
      > foreach my $ref_array (@$array) { # loop through
      > the array
      > # referenced
      > by $array
      > foreach my $scalar (@$ref_array) {
      > print "$scalar\t";
      > }
      > print "\n";
      > }
      >
      > Line 10 is this: my $Book = $Excel->Workbooks->Open("test1.xls"); #
      > open Excel file
      >
      > Could someone kick me in the right direction?
      >
      > Thanks for the help.
      >
      > Richard Hug
      >
      >
      >
      >
      >
      > Unsubscribing info is here: http://help.yahoo.com/help/us/groups/groups-32.html
      > Yahoo! Groups Links
      >
      >
      >
      >
      >
      >
      > ----------------------------------------
      > Scanned for Viruses! mail.dominey.biz
      >
      > ----------------------------------------
      > Scanned for Viruses! mail.dominey.biz
      >
      > ----------------------------------------
      > Scanned for Viruses! mail.dominey.biz
      >
      > ----------------------------------------
      > Scanned for Viruses! mail.dominey.biz
      >

      --

      +-------------------------------------------------------------------+
      | P J Dominey |
      | Independent UNIX Contractor |
      | |
      | E-Mail: pdominey@... |
      | Web Site: www.dominey.biz |
      | Tel: 817-488-5957 Yahoo IM: pdominey |
      +-------------------------------------------------------------------+

      ----------------------------------------
      Scanned for Viruses! mail.dominey.biz

      ----------------------------------------
      Scanned for Viruses! mail.dominey.biz
    • rhug505456
      Greetings, I am trying to read an Excel file. My environment is Windows XP - SP2 and Excel is from Office 2003. I have taken the code from the Active State
      Message 2 of 2 , Jun 2 6:36 AM
        Greetings,

        I am trying to read an Excel file. My environment is Windows XP -
        SP2 and Excel is from Office 2003. I have taken the code from the
        Active State Website, and am trying to read a file called
        text1.xls. I get an error message:

        Win32::OLE(0.1701}error 0x800a03ec
        in METHOD/PROPERTYGET "Open" at win32excel.pl line 10

        This is the code:

        #!/usr/bin/perl -w

        use strict;
        use Win32::OLE qw(in with);
        use Win32::OLE::Const 'Microsoft Excel';
        $Win32::OLE::Warn = 3; # die on
        errors...
        my $Excel = Win32::OLE->GetActiveObject('Excel.Application')
        || Win32::OLE->new('Excel.Application', 'Quit'); # get already
        active Excel
        # application
        or open new
        my $Book = $Excel->Workbooks->Open("test1.xls"); # open Excel file
        my $Sheet = $Book->Worksheets(1); # select
        worksheet number 1
        my $array = $Sheet->Range("A8:B9")->{'Value'}; # get the
        contents
        $Book->Close;
        foreach my $ref_array (@$array) { # loop through
        the array
        # referenced
        by $array
        foreach my $scalar (@$ref_array) {
        print "$scalar\t";
        }
        print "\n";
        }

        Line 10 is this: my $Book = $Excel->Workbooks->Open("test1.xls"); #
        open Excel file

        Could someone kick me in the right direction?

        Thanks for the help.

        Richard Hug
      Your message has been successfully submitted and would be delivered to recipients shortly.