当前位置:   article > 正文

perl 解析excel_perl解析表格

perl解析表格

因为工作需要,给一些内容的结果需要转换成excel给上面看,所以用perl来实现这个事件,发现perl来写excel实在是太容易了。。我真想学老罗的讲"太容易了,实在是太容易了".

在 2000 年,Takanori Kawai 和 John McNamara 编写出了 Spreadsheet::WriteExcel 和 Spreadsheet::ParseExcel 模块并将它们张贴在 CPAN 上,这两个模块使得在任何平台上从 Excel 文件抽取数据成为可能。

perl写excel这个模块的内容

#!/usr/bin/perl
use strict;
use warnings;
 
use Encode;
use Spreadsheet::WriteExcel;
 
# 设置new一个对象出来,并写上需要存成什么名字的xls
my $xls = Spreadsheet::WriteExcel->new( "fukaiss.xls" );
 
# xml的内容名字
my $xlsContent = $xls->add_worksheet( 'report' );
 
# 这是对格式的设置,我们可以设置一个标题的,一个内容的,
# 我现在只设置一个内容
my $contentStyle = $xls->add_format();
    $contentStyle->set_size( 8 );
    $contentStyle->set_bold();           #设置字体为粗体
    $contentStyle->set_align( 'center' );#设置单元格居中
    $contentStyle->set_text_wrap();      #是否回车换行
    $contentStyle->set_color('red');     #设置单元格前景色为红色
 
# 写表内容(格式是使用上面添加的表格式)
# 这个中的A,B,C是设置的excel中上面行的字母
# 这个地方中的文字我用了decode这样中文才能正常显示
# 最后面的contentStyle是我上面设置的行风格
 
$xlsContent->write( "A1", decode( 'utf8', "名字" ), $contentStyle );
$xlsContent->write( "B1", decode( 'utf8', "时间" ), $contentStyle );
$xlsContent->write( "C2", decode( 'utf8', "语言" ), $contentStyle );
#$xlsContent->write($row, $col, 'Hi Excel!', $format); #行,列,内容,格式

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/316343
推荐阅读
相关标签
  

闽ICP备14008679号