On Fri, 11 Jul 2003, Beckett Richard-qswi266 wrote: > Guys, > > I have sorted out what the problems are, I just don't know how to address > them. > > I am trying to find the first empty row in a spreadsheet. > > If I use this suggestion: > > my $EmptyRow = $sheet->UsedRange->rows->count; > $EmptyRow++; > > This points $LastRow to the first empty row of the spreadsheet, UNLESS the > spreadsheet is totally empty. Then, the first line returns a 1, and so I > write into row 2 by mistake. > > > This suggestion: > > my $EmptyRow = $sheet->UsedRange->Find({What=>"*", > SearchDirection=>xlPrevious, > SearchOrder=>xlByRows})->{Row}; > $EmptyRow++; > > Will again point $LastRow at the first empty row, UNLESS the spreadsheet is > totally empty, when it causes the script to die with... > > Can't use an undefined value as a HASH reference at D:\PR.pl line 43, <FILE> > line 167. > Win32::OLE(0.1502) error 0x80010108: "The object invoked has disconnected > from its clients" in METHOD/PROPERTYGET "" at D:\PR.pl line 119 > > > So, either I need to be able to test for an empty spreadsheet, or I need to > catch the error generated, and set the value of $LastRow to 0. > > Unfortunately, both options are beyond me. >
For an empty spreed sheet, it _may_ be that the UsedRange property is undefined. That seems both logical a reasonable to me. It that is correct then you could check for this condition by: if (ref($sheet->UsedRange) eq "Win32::OLE") { # sheet not empty .. .. } else { $EmptyRow=1; } **** [EMAIL PROTECTED] <Carl Jolley> **** All opinions are my own and not necessarily those of my employer **** _______________________________________________ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs