å¨EXCELéæç¯å¢éé¢å·¥ä½ççç¼ç¨è¯è¨ï¼åªè½æ¯VBAï¼æ æ³ä½¿ç¨PHPãPERLãJAVAãCçå
¶å®è¯è¨ã
å¯ä»¥ä½¿ç¨VBAä¹å¤çå
¶å®è¯è¨æ¥å¼åEXCELåºç¨ï¼ä½æ¯ä¸è½å¨EXCELç¯å¢éé¢å¼ååè°è¯ï¼åªè½å¨å
¶å®è¯è¨éé¢å¼ååè°è¯ãå
¶å®è¯è¨æä½EXCELå¯ä»¥ä½¿ç¨OLE对象æ¥å®ç°ï¼ä»ä¸é¢çPERLä¾å代ç å¯ä»¥æç½æè·¯åæ¹æ³ï¼
#!/usr/bin/perl
use strict;
use warnings;
use Win32::OLE qw(in with);
use Win32::OLE::Const 'Microsoft Excel';
use Win32::OLE::NLS qw(:LOCALE :TIME);
my $Excel = Win32::OLE->GetActiveObject('Excel.Application')
|| Win32::OLE->new('Excel.Application', 'Quit');
my$excelfile='E:\å¦ä¹ ç¨åº\perl\excelfile.xls';
#å
³éè¦åä¿¡æ¯ï¼ä¾å¦ä¿åç,ä¸è·³åºç¡®è®¤çªå£
$Excel->{DisplayAlerts}=0;
#å建ä¸ä¸ªworkbook
#my $Book=$Excel->Workbooks->Add();
# $Book->SaveAs($excelfile); # å¢å ä¸ä¸ªworkbookï¼ç¶åä¿å
#ç´æ¥æå¼ä¸ä¸ªexcel è¥åå¨
my$Book=$Excel->Workbooks->Open($excelfile);
#å建ä¸ä¸ªworksheet对象
my $Sheet = $Book->Worksheets("Sheet1");
# $Sheet->Activate();
# $Sheet->{Name} = "DidItInPerl";
#æå
¥æ°æ®
my ($mday,$mon,$year) = (localtime(time))[3,4,5];
$year += 1900;
$mon += 1;
my $str = $year."/".$mon."/".$mday;
#Range è¡æ¹æ³
$Sheet->Range("C1")->{Value}=$str;
$Sheet->Range("D1")->{Value}="ä»å¤©çæ¥æ";
#è¿ä»£æå
¥æ°æ®
foreach my$x (1 ..50) {
my$range="A".$x;
$Sheet->Range($range)->{Value}="è¿æ¯ç¬¬$rangeè¡";
}
#循ç¯è®¿é®sheet
my $sheetcnt = $Book->Worksheets->Count();
foreach (1..$sheetcnt){
print "\t" .$Book->Worksheets($_)->{Name} ."\n";
}
foreach my $Sheet(in $Book->{Worksheets}){
print "\t" .$Sheet->{Name} ."\n";
}
#æ¾å°æåä¸è¡ æåä¸åæ¹æ³
my $LastRow = $Sheet->UsedRange->Find({What=>"*",
SearchDirection=>xlPrevious,
SearchOrder=>xlByRows})->{Row};
my $LastCol = $Sheet->UsedRange->Find({What=>"*",
SearchDirection=>xlPrevious,
SearchOrder=>xlByColumns})->{Column};
print "æåä¸å:",$LastCol,"\n";
print "æåä¸è¡:",$LastRow,"\n";
#读å第ä¸è¡å°æåä¸è¡æ°æ®
print "#" x80,"\n";
print "读åAå第ä¸è¡å°æåä¸è¡æ°æ®\n";
my$tmp;
foreach my$last_data (1..$LastRow) {
$tmp=$Sheet->Range("A".$last_data)->{Value};
print "第$last_dataè¡æ°æ®:",$tmp,"\n";
}