Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Win32-OLE, excel, and empties.

Reply
Thread Tools

Win32-OLE, excel, and empties.

 
 
Richard S Beckett
Guest
Posts: n/a
 
      07-11-2003
Hello World!

I'm trying to find the first empty row in a spreadsheet.

If I use this:

my $EmptyRow = $sheet->UsedRange->rows->count;
$EmptyRow ++;

It works, UNLESS the spreadsheet is empty, where the first line returns 1,
and I end up writing to row 2 instead of row 1.

If I use this:

my $EmptyRow = $sheet->UsedRange->Find({What=>"*",
SearchDirection=>xlPrevious,
SearchOrder=>xlByRows})->{Row};
my $err = Win32::OLE::LastError();
unless ($err eq 0) {$EmptyRow = 0;}
$EmptyRow ++;

This also works, unless the spreadsheet is empty, where I get the following
error:

Can't use an undefined value as a HASH reference at D:\Script.pl line 43,
<FILE> line 167.

Line 43 is:

my $LastRow = $sheet->UsedRange->Find({What=>"*",

and I only have 127 lines.

Can someone help me out, please?

Thanks.

R.


 
Reply With Quote
 
 
 
 
Jay Tilton
Guest
Posts: n/a
 
      07-11-2003
"Richard S Beckett" <(E-Mail Removed)> wrote:

: I'm trying to find the first empty row in a spreadsheet.

: If I use this:
:
: my $EmptyRow = $sheet->UsedRange->Find({What=>"*",
: SearchDirection=>xlPrevious,
: SearchOrder=>xlByRows})->{Row};
: my $err = Win32::OLE::LastError();
: unless ($err eq 0) {$EmptyRow = 0;}
: $EmptyRow ++;
:
: This also works, unless the spreadsheet is empty, where I get the following
: error:
:
: Can't use an undefined value as a HASH reference at D:\Script.pl line 43,
: <FILE> line 167.

Just make sure the Find() method returns a defined value before trying
to use it as a hash reference.

my $search = $sheet->UsedRange
->Find({
What=>"*",
SearchDirection=>xlPrevious,
SearchOrder=>xlByRows
});
my $EmptyRow = 1 + (defined $search && $search->{Row});

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
if and and vs if and,and titi VHDL 4 03-11-2007 05:23 AM



Advertisments