免费注册 查看新帖 |

Chinaunix

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

哪位对Spreadsheet::ParseExcel比较熟悉? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-12-01 11:36 |只看该作者 |倒序浏览
怎么我安装好以后,直接运行这个模块的例子都不行?


  1.     #!/usr/bin/perl -w

  2.     use strict;
  3.     use Spreadsheet::ParseExcel;

  4.     my $parser   = Spreadsheet::ParseExcel->new();
  5.     my $workbook = $parser->Parse('Book1.xls');

  6.     for my $worksheet ( $workbook->worksheets() ) {

  7.         my ( $row_min, $row_max ) = $worksheet->row_range();
  8.         my ( $col_min, $col_max ) = $worksheet->col_range();

  9.         for my $row ( $row_min .. $row_max ) {
  10.             for my $col ( $col_min .. $col_max ) {

  11.                 my $cell = $worksheet->get_cell( $row, $col );
  12.                 next unless $cell;

  13.                 print "Row, Col    = ($row, $col)\n";
  14.                 print "Value       = ", $cell->value(),       "\n";
  15.                 print "Unformatted = ", $cell->unformatted(), "\n";
  16.                 print "\n";
  17.             }
  18.         }
  19.     }
复制代码


执行后一堆错误信息(很多都差不多,拷贝两行如下):

Use of uninitialized value in hash element at /usr/lib/perl5/site_perl/5.8.5/Spreadsheet/ParseExcel/FmtDefault.pm line 89.
Use of uninitialized value in hash element at /usr/lib/perl5/site_perl/5.8.5/Spreadsheet/ParseExcel/FmtDefault.pm line 94.

论坛徽章:
0
2 [报告]
发表于 2009-12-01 14:10 |只看该作者
没用过这个 module,但是解析 excel 的东东,非win环境下用,即使可用,也会有很多限制吧
而且看错误,$parse 可能都没东西,确认存在 Book1.xls 的话,那里面的各个 sheet 有写些东西吗?

论坛徽章:
0
3 [报告]
发表于 2009-12-01 14:20 |只看该作者
原帖由 dugu072_cu 于 2009-12-1 14:10 发表
没用过这个 module,但是解析 excel 的东东,非win环境下用,即使可用,也会有很多限制吧
而且看错误,$parse 可能都没东西,确认存在 Book1.xls 的话,那里面的各个 sheet 有写些东西吗?


这个模块直接parse excel的二进制文件,而不是通过OLE方式访问,所以在Windows下访问也差不多的。

这个问题去掉excel中错误检查以后,就解决了。

论坛徽章:
0
4 [报告]
发表于 2009-12-05 00:33 |只看该作者
检查你的perl版本吧.

论坛徽章:
0
5 [报告]
发表于 2009-12-05 10:15 |只看该作者

回复 #1 billypeng 的帖子

Depending on the Excel version used to generate the files and the actual filetype saved (OOXML anyone?), this might or might not work.

If in doubt, you could use Win32::OLE (on a windows machine) to convert the file to a CSV-File (comma seperated values) first, take a look here:

http://www.ngbdigital.com/perl_ole_excel.html

Then you could use a number of CPAN modules to process the CSV. One of the more exotic one is DBD::CSV, where use can use the file like a database table.
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP