2013-07-08 192 views

回答

2

你需要$Range->Interior()->ColorIndex();

下面是示例程序:

#!/usr/bin/perl 

use Modern::Perl; 
use Win32::OLE; 
use FindBin qw($Bin); 

my $ex; 
eval { $ex = Win32::OLE->GetActiveObject('Excel.Application') }; 
die "Excel not installed" if [email protected]; 
unless (defined $ex) { 
    $ex = Win32::OLE->new('Excel.Application', sub { $_[0]->Quit; }) 
     or die "Oops, cannot start Excel"; 
} 

my $book = $ex->Workbooks->Open("$Bin/test_background.xls"); 

my $sheet = $book->Worksheets(1); 
my $Range = $sheet->Range("A1:A1"); 
say $Range->Interior()->ColorIndex(); 

$Range = $sheet->Range("B1:B1"); 
say $Range->Interior()->ColorIndex(); 

$Range = $sheet->Range("C1:C1"); 
say $Range->Interior()->ColorIndex(); 

此文件enter image description here 輸出是這樣的:

3 
6 
3 
+0

感謝。但正如我所提到的,顏色是基於條件格式設置的。這也會爲此工作嗎? – Siva

+0

嗯......我不確定,但你可以試試。 – gangabass

相關問題