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的文章, 但 ...
随机推荐
- C++中结构体与类的区别 1
转载来源:http://blog.sina.com.cn/s/blog_48f587a80100k630.html C++中的struct对C中的struct进行了扩充,它已经不再只是一个包含不同数据 ...
- linux编辑器使用记录
超强大vim配置文件: wget http://files.cnblogs.com/ma6174/vimrc.zip unzip -f vimrc.zip -d ~/ 一.vim编辑器 进入 ...
- InfluxDB命令使用
身份验证与授权(权限管理) Authentication and Authorization 注意:身份授权与验证不能用于阻止恶意用户.如果有额外的做合理性和安全性的需求,InfluxDB可以运行在第 ...
- Ubuntu TIP
recovery进系统硬盘是挂载为“只读”的,要想改文件需要remount / 并且添加“w”(写权限). 进一次crub,再root进入 折腾几次似乎就可以编辑磁盘上的文件了
- leetcode289
public class Solution { public void GameOfLife(int[][] board) { ) - ; ].GetLength() - ; var list = n ...
- 解决MySql 数据库 提示:1045 access denied for user 'root'@'localhost' using password yes
今天想用用MySQL 数据库 谁知道老提示 1045 access denied for user 'root'@'localhost' using password yes 最后在csdn 上找到 ...
- 1.Hadoop集群搭建之Linux主机环境准备
Hadoop集群搭建之Linux主机环境 创建虚拟机包含1个主节点master,2个从节点slave1,slave2 虚拟机网络连接模式为host-only(非虚拟机环境可跳过) 集群规划如下表: 主 ...
- Mybatis 针对ORACLE和MYSQL的批量插入与多参数批量删除
今天利用Mybatis的<for each>标签做oracle的批量插入数据时,发现和MySQL数据库有区别.在此记录下,以防之后再踩坑. 一.批量插入: 1.controller: /* ...
- Sqlserver中查找包含某一列的所有的表
select cols.name,cols.id,objs.name,objs.id from syscolumns cols INNER JOIN sysobjects objs on cols.i ...
- 数组和集合(二):List集合的使用总结
一.概述 · 继承collection接口,List代表一个元素有序.且可重复(包括null)的集合,集合中的每个元素都有其对应的顺序索引 · List默认按元素的添加顺序设置元素的索引 · 提供了一 ...