免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 5183 | 回复: 5
打印 上一主题 下一主题

perl操作excel如何设置成文本格式 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-08-13 17:42 |只看该作者 |倒序浏览
用Spreadsheet::WriteExcel生成excel时,如果是000002这样的格式,生成的excel会变成2,
如何设置format避免这种问题?或者说有别的解决办法??

论坛徽章:
0
2 [报告]
发表于 2010-08-13 18:09 |只看该作者
perl -le '$x=sprintf("%05d",2);print $x'
00002

论坛徽章:
0
3 [报告]
发表于 2010-08-13 18:49 |只看该作者
lz 说的是,excel 如何不自动格式化……

可以如此:value = "'00002",注意,就是利用了 vbs 的 ' 为注释符号,这样子,就不会给你格式化了!

论坛徽章:
0
4 [报告]
发表于 2010-08-15 08:21 |只看该作者
在 perldoc 文档中有找到这么一段描述,似乎比较符合你遇到的问题:
One problem with the write() method is that occasionally data looks like a number but you don't want it treated as a number. For example, zip codes or ID numbers often start with a leading zero. If you write this data as a number then the leading zero(s) will be stripped. You can change this default behaviour by using the keep_leading_zeros() method. While this property is in place any integers with leading zeros will be treated as strings and the zeros will be preserved. See the keep_leading_zeros() section for a full discussion of this issue.

论坛徽章:
0
5 [报告]
发表于 2010-08-16 09:17 |只看该作者
$worksheet->keep_leading_zeros();对于一个工作表设置一下即可,多谢三位的回复。

论坛徽章:
78
双子座
日期:2013-10-15 08:50:09天秤座
日期:2013-10-16 18:02:08白羊座
日期:2013-10-18 13:35:33天蝎座
日期:2013-10-18 13:37:06狮子座
日期:2013-10-18 13:40:31双子座
日期:2013-10-22 13:58:42戌狗
日期:2013-10-22 18:50:04CU十二周年纪念徽章
日期:2013-10-24 15:41:34巨蟹座
日期:2013-10-24 17:14:56处女座
日期:2013-10-24 17:15:30双子座
日期:2013-10-25 13:49:39午马
日期:2013-10-28 15:02:15
6 [报告]
发表于 2010-08-16 10:29 |只看该作者
关注
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP