使用Perl脚本创建的Excel修剪前缀零

时间:2014-05-30 12:49:36

标签: perl

我使用Perl创建了一个脚本,它将CSV文件转换为Excel。但是excel修剪了第一个零。但输出文件中必须为零。以下是我做的代码

my $workbook  =  Spreadsheet::WriteExcel->new("$pipeline_project_temp\\$without_extension.xls");

my $worksheet = $workbook->add_worksheet();

$outfilename = "$without_extension.xls";
# Create a new CSV parsing object
my $csv = Text::CSV_XS->new;

# Row and column are zero indexed
my $row = 0;

my $line_content = "";
while (<CSVFILE>) {
    $line_content = $_;
    $line_content !~ s/[^[:ascii:]]//g;
    if ($csv->parse($line_content)) {
        my @Fld = $csv->fields;

        my $col = 0;
        foreach my $token (@Fld) {
            $worksheet->write($row, $col, $token);
            $col++;
        }
        $row++;
    }
    else {
        my $err = $csv->error_input;
        print "Text::CSV_XS parse() failed on argument: ", $err, "\n";
    }
}

044444将转换为44444.我可以使用一些可以将INT转换为String的逻辑吗?

1 个答案:

答案 0 :(得分:5)

记录了

keep_leading_zeros