1

次の内容の Excel シート (A.xls) があります。

Date,Value
10/1/2020,36.91
10/2/2020,36.060001

Solaris 5.8 で Perl v5.6.1 と同じスクリプトを使用して、次の出力を得ました。

>>./a4_test.pl
INFO>Excel File=A.xls,#WorkSheet=1,AuthorID=Sahoo, Ashish
DEBUG>row 2 - col 0:10-2-20
DEBUG>row 2 - col 1:36.060001

そして、solaris 5.11 の perl v5.26.3 で同じスクリプトを使用して、日付フィールドの異なる出力を得ました。

>>./a4_test.pl
INFO>Excel File=A.xls,#WorkSheet=1,AuthorID=Sahoo, Ashish
DEBUG>row 2 - col 0:2020-10-02
DEBUG>row 2 - col 1:36.060001

Solaris 8 マシンでは 0.2602 バージョンを使用Spreadsheet::ParseExcelし、Solaris 11 マシンでは 0.65 バージョンを使用しました。

モジュール
を介して Excel シートから日付フィールドを読み取るときに、異なる出力が得られるのはなぜですか?Spreadsheet::ParseExcel

#!/usr/perl/5.12/bin/perl -w
use Spreadsheet::ParseExcel;

my $srce_file = "a.xls"; 
my $oExcel = new Spreadsheet::ParseExcel;
my $oBook = $oExcel->Parse($srce_file); 
my %hah_sheet = ();
my $header_row  = 1;
my($iR, $iC, $oWkS, $oWkC);
my $book = $oBook->{File};
my $nsheet= $oBook->{SheetCount};
my $author= $oBook->{Author};
unless($nsheet){
    print "ERR>No worksheet found for source file:$srce_file\n";
    return 0;
}
else{
    print "INFO>Excel                         
   File=$srce_file,#WorkSheet=$nsheet,AuthorID=$author\n";
}


for(my $iSheet=0; $iSheet < $oBook->{SheetCount} ; $iSheet++) {
    next if($iSheet >0);    
    $oWkS = $oBook->{Worksheet}[$iSheet];

    my $rows = 0;
    for(my $iR = $oWkS->{MinRow}; defined $oWkS->{MaxRow} && $iR <= $oWkS->{MaxRow} ; $iR++) {
        $rows++;

        my $str_len = 0;
        for(my $iC = $oWkS->{MinCol}; defined $oWkS->{MaxCol} && $iC <= $oWkS->{MaxCol}; $iC++) {
            $oWkC = $oWkS->{Cells}[$iR][$iC];
            next if ($iR <$header_row);
            
            if (defined($oWkC)){
                my $cell_value = $oWkC->Value;
                $cell_value =~s/\n+//g;               #removed newline inside the value
                #
                ##if the first column at header row is null then skip. Column might be shifted
                if($iR==$header_row && $iC == 0){
                    last unless($cell_value);
                }
                if($iR == $header_row){
                   $hah_sheet{$iR}{$iC} = uc($cell_value);
                }else {
                   $hah_sheet{$iR}{$iC} = $cell_value;
                   $str_len += length($cell_value);  
                   ##View cell value by row/column
                   print "DEBUG>row ${iR} - col ${iC}:$cell_value\n";
                }
            }else{
                $hah_sheet{$iR}{$iC} = "";              #keep position for NULL value
            }
        } # END of Column loop
    } # END of Row loop
} # END of Worksheet
      
4

1 に答える 1