打开使用Spreadsheet :: WriteExcel创建的电子表格时出现文件错误

时间:2015-06-23 11:39:45

标签: excel perl

我正在使用Spreadsheet::WriteExcel使用perl创建xls文件。当电子表格的范围增加时,Microsoft Excel会在打开文件之前显示警告" 文件错误:数据可能已丢失"。

请帮我解决这个问题。

这是代码

my $row = 2;
foreach my $sid(array of students objects)
{
        my $s = $students->{$sid};
    my $cc = 0;
my $wall = f1($x, $y, $z);#f1 is a method returns hash of arrays that have to write on excel having keys @key_array
foreach my $key (@key_array) {
my $t_row = $row;
my $i_c = 0;
my $t_col = 0;
my $m_row = $max_row;
while($m_row > 0){
    $t_col = 3+($cc*7);
    if($cc == 0){
    $ws->write($t_row, 0,
                [$s->{first_name}, $s->{last_name}, $s->{l_name}], $fmt_wrap    
            );
    }
    if(defined $wall->{$key}->[$i_c] ){
    $ws->write($t_row, $t_col, $wall->{$key}->[$i_c], $fmt_wrap);
    } else {
    $ws->write($t_row, (3+$cc*7),["","","","","","",""], $fmt_wrap);                
    }
    $t_row++;
    $i_c++;
    $m_row--;
 }#while loop
    $ws->write($t_row-1, 3+$company_format*$max_step,
                [ (scalar keys %{$s->{videos}}), $s->{total_pageviews} ], $fmt
            );
 $cc++;
 $t_row = 2;
}#foreach loop
$row+=$max_row;
}#foreach student array

1 个答案:

答案 0 :(得分:1)

我找到了答案。在代码中有一行将数据多次写入单元格。所以我发现对特定单元的多次写入尝试可能导致文件损坏。