sandeep_car has asked for the wisdom of the Perl Monks concerning the following question:
Hi,
We upload file in .xlsx or xls format. In this file there is one coloumn for which value is in decimal. For these value for some it shows differnet result while reading from excel file and for some it shows correct result.
For example:
at place of 1.14 it comes 1.139999999999999
at place of 1.13 it comes 1.129999999999999
where as for some it give correct result.
Code used for reading .xlsx file is:
$fileName = $_[0]; $fFnc = $_[1]; $logMsg = new LogMessage(); $logMsg->writeLog( $fFnc, "Reading $fileName \n" ); $FileData = ""; %FileHash = (); %source_headers = (); # For XLSX formats if( $fileName =~ /\.xlsx$/i ) { my $myConv = Text::Iconv->new ("utf-8" +, "windows-1251"); my %xlFileData = (); my $myBook = Spreadsheet::XLSX->new( " +$fileName", $myConv ); if( $myBook ) { foreach my $sheet (@{$myBook->{Work +sheet}}) { $sheet->{MaxRow} ||= $sheet +->{MinRow}; foreach my $row ($sheet -> +{MinRow} .. $sheet -> {MaxRow}) { $sheet -> {MaxCol} +||= $sheet -> {MinCol}; foreach my $col ($s +heet -> {MinCol} .. $sheet -> {MaxCol}) { my $cell = $ +sheet -> {Cells} [$row] [$col]; // At this place it gives incorrect result }
Code used for reading .xls file is:
if($fileName =~ /\.xls$/i ) { my $parser = Spreadsheet::ParseExcel-> +new(); my $workbook = $parser->parse( "$fileN +ame" ); if( defined $workbook ) { for my $worksheet ( $workbook->works +heets() ) { my ( $row_min, + $row_max ) = $worksheet->row_range(); my ( $col_min, + $col_max ) = $worksheet->col_range(); for my $row ( +$row_min .. $row_max ) { for my + $col ( $col_min .. $col_max ) { + my $cell = $worksheet->get_cell( $row, $col ); // At this place it gives incorrect result while reading. }
Please help me on this.
Thanks,
Sandeep
|
|---|