[Perl][Win32::OLE]判断单元格是否为合并单元格

There's more than one way to do it!
https://metacpan.org http://perlmonks.org
回复
头像
PerlMonk
渐入佳境
渐入佳境
帖子: 49
注册时间: 2016年09月19日 10:20
联系:

[Perl][Win32::OLE]判断单元格是否为合并单元格

帖子 PerlMonk »

$o = $sheet->Cells(1, 2)->{'MergeCells'};

是合并单元格时返回1,不是时返回0
use Win32::OLE qw (in with);
use Win32::OLE::Const ('Microsoft Excel');
use Win32::OLE::Variant;
use Cwd;
use Encode;
use IO::Handle;
STDOUT->autoflush(1);

my $fold = getcwd(); #完整路径
$fold=~s/\//\\/;

our $ex;
our $book;
our $sheet;

load_sheet( $fold ."\\info.xlsx", 2 ); #文件名,sheet表的编号

my $o = $sheet->Cells(1, 2); #row, column
print $o->{'MergeCells'};


print $sheet->Cells(1, 2)->{'MergeCells'};

over();
exit;

sub load_sheet
{
my ($file, $sh_num) = (shift, shift);

# use existing instance if Excel is already running
eval { $ex = Win32::OLE->GetActiveObject('Excel.Application') };

die "Excel not installed" if $@;
unless (defined $ex)
{
$ex = Win32::OLE->new('Excel.Application', sub {${file}->Quit;})
or die "Oops, cannot start Excel";
}

# get a new workbook
$book = $ex->Workbooks->open( $file );

# write to a particular cell
$sheet = $book->Worksheets( $sh_num );
}

sub over
{
# save and exit
$ex->{DisplayAlerts} = 'False';
$book->Save();
undef $sheet;
undef $book;
undef $ex;
}
回复

在线用户

正浏览此版面之用户: 没有注册用户 和 4 访客