perl读取excel
因为工作当中遇到要处理大数据的excel的玩意,最多的有几十万行。用perl的方式试试,看看效果如何。
ppm install OLE::Storage_Lite #如果不安装这个,后面两个安装不了
ppm install Spreadsheet::ParseExcel
ppm install Spreadsheet::WriteExcel
查看是否安装成功
perldoc Spreadsheet::ParseExcel #如果打印出文档则表示安装成功
为保证编码正确
ppm install Unicode::Map
use strict;
use Spreadsheet::ParseExcel;
use Spreadsheet::ParseExcel::FmtUnicode; #字符编码 my $parser = Spreadsheet::ParseExcel->new();
my $formatter = Spreadsheet::ParseExcel::FmtUnicode->new(Unicode_Map=>"CP936");#设置字符编码
#my $workbook = $parser->parse('Book.xls');
my $workbook = $parser->parse('E:\webdev\project\perl\a.xls', $formatter);#按所设置的字符编码解析 my $log = "demo.log"; if ( !defined $workbook ) {
die $parser->error(), ".\n";
} open(FILE,">$log"); for my $worksheet ( $workbook->worksheets() ) { my ( $row_min, $row_max ) = $worksheet->row_range();
my ( $col_min, $col_max ) = $worksheet->col_range(); for my $row ( $row_min .. $row_max ) {
for my $col ( $col_min .. $col_max ) { my $cell = $worksheet->get_cell( $row, $col );
next unless $cell;
print $cell->value()," ";
print(FILE $cell->value()."\t");
}
print "\n";
print(FILE "\n");
}
} close(FILE);
记录下,明天去公司试试效果
use strict;
use warnings;
use Spreadsheet::XLSX;
use Encode;
use Getopt::std;
use File::Basename;
use LWP::Simple;
use URI::Escape; #my $converter = Text::Iconv -> new ("utf-8", "windows-1251");
#my $excel = Spreadsheet::XLSX -> new ('test.xlsx', $converter); eval {
my $l = "D:\\log.log"; #读取excel文件
my $excel_path = $ARGV[];
my $dir = dirname($excel_path); #设置log文件路径
my $log = $dir."/".$ARGV[].".log";
open(FILE,">$l");
print(FILE "http://localhost/kwm/source/index.php?s=Admin/Index/extract/log/".$ARGV[]);
close(FILE);
#print 'http://localhost/kwm/source/index.php?s=Admin/Index/extract/log/'.$ARGV[1]; #print $log;die;
#print(FILE "praam $excel_path\n");
my $excel = Spreadsheet::XLSX->new($excel_path);
#print(FILE "excel read over\n"); my $sheet = $excel->Worksheet(); open(FILE,">$log"); printf("Sheet: %s/n", $sheet->{Name}); $sheet -> {MaxRow} ||= $sheet -> {MinRow}; foreach my $row ($sheet -> {MinRow} .. $sheet -> {MaxRow}) {
$sheet -> {MaxCol} ||= $sheet -> {MinCol};
foreach my $col ($sheet -> {MinCol} .. $sheet -> {MaxCol}) {
my $cell = $sheet -> {Cells} [$row] [$col];
my $a = "";
if ($cell) {
$a = $cell->{Val};
#$a = encode("gbk", decode("utf8", $a));
#printf("( %s , %s ) => %s/n", $row, $col, $a);
#printf("$a ");
} print(FILE $a."\t");
}
#print "/n"; ## one row over
print(FILE "\n");
}
close(FILE); my $content = get('http://localhost/kwm/source/index.php?s=Admin/Task/extract/log/'.$ARGV[]."/id/".$ARGV[]."/uid/".$ARGV[]);
print encode("gbk", $content);
die;
}; if($@) {
#print "error";
}
perl读取excel的更多相关文章
- 使用perl读取Excel
使用perl读取Excel 环境 windows 7 ActiveState Perl Win32::OLE[perl package] 基本功能 循环处理多个sheet 读取Excel单元,提取in ...
- perl 读取Excel写入txt 乱码
用perl读出excel的内容(中文),然后输出在txt中乱码,但是打印在控制台正常. 解决办法: use Encode qw/from_to/; from_to($value, 'gb2312', ...
- Perl读取Excel中的数据
#!usr/bin/perl -W use strict; use Spreadsheet::ParseExcel;#PERL的Spreadsheet::ParseExcel模块支持Excel的读操作 ...
- Perl读写Excel简单操作
Perl读写Excel简单操作 使用模块 Spreadsheet::ParseExcel Spreadsheet::WriteExcel 读Excel #!/usr/bin/perl -w use s ...
- java的poi技术读取Excel数据到MySQL
这篇blog是介绍java中的poi技术读取Excel数据,然后保存到MySQL数据中. 你也可以在 : java的poi技术读取和导入Excel了解到写入Excel的方法信息 使用JXL技术可以在 ...
- poi读取excel模板,填充内容并导出,支持导出2007支持公式自动计算
/** * 版权所有(C) 2016 * @author www.xiongge.club * @date 2016-12-7 上午10:03:29 */ package xlsx; /** * @C ...
- C#读取Excel,或者多个excel表,返回dataset
把excel 表作为一个数据源进行读取 /// <summary> /// 读取Excel单个Sheet /// </summary> /// <param name=& ...
- PHP读取EXCEL时间
在使用php读取excel表格中的时间时得到一串数字而不是时间:40359.58333333334 excel 中的时间值是自1900年以来的天数,注意是格林威治时间php 中的时间值是自1970年以 ...
- Open Xml 读取Excel中的图片
在我的一个项目中,需要分析客户提供的Excel, 读出其中的图片信息(显示在Excel的第几行,第几列,以及图片本身). 网络上有许多使用Open Xml插入图片到Word,Excel的文章, 但 ...
随机推荐
- Maven assembly插件进行自定义构建
众所周知,Maven是一个约定优于配置的java构建工具,通常我们只需要定义非常少的内容,就可以根据package标签属性来构建生成的jar, war包的相关内容. 如果想要对maven中依赖的内容一 ...
- java 字符串排序
http://bbs.csdn.net/topics/280032929 大可不需要那样复杂了!(一)如果要排序的为字符串,如:String sortStr = "ACDFE"; ...
- eclipse egit 更新未提交文件的方法
问题 以前一直在项目中使用SVN..感觉真的很好用,不管是切分支,合并分支,编辑冲突,还是更新代码什么的都感觉很方便...现在新公司项目里使用git...我自己虽然用过,但是多人合作一直没用过.所以遇 ...
- MySQL 执行 'use databases;' 时很慢
问题描述: 就是这么个情况,登录数据库切换库时感觉很卡,需要等待几秒钟. 案例: shell > mysql -uroot -ppassword mysql> use databases; ...
- Java开发WebService实例(1)
参考文献:http://blog.sina.com.cn/s/blog_7bd0d6a70101dixc.html 简单的java工程实现 1 首先建立一个Java工程,在里面建一个Web servi ...
- [KVM][guestfs] 安装 guestfs-python 出错
pip install http://download.libguestfs.org/python/guestfs-1.36.13.tar.gz 执行后出错: 然后百度.谷歌,都是说安装 gcc 或者 ...
- Plugins in Unity
[Plugins in Unity] In Unity, you normally use scripts to create functionality but you can also inclu ...
- Render Texture
[Render Texture] Render Textures are special types of Textures that are created and updated at runti ...
- ubuntu 重启显卡报错 nvidia
1.我装玩显卡以后重启报错了 解决了5个小时才解决,先贴个当时报错的图 第一个图是没有加nomodeset 出先的 当你出现第二个图片的时候证明你离成功不远了 从头开始: 1.开机,出现 ubuntu ...
- Ubuntu Server 12.04 LTS搭建SVN服务及修改端口
采用了apache结合svn的方式. 首先安装apache.subversion.svn-apache sudo apt-get install apache2 sudo apt-get instal ...