当我尝试使用 Perl 的 Win32::OLE 设置 Excel 中单元格的值时,为什么会出现异常?

发布于 2024-09-11 11:18:34 字数 532 浏览 1 评论 0原文

我收到错误 Win32::OLE<0.1709>错误 0x80020009:第 109 行 PROPERTYPUT“Value” 中“发生异常”。

代码为 Perl。

foreach my $ref_array1 (@$array1) {     # loop through the array
 foreach my $col1 (@$ref_array1) {     
   foreach my $ref_array2 (@$array2) {     # loop through the array   
     foreach my $col2 (@$ref_array2) {      
       if ($col1 eq $col2)
        {

             this is line 109: **$worksheet1->Cells($j,1)->{'Value'} = $col1;**

             $j++;

任何形式的帮助表示赞赏。 谢谢

I am getting the error Win32::OLE<0.1709> error 0x80020009: "Exception occurred" in PROPERTYPUT "Value" at line 109.

The code in is Perl.

foreach my $ref_array1 (@$array1) {     # loop through the array
 foreach my $col1 (@$ref_array1) {     
   foreach my $ref_array2 (@$array2) {     # loop through the array   
     foreach my $col2 (@$ref_array2) {      
       if ($col1 eq $col2)
        {

             this is line 109: **$worksheet1->Cells($j,1)->{'Value'} = $col1;**

             $j++;

Any kind of help is appreciated.
Thankyou

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

凡尘雨 2024-09-18 11:18:34

以下不完整的示例有效(即,它将 5 放入单元格 A1 中):

#!/usr/bin/perl

use strict; use warnings;

use Win32::OLE qw(in with);
use Win32::OLE::Const 'Microsoft Excel';
$Win32::OLE::Warn = 3;

my $excel = get_excel();
$excel->{Visible} = 1;

my $book = $excel->Workbooks->Add;
my $sheet = $book->Worksheets->Add;
$sheet->{Name} = 'Perl Win32-OLE Example';

my $range = $sheet->Cells(1,1);
$range->{Value} = 5;
$range->AutoFormat;

sub get_excel {
    my $excel;

    unless ( eval {
            $excel = Win32::OLE->GetActiveObject('Excel.Application')
    }) {
        die $@, "\n";
    }

    unless(defined $excel) {
        $excel = Win32::OLE->new('Excel.Application', sub { $_[0]->Quit })
            or die "Oops, cannot start Excel: ",
                   Win32::OLE->LastError, "\n";
    }
    return $excel;
}

另请参阅我的 Perl Win32::OLE 示例

The following incomplete example works (i.e., it puts 5 in cell A1):

#!/usr/bin/perl

use strict; use warnings;

use Win32::OLE qw(in with);
use Win32::OLE::Const 'Microsoft Excel';
$Win32::OLE::Warn = 3;

my $excel = get_excel();
$excel->{Visible} = 1;

my $book = $excel->Workbooks->Add;
my $sheet = $book->Worksheets->Add;
$sheet->{Name} = 'Perl Win32-OLE Example';

my $range = $sheet->Cells(1,1);
$range->{Value} = 5;
$range->AutoFormat;

sub get_excel {
    my $excel;

    unless ( eval {
            $excel = Win32::OLE->GetActiveObject('Excel.Application')
    }) {
        die $@, "\n";
    }

    unless(defined $excel) {
        $excel = Win32::OLE->new('Excel.Application', sub { $_[0]->Quit })
            or die "Oops, cannot start Excel: ",
                   Win32::OLE->LastError, "\n";
    }
    return $excel;
}

See also my Perl Win32::OLE example.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文