2
我需要检索excel单元格的背景颜色(根据表单中的条件格式设置为红色/绿色)。尝试搜索论坛,但无法找到任何东西来检索,虽然设置颜色在那里。 任何帮助,将不胜感激......使用Perl获取excel单元格背景颜色excel win32 ole
我需要检索excel单元格的背景颜色(根据表单中的条件格式设置为红色/绿色)。尝试搜索论坛,但无法找到任何东西来检索,虽然设置颜色在那里。 任何帮助,将不胜感激......使用Perl获取excel单元格背景颜色excel win32 ole
你需要$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();
此文件 输出是这样的:
3
6
3
感谢。但正如我所提到的,颜色是基于条件格式设置的。这也会为此工作吗? – Siva
嗯......我不确定,但你可以试试。 – gangabass