Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用perl excel win32 ole检索excel单元格背景色_Perl_Excel_Win32ole - Fatal编程技术网

使用perl excel win32 ole检索excel单元格背景色

使用perl excel win32 ole检索excel单元格背景色,perl,excel,win32ole,Perl,Excel,Win32ole,我需要检索excel单元格的背景色(根据工作表中的条件格式设置为红色/绿色)。尝试搜索论坛,但找不到任何可检索的内容,尽管设置了颜色。 非常感谢您的帮助……您需要$Range->Interior()->ColorIndex() 以下是示例程序: #!/usr/bin/perl use Modern::Perl; use Win32::OLE; use FindBin qw($Bin); my $ex; eval { $ex = Win32::OLE->GetActiveObject('

我需要检索excel单元格的背景色(根据工作表中的条件格式设置为红色/绿色)。尝试搜索论坛,但找不到任何可检索的内容,尽管设置了颜色。
非常感谢您的帮助……

您需要
$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 $@;
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