我有一个以下格式的Excel文件:
Own,Test,Yes,No
ngh,y,4,3
我有一个foreach循环,可以打印出要添加到excel文件底部的代码行:
foreach my $val(sort keys %hash) {
my $own = $hash{$val}{own};
my $test = $hash{$val}{test};
my $yes = $hash{$val}{yes};
my $no = $hash{$val}{no};
print "$own, $test, $yes, $no\n";
}
我的foreach打印以下内容:
dfg,n,6,3
hgf,y,7,4
jsd,n,4,2
lbg,y,7,1
nyg,n,7,6
我想附加此打印语句以在excel表格的末尾打印,以便excel表格如下所示:
Own,Test,Yes,No
ngh,y,4,3
dfg,n,6,3
hgf,y,7,4
jsd,n,4,2
lbg,y,7,1
nyg,n,7,6
我一直在尝试使用WriteExcel
和ParseExcel
,但是我什么也没能打印到excel工作表中。任何指导将不胜感激。
foreach my $val(sort keys %hash) {
my $own = $hash{$val}{own};
my $test = $hash{$val}{test};
my $yes = $hash{$val}{yes};
my $no = $hash{$val}{no};
my $file = "/C:/programs/Desktop/lsa/test.xlsm";
my $workbook = Excel::Writer::XLSX->new($file);
open (my $fh, '>>', $file) or warn "cant open";
print $fh "$own,$test,$yes,$no\n";
}