tags:

views:

49

answers:

2

I am reading an .xls file using Spreadsheet::ParseExcel and was able to get data as is.

But,when reading an .xlsx file using Spreadsheet::XLSX, the read values are truncated.

E.g., 2.4578 in .xls and .xlsx file is read as 2.4578 and 2.45, respectively.

Please suggest why .xlsx file data is corrupted.

+2  A: 

I created a simple workbook containing one sheet and only the value 2.4578 in A1 and ran the following script:

use Spreadsheet::XLSX;

my $excel = Spreadsheet::XLSX->new('Book1.xlsx');

my ($sheet) = @{ $excel->{Worksheet} };

print $sheet->{Cells}[0][0]{Val}, "\n";

Output:

C:\Temp> x
2.4578000000000002

So, in this simple case, everything seems to be OK.

If you can post a short, self-contained example that exhibits the problem and a small sample .xlsx file which we can look at, we would have a better chance of identifying the problem.

Sinan Ünür
+1  A: 

Try $cell->{Val} for the unformatted raw value instead of $cell->Value() for the Excel formatted value.

jmcnamara
I think you have it backwards. Using the code in my answer, replacing `Val` with `_Value` prints `2.46`.
Sinan Ünür
The above order is correct.
jmcnamara