使用Excel :: XLSX在Perl中解析电子表格(Using Excel::XLSX to parse a spreadsheet in Perl)
我使用Perl模块Spreadsheet :: XLSX来解析Excel电子表格。 部分数据如下所示:
Time A1 A2 A3 0m14m35 0.12 0.13 0.14 0m29m35 0.15 0.16 0.17
以下是部分代码:
foreach my $row ($sheet->{MinRow} .. $sheet->{MaxRow}) { foreach my $col ($sheet->{MinCol} .. $sheet->{MaxCol}) { my $cell = $sheet->{Cells}[$row][$col]; my $val = $cell->{Val} || ""; } }
问题是时间值转换为浮点数:
'0m14m35' becomes: 0.0101273148148148 '0m29m35' becomes: 0.0205439814814815
我如何保持时间字符串是一个字符串?
谢谢! L.
I am using the Perl module Spreadsheet::XLSX to parse an Excel spreadsheet. 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.
原文:https://stackoverflow.com/questions/17576431
更新时间:2022-11-16 14:11
最满意答案
您可以使用自定义属性 :
public class FooAttribute : Attribute { public string Description { get; set; } } public class Bar { [Foo(Description = "Some description")] public string BarProperty { get; set; } } public class Program { static void Main(string[] args) { var foos = (FooAttribute[])typeof(Bar) .GetProperty("BarProperty") .GetCustomAttributes(typeof(FooAttribute), true); Console.WriteLine(foos[0].Description); } }
You could use a custom attribute:
public class FooAttribute : Attribute { public string Description { get; set; } } public class Bar { [Foo(Description = "Some description")] public string BarProperty { get; set; } } public class Program { static void Main(string[] args) { var foos = (FooAttribute[])typeof(Bar) .GetProperty("BarProperty") .GetCustomAttributes(typeof(FooAttribute), true); Console.WriteLine(foos[0].Description); } }
相关问答
更多-
TCP/IP模型是一个________。[2023-10-02]
a -
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
设置它需要在XP和Win2003中引入的ChangeServiceConfig2 API函数,Delphi之前的服务类是在那之前编写的,很长一段时间,Windows NT4和2000是Delphi RTL的基准。 另外由于某些未知的原因,Borland(和后继者)一直不愿意在Windows API函数上使用动态绑定,宁愿静态绑定到DLL或迟到但不可选的绑定(不要问我为什么,对我来说没有意义),并且使用以前的函数将需要Win2003作为最低版本或使用动态绑定。 所以我不认为这是一个蓄意的决定,而是更多的公司政 ...
-
如果您在C#中使用基本相同的代码,则它至少会在属性值中包含换行符: [Description("Specifies the precision of decimal numbers\n etc"] public int Precision { ... } 现在Visual Studio如何处理这是另一回事。 您可能想尝试\r\n而不是\n 。 我怀疑你当前在设计器中看到的原因是,VB现在并没有以相同的方式逃避字符串。 在VB中,你可以尝试使用vbCrLf (相当于\r\n ):
描述一个属性(make description for a property)[2022-01-08]
您可以使用自定义属性 : public class FooAttribute : Attribute { public string Description { get; set; } } public class Bar { [Foo(Description = "Some description")] public string BarProperty { get; set; } } public class Program { static void Main(st ...DescriptionAttribute实际上可以应用于任何类型的成员,包括枚举值。 你确定你使用了正确的[Description] ? 确保你参考它来自的组件: using System.ComponentModel; 而且,如果您的范围内确实碰巧有两个不同的属性,称为'描述',则用名称空间前缀以消除歧义,即 enum MyEnum { [System.ComponentModel.Description("Blah")] MyValue } The DescriptionAttrib ...您可以对属性使用action=wbgetentities ,就像使用普通项一样。 要获得P31所有可读描述: https://www.wikidata.org/w/api.php?action=wbgetentities&ids=P31 并将结果限制为一种语言(英语): https://www.wikidata.org/w/api.php?action=wbgetentities&ids=P31&languages=en 使用pywikibot只是为了这个任务看起来有点矫枉过正(pywikibot是一个 ...获取属性描述属性(Getting property description attribute)[2022-10-31]
这应该适合你: return properties.Select(p => Attribute.IsDefined(p, typeof(DescriptionAttribute)) ? (Attribute.GetCustomAttribute(p, typeof(DescriptionAttribute)) as DescriptionAttribute).Description: p.Name ).ToArray(); This should wor ...应忽略JSON Reference对象中除“$ ref”以外的任何成员。 https://tools.ietf.org/html/draft-pbryan-zyp-json-ref-03#section-3 为了设置description ,您必须执行类似以下示例的操作。 它可能会在你的编辑器中引起其他的怪异,但我很确定这是最干净的方法。 原版的: { "$ref": "#/definitions/Path", "description": "Here the description whe ...您模板中的结束标记不正确 。 把它改成这个: {{#each calendar in model}}- {{calendar.name}}
{{/each}} Your closing tag in your template is incorrect. Change it to this: {{#each calendar in model}}- {{calendar.name}}
{{/each}}相关文章
更多- POI Excel电子表格处理
- 这种的EXCEL表格 怎么来解析??
- POI 操作Excel公式
- lucene读取word,excel,pdf
- java+jsp来获取excel的数据?
- POI读取数据库数据到excel
- JXLS根据excel模板生成EXCEL并下载
- POI 操作 Excel的主要API
- 原创:如何实现在Excel通过循环语句设置指定行的格式
- 使用POI操作Excel和Word
最新问答
更多- 以编程方式创建视频?(Create videos programmatically?)
- 为什么开机慢上面还显示;Inetrnet,Explorer
- javascript数组,如何改变这个数组结构(javascript arrays, how to change this array structure)
- 在ASP.NET Web API中使用多个Get方法进行路由(Routing with multiple Get methods in ASP.NET Web API)
- 用于backbone.js验证的自定义验证器(Custom validator for backbone.js validation)
- const char *与其他指针有什么不同?(Is const char * different from other pointers? [duplicate])
- 无效的列索引,使用PreparedStatement更新(Invalid column index , update using PreparedStatement)
- watchOS WCSession'已配对'和'watchAppAvailable'不可用(watchOS WCSession 'paired' and 'watchAppAvailable' are unavailable)
- CalledFromWrongThreadException在Android上执行JUnit测试(CalledFromWrongThreadException exercising JUnit tests on Android)
- 如何把文件保存到你的应用程序目录中?(How to put\save files into your application directory? (adobe air))
- 美元符号在Java方法描述符中的含义?(Meanings of dollar sign in Java method descriptor?)
- font-size的含义是什么:1em / 2em?(What doe the meaning of font-size:1em/2em?)
- h2元素推动其他h2和div。(h2 element pushing other h2 and div down. two divs, two headers, and they're wrapped within a parent div)
- 创建一个功能(Create a function)
- Android - 检测与特定wifi ssid断开连接的正确方法?(Android - Correct way to detect disconnecting from a particular wifi ssid?)
- 通过Shell脚本将文件转换为另一个文件(Convert File To Another File By Shell Script)
- 我投了份简历,是电脑编程方面的学徒,面试时说要培训三个月,前面
- 如何过滤magento废弃的购物车报告集合(How to Filter the magento abandoned cart report collection)
- PDO语句不显示获取的结果(PDOstatement not displaying fetched results)
- web api http post传递对象504接收失败(web api http post passing object 504 Receive Failure)
- Rails从视图编辑模型上的多个属性的方法(Rails way to edit multiple attributes on a model from a view)
- 总是用{}初始化对象是否是好习惯?(Is it good habit to always initialize objects with {}?)
- 在方案中编写特殊字符到输出端口(编译器设计)(writing special characters to output port in scheme (compiler design))
- 电脑等级考试得证有多大用处?
- Qt冻结循环的原因?(Qt freezing cause of the loop?)
- 第一次调用函数将无法按预期工作,但下一次工作正常(calling a function on the first time won't work as expected, but next time is working)
- 如何优化使用BigInteger操作执行时间的代码(How to optimize the code that uses BigInteger operations for execution time)
- TableView重复youtube-api结果(TableView Repeating youtube-api result)
- 如何提供个人资料信息,以便Passport.js可以使用它?(how does Profile information should be provided so Passport.js can use it?)
- 有没有办法初始化jquery数据表中的细节?(is there any way to initialize details in jquery datatable?)