in reply to Win32::OLE Excel Format problem
| A1 | B1 | C1 | |
|---|---|---|---|
| My Data: | 2.00 | 23.00% | 3.72E+04 |
The Code:
use Win32::OLE::Const 'Microsoft Excel'; $Win32::OLE::Warn = 2; # Don't Die on errors my $file = 'c:\perl\projects\excel\format.xls'; my $Excel = Win32::OLE->GetActiveObject('Excel.Application') || Win32::OLE->new('Excel.Application', 'Quit'); my $Book = $Excel->Workbooks->Open($file); my $Sheet = $Book->Worksheets("sheet1"); $Sheet->Activate(); my @ranges = qw(a1 b1 c1) ; foreach my $cell(@ranges){ my $format = $Sheet->Range($cell)->{NumberFormat}; print "$cell : $format\n"; } $Book = $Excel->Workbooks->Close(); undef $Excel
UPDATE: I just wanted to mention (now that I've had some sleep) that most of my experimentation was directed by examining the object model using the object browser in Visual Studio and the "MSDN Excel Visual Basic Reference"(tm). It was there that I noticed that both the Range object and the Stlye object both have a NumberFormat property. *sigh* If only there were notes on Precedence, and MS's "thinking" on it.
C-.
|
|---|