簡體   English   中英

當我嘗試使用Perl的Win32 :: OLE在Excel中設置單元格的值時,為什么會出現異常?

[英]Why am I getting an exception when I try to set the value of a cell in Excel using Perl's Win32::OLE?

我收到錯誤Win32::OLE<0.1709> error 0x80020009: "Exception occurred" in PROPERTYPUT "Value"的第109行Win32::OLE<0.1709> error 0x80020009: "Exception occurred" in 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++;

任何幫助都將受到贊賞。 謝謝

以下不完整示例有效(即,將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示例

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM