- or download this
#!c:\perl\bin\
use strict;
...
# expects that the programmer deals #
my $excelfile = '<MYPATH>\perltut.xls';
- or download this
my $Excel = Win32::OLE->GetActiveObject('Excel.Application')
|| Win32::OLE->new('Excel.Application', 'Quit');
- or download this
$Excel->{DisplayAlerts}=0;
- or download this
my $Book = $Excel->Workbooks->Add();
$Book->SaveAs($excelfile); #Good habit when working with OLE, save
+often.
- or download this
my $Book = $Excel->Workbooks->Open($excelfile);
- or download this
my $Sheet = $Book->Worksheets("Sheet1");
$Sheet->Activate();
$Sheet->{Name} = "DidItInPerl";
- or download this
my ($mday,$mon,$year) = (localtime(time))[3,4,5];
$year += 1900;
...
$Sheet->Range("a1")->{Value} = $str;
$Sheet->Range("c1")->{Value} = "This is a long piece of text";
- or download this
foreach my $y(1..56){
my $range = 'b'.$y;
...
}
#$Excel->ActiveSheet->Pictures->Insert(<PATH TO THE PIC>);
- or download this
my $dt = Variant(VT_DATE, $Sheet->Range("a1")->{Value});
...
#$Book->Save();
#$Book = $Excel->Workbooks->Close();
- or download this
my $sheetcnt = $Book->Worksheets->Count();
foreach (1..$sheetcnt){
print "\t" .$Book->Worksheets($_)->{Name} ."\n";
}
- or download this
foreach my $Sheet(in $Book->{Worksheets}){
print "\t" .$Sheet->{Name} ."\n";
}
- or download this
my $LastRow = $Sheet->UsedRange->Find({What=>"*",
SearchDirection=>xlPrevious,
...
my $LastCol = $Sheet->UsedRange->Find({What=>"*",
SearchDirection=>xlPrevious,
SearchOrder=>xlByColumns})->{Column};
- or download this
# Create the chart by dimension #
my $Chart = $Sheet->ChartObjects->Add(200, 200, 200, 200);
- or download this
$Chart->Chart->ChartWizard({Source =>$Sheet->Cells(1)});
$Chart->Chart->SeriesCollection(1)->{Values}= [19,3,24,56,34, 33
+, 16, 10, 3, 100];
- or download this
$Excel->Run($MacroName);
- or download this
with ($Sheet->PageSetup, Zoom => Variant(VT_BOOL, 0),
FitToPagesTall => 1, FitToPagesWide => 1,
Orientation => xlLandscape);
- or download this
my $Sheet = $Book->Worksheets->Add({After=>$Book->Worksheets($Book->Wo
+rksheets->{Count})}) or die Win32::OLE->LastError();
- or download this
my $Sheet = $Book->Worksheets->Add({Before=>$Book->Worksheets(1)}) or
+die Win32::OLE->LastError();
- or download this
my $Sheet = $Book->Worksheets->Add({After=>$Book->Worksheets("Sheet1")
+}) or die Win32::OLE->LastError();