Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re: Why Does the Module(s) Round off to 2 Decimal Places?

by frieduck (Hermit)
on May 02, 2009 at 23:58 UTC ( #761553=note: print w/replies, xml ) Need Help??

in reply to Why Does the Module(s) Round off to 2 Decimal Places?

You're calling $cell->Value which gets the formatted value whereas $cell ->{Val} should get you the unformatted (full) value.
ss2tk uses the unformatted value via the cell hash entry method (ex: $s->{cell}$_$r) of getting data from Spreadsheet::Read
  • Comment on Re: Why Does the Module(s) Round off to 2 Decimal Places?

Replies are listed 'Best First'.
Re^2: Why Does the Module(s) Round off to 2 Decimal Places?
by socrtwo (Sexton) on May 03, 2009 at 12:29 UTC
    Thanks very much for your answer and that may be the crux of the matter, however, when I change $cell->Value to $cell ->{Val} in Spreadsheet::XLSX::Utility2007, nothing changes. I also tried {$cell}->Value

      Below is my changed code, which tests fine for me. I also had to add a "Use Spreadsheet::XLSX" to the top of Spreadsheet::XLSX::Utility2007, and, for some reason I don't understand, had to change line 136 of Spreadsheet::XLSX::Fmt2007 to "return Spreadsheet::XLSX::Utility2007::ExcelFmt($sFmtStr, $Dt, $Flg1904, $oCell->{Type});"

      if( !$rotate) { for( my $y = $y1 ; $y <= $y2 ; $y++) { for( my $x = $x1 ; $x <= $x2 ; $x++) { my $cell = $oWkS->{Cells}[$y][$x] ; #$output .= $cell->Value if(defined $cell); $output .= $cell->{Val} if(defined $cell); $output .= "," if( $x != $x2) ; } $output .= "\n" ; } } else { for( my $x = $x1 ; $x <= $x2 ; $x++) { for( my $y = $y1 ; $y <= $y2 ; $y++) { my $cell = $oWkS->{Cells}[$y][$x] ; #$output .= $cell->Value if(defined $cell); $output .= $cell->{Val} if(defined $cell); $output .= "," if( $y != $y2) ; } $output .= "\n" ; } }
      It turns out that is you change in the Spreadsheet::XLSX module:
      my $cell =Spreadsheet::ParseExcel::Cell->new( Val => $v, Format => $thisstyle, Type => $type );
      my $cell =Spreadsheet::ParseExcel::Cell->new( Val => $v, Format => $thisstyle, Type => "" );
      It removes the formatting. There are still minor differences with what appears in the ss2tk display. The format that results from the change mentioned above seems to use the same sort of rounding that Excel itself does before displaying the raw data from worksheet#.xml files.

      For instance a piece of raw data displayed in the ss2tk table and in the XML worksheet file is 1.3318000000000001 and changing the Spreadsheet::XLSX routine and using the Utility2007::xls2csv function and Excel itself displays a rounding to 1.3318.

      Thanks again for the help.

        The change you've made appears to apply default formatting (i.e. ignoring the specified format for the cell), whereas the change I proposed to xls2csv (earlier reply) pulls the unformatted value as stored in the xlsx file.

        Personally, I'd change my local xls2csv sub, to avoid surprises in other uses of Spreadsheet::XLSX.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://761553]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (3)
As of 2018-01-23 06:53 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (240 votes). Check out past polls.