Chinaunix首页 | 论坛 | 博客
  • 博客访问: 415299
  • 博文数量: 83
  • 博客积分: 2010
  • 博客等级: 大尉
  • 技术积分: 900
  • 用 户 组: 普通用户
  • 注册时间: 2006-01-02 01:33
文章分类

全部博文(83)

文章存档

2011年(1)

2010年(5)

2009年(10)

2008年(4)

2007年(24)

2006年(39)

我的朋友

分类:

2007-02-12 23:57:30

需要用的模块:
Spreadsheet::ParseExcel
Unicode::Map
IO-stringy
OLE-Storage_Lite

其中IO-stringy,OLE-Storage_Lite为运行的必要包
Spreadsheet::ParseExcel是解析Excel的必要程序
Unicode::Map为完全支持中文的字符集转换包
 
perldoc Spreadsheet::ParseExcel 介绍的很详细了
中文 excel 处理需要稍微多做一步
用 Spreadsheet::ParseExcel::FmtUnicode 指定 Unicode_Map 为 CP936

然后直接调用 Parse 方法就行了
返回值是一个关键数组 内容就是 excel 文件的内容

$oBook->{File} 是文件名
$oBook->{SheetCount} 是sheet个数
$oBook->{Worksheet}[0]->{Name} 是第一个 sheet 的名字
$oBook->{Worksheet}[1]->{MaxRow} 是第二个 sheet 的最大行
$oBook->{Worksheet}[2]->{Cells}[1][0]->{Val} 是第三个 sheet 的第二行第一列的值
$oBook->{Worksheet}[2]->{Cells}[1][0]->Value 是第三个 sheet 的第二行第一列的转化后的中文值

use Spreadsheet::ParseExcel;
use Spreadsheet::ParseExcel::FmtUnicode;

my $oExcel = new Spreadsheet::ParseExcel;
my $oCode = "CP936";
my $oFmtJ = Spreadsheet::ParseExcel::FmtUnicode->new(Unicode_Map => $oCode);
my $oBook = $oExcel->Parse($excelFile, $oFmtJ);

然后根据情况 循环sheet 行/row 列/column 处理就行了
阅读(3779) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~