Title: Message

Bill,
Thanks for your feedbacks.  I was able to get pass that error message, but this message I am still stuck on:
"Can't call method "Cells" on an undefined value at c:\inetpub\wwwroot\trialmap\cgi-bin\standardQ.pl line 728."

Any ideas here,
Thanks,
David



use Win32::OLE;

my $path = 'fubar.xls';
unlink $path if (-e $path);

my $Class = "Excel.Application";
my $Excel = Win32::OLE->GetActiveObject($Class);
if (!$Excel) {
        $Excel = new Win32::OLE( $Class) ||
          die "Could not create an OLE '$Class' object";
}
my $Workbook = $Excel->Workbooks->Add();
$Excel->{SheetsInNewWorkbook} = 7;
$Excel->{DisplayAlerts} = 0;

$Excel->{Visible} = 1;

my @sheetName = qw(QvData QvSummary PidcData PidcSummary ScnrDscp
  SampleSummary FileSummary);
my @cols = qw(A B C D E F G);
my $numCol = scalar @cols;

my $numSheets = 7;
for (my $i = 0; $i < $numSheets; $i++) {

        my $sheet = $sheetName[($numSheets - $i - 1)];
        my $Worksheet = $Workbook->Worksheets($numSheets - $i); # name sheets
        $Workbook->Worksheets($numSheets - $i)->{Name} = $sheet;

        # write header row to excel
        my $row = 1; my $col = 'A';
        for (my $j = 1; $j < $numCol; $j++) {
                my $Cell = $Worksheet->Cells($row, $col);   ### Line 728 Error here
                $Cell->{Value} = $cols[$j];
                $col++;
        }
}



-----Original Message-----
From: $Bill Luebkert [mailto:[EMAIL PROTECTED]]
Sent: Monday, January 26, 2004 2:17 PM
To: Hsu, David
Subject: Re: Can't use an undefined value as a HASH reference when using W in32 ::OLE


Hsu, David wrote:

> Bill
> Why the '- 1' above ?
> Why not '$numsheets - $i' ?
> My sheet name is in an array and my $i starts at 0.  I am getting my last
> element first.

> Are you trying to re-order the sheets ?  Why not just:  my $sheet =
> $sheetName[$i];
> and the same below ? 
> I am populating the last sheet first with the data.

> Why not '- 1' on the lines below if you use it above ?
>  $Workbook->Worksheets($numSheets - $i)->{Name} = "$sheet";
> I am referencing the 7 sheets in the excel workbook.

I managed to get that error once, but can't reproduce.

I was playing with this loop :

        for (my $j = 1; $j < $numCol; $j++) {

which should start at 0 shouldn't it or change to <= ?

This code works for me:

use Win32::OLE;

my $path = 'fubar.xls';
unlink $path if (-e $path);

my $Class = "Excel.Application";
my $Excel = Win32::OLE->GetActiveObject($Class);
if (!$Excel) {
        $Excel = new Win32::OLE( $Class) ||
          die "Could not create an OLE '$Class' object";
}
my $Workbook = $Excel->Workbooks->Add();
$Excel->{SheetsInNewWorkbook} = 7;
$Excel->{DisplayAlerts} = 0;

$Excel->{Visible} = 1;

my @sheetName = qw(QvData QvSummary PidcData PidcSummary ScnrDscp
  SampleSummary FileSummary);
my @cols = qw(A B C D E F G);
my $numCol = scalar @cols;

my $numSheets = 7;
for (my $i = 0; $i < $numSheets; $i++) {

        my $sheet = $sheetName[($numSheets - $i - 1)];
        my $Worksheet = $Workbook->Worksheets($numSheets - $i); # name sheets
        $Workbook->Worksheets($numSheets - $i)->{Name} = $sheet;

        # write header row to excel
        my $row = 1; my $col = 'A';
        for (my $j = 1; $j < $numCol; $j++) {
                my $Cell = $Worksheet->Cells($row, $col);
                $Cell->{Value} = $cols[$j];
                $col++;
        }
}

__END__


--
  ,-/-  __      _  _         $Bill Luebkert    Mailto:[EMAIL PROTECTED]
 (_/   /  )    // //       DBE Collectibles    Mailto:[EMAIL PROTECTED]
  / ) /--<  o // //      Castle of Medieval Myth & Magic http://www.todbe.com/
-/-' /___/_<_</_</_    http://dbecoll.tripod.com/ (My Perl/Lakers stuff)

Reply via email to