0

我正在尝试使用 perl 脚本创建一个 excel 文件。
我按照教程编写了以下代码:

#!/usr/bin/perl

use strict;
use warnings;
use Excel::Writer::XLSX;
use Excel::Writer::XLSX::Utility;

my $workbook = Excel::Writer::XLSX->new( 'perl.xlsx' );    # Step 1
$worksheet = $workbook->add_worksheet('cc');                   # Step 2
$worksheet->write( 'A1', 'Hi Excel!' );  

但我收到以下错误:

Global symbol "$worksheet" requires explicit package name at test_excel.pl line 10.
Global symbol "$worksheet" requires explicit package name at test_excel.pl line 11.
4

1 回答 1

5

你需要声明$worksheet变量,像这样

my $worksheet = $workbook->add_worksheet('cc');                   # Step 2
于 2020-02-20T12:00:13.733 回答