[EMAIL PROTECTED] wrote:
Since I'm still rather new, I was wondering if anyone with more experience
than I could answer a question before i test it and possibly ruin data.
On an existing workbook with two or more sheets, is it possible to select
a specific sheet by name or create a new one:
IE: i need to collect information daily and dump it into file.xls, would
this code work to use the existing page for the day if it is there or make
it and use it if not?
my $ws = $report->Worksheets("$date - General");
if not, how would i go about testing for a particular sheet and create it
if not? i assume creation would look something like
my $ws = $workbook -> Worksheets(1);
$ws -> { 'Name' } = "$date - General";
<-snip->
When I was at about where you are with Excel/OLE a few months
back, I got a whole lot of help from both the archives and
knowlegeable contributors over at
microsoft.public.excel and microsoft.public.excel.programming
Converting VBE code to perl is quite easy...even easier with
Activestate's PDK VBScript convertor - AFAIK it comes with the
downloadable demo.
Searching the MPE groups for 'worksheet exist' will turn
up a whole lot of answers most relying on the VB 'on error resume next'
for which I never found a Win32::OLE equivalent.
Keep searching though, and eventually you'll come across
the idea of looping thru all the sheets in the book
and testing to see if the sheet name matches the one you are
looking for, which won't (shouldnt...) throw an error.
Something like (untested)
sub worksheetExists
{
my $tst = shift;
for my $a(1 .. $workbook->Sheets->Count)
{
if ($workbook->Sheets($a)->Name eq $tst)
{
return 1;
}
}
return 0;
}
Remember also the Excel VBE/Macro Editor, macro recorder
and Object Browser built right into Excel. Record a macro as you
create and position a new worksheet in a book to get to
what you need to perform in perl.
HTH - Lynn.
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs