为什么在Perl中读取Excel 2007(.xlsx)文件时会截断值?

时间:2021-11-21 16:58:22

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

我正在使用Spreadsheet :: ParseExcel读取.xls文件,并且能够按原样获取数据。

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

但是,当使用Spreadsheet :: XLSX读取.xlsx文件时,读取值将被截断。

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

例如,.xls和.xlsx文件中的2.4578分别读作2.4578和2.45。

Please suggest why .xlsx file data is corrupted.

请提供建议.xlsx文件数据损坏的原因。

2 个解决方案

#1


3  

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

我创建了一个包含一个工作表的简单工作簿,并且只在A1中创建了值2.4578并运行了以下脚本:

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.

如果您可以发布一个展示问题的简短,自包含的示例以及我们可以查看的小样本.xlsx文件,我们将有更好的机会识别问题。

#2


2  

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

对于未格式化的原始值,请尝试$ cell - > {Val},而不是Excel格式化值的$ cell-> Value()。

#1


3  

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

我创建了一个包含一个工作表的简单工作簿,并且只在A1中创建了值2.4578并运行了以下脚本:

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.

如果您可以发布一个展示问题的简短,自包含的示例以及我们可以查看的小样本.xlsx文件,我们将有更好的机会识别问题。

#2


2  

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

对于未格式化的原始值,请尝试$ cell - > {Val},而不是Excel格式化值的$ cell-> Value()。