First, I would suggest that you get the book "Excel 2003 VBA Programmer's Reference" by Wiley Publishing. 1100+ pages that still doesn't cover everything.. And yes, you must mentally translate VBA to Perl "on the fly" as you read it. But you'll also find that it's useful when you have to create Excel functions / "macros" that can be executed by the end user of the worksheets you create with Perl and Win32::OLE.
I think I can explain the subtle differences here...
"$cell" is created as a reference to a Range object. "$Sheet->Cells(1,1)" returns a Range object that contains just a single cell. One of the properties of a Range object is Name object -- which is a variant. This corresponds to a named range in Excel. One of the properties of a Name object is the "Name" string.
So "$cell->{Name}" refers to the Name object of the Range object referenced by "$cell". "$cell->{Name}{Name}" or "$cell->{Name}->{Name}" refers to the "Name" string of the Name object of the Range object referenced by "$cell".
I'm guessing that the assignment, "$cell->{'Name'} = 'mycell';" effectively casts the right hand side value (rval) as a Name variant and then assigns the Name variant's Name property as the string 'mycell'.
One of the properties of a Worksheet object and a Workbook object is a Name string. The difference is that the Name property of a worksheet object and a workbook object is a simple string. Whereas the Name property of a Range object is a Name object / variant. So "$Sheet->{Name}" and "$Book->{Name}" return simple string values -- whereas "$cell->{Name}" returns a Name object / variant.
Regards,
... Dewey
[EMAIL PROTECTED] wrote on 05/14/2006 09:53:26 PM:
> Hi Bill,
>
> It worked! Your suggestion worked! Thank you very much. But I don't understand
> why the syntax has to be different for the cell name. Maybe I'll come to know
> as I go along. Thanks so much.
>
> jagdish eashwar
>
> Quoting $Bill Luebkert <[EMAIL PROTECTED]>:
>
> > jagdish eashwar wrote:
> >
> > > Hi,
> > >
> > > I am unable to get the name of the cells in my excel worksheet though
> > I can get those of my workbook and my worksheet. I have named my
> > workbook as 'myworkbook', my worksheet as 'myworksheet, and cell A1 as
> > 'mycell'.I am using the following code:
> > >
> > > use warnings;
> > > use strict;
> > >
> > > use Win32::OLE qw(in with);
> > > use Win32::OLE::Const 'Microsoft Excel';
> > > use Win32::OLE::Variant;
> > > use Win32::OLE::NLS qw(:LOCALE :DATE);
> > >
> > > $Win32::OLE::Warn = 3; # Die on Errors.
> > >
> > > my $Excel = Win32::OLE->new('Excel.Application', 'Quit');
> > >
> > > $Excel->{DisplayAlerts}=0;
> > >
> > > my $Book = $Excel->Workbooks->Add();
> > > my $Sheet = $Book->Worksheets(1);
> > > $Sheet->Activate();
> > > $Sheet->{'Name'} = "myworksheet";
> > >
> > > my $cell = $Sheet->Cells(1,1);
> > > $cell->{'Name'} = 'mycell';
> > > $Book->SaveAs('myworkbook');
> > > print "My workbook name is $Book->{Name}n";
> > > print "My worksheet name is $Sheet->{Name}n";
> > > print "My cell name is $cell->{Name}n";
> > > $Book->Save;
> > >
> > > #End of script
> > >
> > > The output I am getting is :
> > >
> > > My workbook name is myworkbook.xls
> > > My worksheet name is myworksheet
> > > My cell name is Win32::OLE=HASH(0x1ce747c)
> > >
> > > Why am I unable to get the cell name?
> >
> > Not sure why, but try:
> > print "My cell name is $cell->{Name}{Name}n";
> >
>
> _______________________________________________
> Perl-Win32-Users mailing list
> [email protected]
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
_______________________________________________ Perl-Win32-Users mailing list [email protected] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
