简体   繁体   English

使用Excel :: XLSX解析Perl中的电子表格

[英]Using Excel::XLSX to parse a spreadsheet in Perl

I am using the Perl module Spreadsheet::XLSX to parse an Excel spreadsheet. 我使用Perl模块Spreadsheet :: XLSX来解析Excel电子表格。 Part of the data looks like this: 部分数据如下所示:

    Time        A1      A2      A3      
    0m14m35     0.12    0.13    0.14
    0m29m35     0.15    0.16    0.17

Here's part of the code: 这是代码的一部分:

foreach my $row ($sheet->{MinRow} .. $sheet->{MaxRow}) {

    foreach my $col ($sheet->{MinCol} ..  $sheet->{MaxCol}) {

        my $cell = $sheet->{Cells}[$row][$col];
        my $val = $cell->{Val} || "";
    }   
}

The problem is that the time values are converted to floats: 问题是时间值转换为浮点数:

 '0m14m35' becomes:  0.0101273148148148
 '0m29m35' becomes:  0.0205439814814815

How can I keep the time string a string? 如何将时间字符串保留为字符串?

Thanks! 谢谢! L. L.

$cell->{Val} is the unformatted value (which is the same as $cell->unformatted() ). $cell->{Val}是未格式化的值(与$cell->unformatted() )。 Try getting $cell->value() (same as $cell-{_Value} ), which is the formatted value; 尝试获取$cell->value() (与$cell-{_Value} ),这是格式化的值;

Excel stores dates as floats, so if you want to format those, you can use the ExcelFmt() function from Spreadsheet::ParseExcel::Utility, and you will want to use the unformatted value as one of the arguments to that function. Excel将日期存储为浮点数,因此如果要格式化它们,可以使用Spreadsheet :: ParseExcel :: Utility中的ExcelFmt()函数,并且您将希望使用未格式化的值作为该函数的参数之一。 You might even be able to get the format argument with $cell->get_format() 您甚至可以使用$cell->get_format()获取format参数

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM