Perl中的Excel - Spreadsheet :: WriteExcel

时间:2013-11-10 15:08:43

标签: excel perl spreadsheet

use strict;
use lib qw(./lib);
use Spreadsheet::WriteExcel;
use Math::Random qw(:all);


    $worksheet->write(0, 0, "Zahl", $format); 
    $worksheet->write(0, 1, "Vorkommt",$bold);

    my @rand_arr = map int,random_normal(10,5,5);

    my ($temp,$count) = ("@rand_arr", 0);   
    ($count = $temp =~ s/($_)//g) and printf "%2d:%s vor.\n", $_,$count for @rand_arr;

    $worksheet->write(1, 0, "$_");
    $worksheet->write(1, 1, "$count");


    $workbook->close();

    print "\n";

如果你这样做,你会在终端获得良好的输出,但我想要做的是,在Excel中获得相同的输出,我认为我的问题在这里

$worksheet->write(1, 0, "$_");
$worksheet->write(1, 1, "$count"); 

我不知道如何让excel单独使用$ ROW ++ ..

1 个答案:

答案 0 :(得分:1)

我不确定你的终端代码输出是做什么的 - 它看起来很奇怪。

也许你只是想要:

for my $row (0..$#rand_arr) {
    $worksheet->write($row+1, 0, $row);
    $worksheet->write($row+1, 1, $rand_arr[$row]);
}