免费注册 查看新帖 |

Chinaunix

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

读excel使用了cp936依然乱码<分享> [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-10-08 16:51 |只看该作者 |倒序浏览
本帖最后由 zhlong8 于 2012-01-04 09:39 编辑

test.zip (2.26 KB, 下载次数: 23)
问题:perl读取excel中文乱码
解决方法:
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);
详细代码
  1. use strict;
  2. use Cwd;
  3. use Spreadsheet::ParseExcel;
  4. use Spreadsheet::ParseExcel::FmtUnicode;
  5. use Unicode::Map;

  6. my ($EXCEL,$BOOK,$SHEET,$CODE,$FMTJ,$CELL);
  7. my $dir = getcwd;
  8. my $dir = $dir.'\\test.xls';


  9. sub initExcel()
  10. {
  11.                 $EXCEL = new Spreadsheet::ParseExcel;
  12.                 $CODE = "CP936";
  13.                 $FMTJ = Spreadsheet::ParseExcel::FmtUnicode->new(Unicode_Map => $CODE);
  14.                 $BOOK = $EXCEL->Parse($dir,$FMTJ);
  15.          $SHEET = $BOOK->Worksheet('供数接口配置信息');
  16. }

  17. sub main
  18. {       
  19.         initExcel();
  20.         $CELL = $SHEET->{Cells}[0][0]->{Val};
  21.         print $CELL;
  22. }
  23. main();
复制代码
问题:使用了FmtUnicode模块 code = 'CP936'依然乱码
解决方法:
将:$CELL = $SHEET->{Cells}[0][0]->{Val};
改为:$CELL = $SHEET->{Cells}[0][0]->Value;

论坛徽章:
0
2 [报告]
发表于 2011-10-09 08:35 |只看该作者
http://bbs.chinaunix.net/viewthr ... amp;from=favorites#

版主的终极方案,一定能终结你的问题,我也发过同样的贴,被终结了!
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP