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的文章, 但 ...
随机推荐
- APP推送通知相关实现
关于推送通知,iOS推送主要是通过服务端来实现的,相关过程可以参考下面两篇文章: http://cshbbrain.iteye.com/blog/1859810 http://zxs198 ...
- c# 关键字学习
partial class Test { public string str; public void get() { } } partial class Test { public int i; p ...
- HDU2546题解
解题思路:先对价格排序(顺序或倒序都可以),然后,对前n-1(从1开始.排序方式为顺序)做容量为m(卡上余额)-5的01背包(背包体积和价值相等).假设dp[i][j]表示从前i个背包中挑选体积不超过 ...
- opatch lsinventory –details
今天把RAC的数据库升完级后,在RAC1节点执行opatch lsinventory –detail 命令,没有报错.在rac2节点执行报错: [oracle@rac2 ~]$ opatch lsin ...
- Integer-->String String-->Integer
参考:http://blog.csdn.net/wangjolly/article/details/18354457 crane: String str="123";int a=0 ...
- mysql导出文本文件,加分隔符
从mysql导出,再导入到oracle #!/bin/sh cd /u03/tools/machine_info rm -f data/machine_info.txt mysql -u用户名 -p密 ...
- 24_java之转换流和缓冲流
01转换流概述 * A: 转换流概述 * a: 转换流概述 * OutputStreamWriter 是字符流通向字节流的桥梁:可使用指定的字符编码表,将要写入流中的字符编码成字节 * 将字符串按照指 ...
- Netty使用Google的ProtoBuf
protobuf是由Google开发的一套对数据结构进行序列化的方法,可用做通信协议,数据存储格式,等等.其特点是不限语言.不限平台.扩展性强 Netty也提供了对Protobuf的天然支持,我们今天 ...
- clipboard使用总结
官方网站:https://clipboardjs.com/ 使用总结:http://blog.csdn.net/hry2015/article/details/70941912
- halcon连续采集图像
dev_close_window()dev_update_window('off')create_bar_code_model ([], [], BarCodeHandle)dev_open_wind ...