1.读取excel:
use strict;
use Spreadsheet::ParseExcel;
my $parser = Spreadsheet::ParseExcel->new();
my $workbook = $parser->Parse('Book1.xls');
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 "Row, Col = ($row, $col)\n";
print "Value = ", $cell->value(), "\n";
print "Unformatted = ", $cell->unformatted(), "\n";
print "\n";
}
}
}
2.写excel:
use Spreadsheet::WriteExcel;
#************生成Excel文档****************
my $xl = Spreadsheet::WriteExcel->new("TEST.xls");
#生成Excel表
my $xlsheet = $xl->add_worksheet(“TestSheet”);
#添加格式(表头)
$rptheader = $xl->add_format(); # Add a format
$rptheader->set_bold();
$rptheader->set_size('12');
$rptheader->set_align('center');
#添加格式(表内容)
$normcell = $xl->add_format(); # Add a format
$normcell->set_size('9');
$normcell->set_align('center');
$normcell->set_bg_color('22');
#设置列的宽度
$xlsheet->set_column('A:A',10);
$xlsheet->set_column('B:B',12);
$xlsheet->set_column('C:C',17);
#写表头(格式是使用上面添加的表头格式)
$xlsheet->write("A2","Number", $rptheader);
$xlsheet->write("B2","Name",$rptheader);
$xlsheet->write("C2","Language",$rptheader);
#写内容(格式是使用上面添加的表内容格式)
$xlsheet->write("A3","1", $normcell);
$xlsheet->write("B3","Test",$normcell);
$xlsheet->write("C3","Perl",$normcell);
#关闭操作excel的对象.
$xl->close();
#!/usr/bin/perl
use Spreadsheet::WriteExcel;
#************生成Excel文档****************
my $xl = Spreadsheet::WriteExcel->new("TEST.xls");
#生成Excel表
my $xlsheet = $xl->add_worksheet(“TestSheet”);
#添加格式(表头)
$rptheader = $xl->add_format(); # Add a format
$rptheader->set_bold();
$rptheader->set_size('12');
$rptheader->set_align('center');
#添加格式(表内容)
$normcell = $xl->add_format(); # Add a format
$normcell->set_size('9');
$normcell->set_align('center');
$normcell->set_bg_color('22');
#设置列的宽度
$xlsheet->set_column('A:A',10);
$xlsheet->set_column('B:B',12);
$xlsheet->set_column('C:C',17);
#写表头(格式是使用上面添加的表头格式)
$xlsheet->write("A2","Number", $rptheader);
$xlsheet->write("B2","Name",$rptheader);
$xlsheet->write("C2","Language",$rptheader);
#写内容(格式是使用上面添加的表内容格式)
$xlsheet->write("A3","1", $normcell);
$xlsheet->write("B3","Test",$normcell);
$xlsheet->write("C3","Perl",$normcell);
#关闭操作excel的对象.
$xl->close();
解决中文乱码:
use Spreadsheet::WriteExcel;
use Encode;#(这里增加Encode)
#************生成Excel文档****************
my $xl = Spreadsheet::WriteExcel->new("TEST.xls");
#生成Excel表
my $xlsheet = $xl->add_worksheet(decode('utf8' ,“测试写入Excel”));#(中文名称)
#添加格式(表头)
$rptheader = $xl->add_format(); # Add a format
$rptheader->set_bold();
$rptheader->set_size('12');
$rptheader->set_align('center');
#添加格式(表内容)
$normcell = $xl->add_format(); # Add a format
$normcell->set_size('9');
$normcell->set_align('center');
$normcell->set_bg_color('22');
#设置列的宽度
$xlsheet->set_column('A:A',10);
$xlsheet->set_column('B:B',12);
$xlsheet->set_column('C:C',17);
#写表头(格式是使用上面添加的表头格式)(这里是输入中文)
$xlsheet->write("A2",decode(‘utf8’,"号码"), $rptheader);
$xlsheet->write("B2", decode(‘utf8’,"名称"),$rptheader);
$xlsheet->write("C2", decode(‘utf8’,"语言"),$rptheader);
#写内容(格式是使用上面添加的表内容格式)(这里是输入中文)
$xlsheet->write("A3", decode(‘utf8’,"1"), $normcell);
$xlsheet->write("B3", decode(‘utf8’,"测试"),$normcell);
$xlsheet->write("C3", decode(‘utf8’,"Perl"),$normcell);
#关闭操作excel的对象.
$xl->close();
分享到:
相关推荐
通过perl读写excel 通过perl读写excel 通过perl读写excel 通过perl读写excel
利用perl读取EXCEL文件输出到XML文件
讲解perl中读写excel用到的库函数,以及如何使用库函数进行操作。
perl读取excel内容,并发送html邮件!中文不乱码,直接下载可用,只需要改一下文件路径,这是已经上生产的脚本
这是一个用perl语言解析的一个excel文件,将excel中的数据按照既定格式输出,方便数据处理
赛哦ifuowoe弱任务哦尔维尔哦温柔温柔品牌人哦 飞洒票房破而 分
引言脚本语言,其目的是将 Unix shell 的易用性和编程语言( 比如 C) 的功能与可塑性结合起来。它最初只是 Unix 系统管理员的一个工具, 在工作日
根据Excel列表信息提取输入输出接口生成Verilog文件
excel/CSV 表数据excel/CSV为C++代码,支持程序内直接读取数据结构
Spreadsheet-ParseExcel,Perl的Excel插件,可用于读写Excel文件,在Linux下对Excel文件进行处理。 可以用Spreadsheet::ParseExcel先解析excel,再用Spreadsheet::WriteExcel写入。 或者直接使用Spreadsheet::...
Python对Excel操作详解 文档摘要: 本文档主要介绍如何通过python对office excel进行读写操作,使用了xlrd、xlwt和xlutils模块。另外还演示了如何通过Tcl tcom包对excel操作。 关键字: Python、Excel、xlrd、xlwt、...
Qt操作xlsx格式Excel所需开源库,该库无需调用excel和wps,可以直接读取写xlsx文件。效率高
它提供了创建、读取和写入Excel工作表的功能,包括单元格、行和列的格式设置以及数据验证和保护等功能。xlslib库支持多平台,包括Windows、Linux、Solaris、FreeBSD和MacOSX等操作系统。xlslib库可以直接在C/C++应用...
Qt读写excel的库文件QXlsx,已经编译好的,拷到相应文件夹下可直接使用
快速读取xml文件并转换为SAS / WPS数据集。 关键字:sas sql join合并大数据分析宏oracle teradata mysql sas社区stackoverflow statistics人工智慧AI Python R Java Javascript WPS Matlab SPSS Scala Perl CC#...
Mojolicious服务器端应用程序,能够读取excel电子表格并提供一个rest接口来访问其内容。 一个jQuery javascript插件,用于从服务器请求数据并将数据插入适当准备的html表对象中。 设置 SpreadButler在和软件包中...
matlab代码不Reactutl_...CC#Excel MS Access JSON图形映射NLP自然语言处理机器学习igraph DOSUBL DOW循环stackoverflow SAS社区。 使用元数据将列平均高度添加到sas数据库中的每个表 github https://goo.gl/mt1Wym ...
V2,3,2,0版本之后,NTKO OFFICE文档控件支持直接从ODBC数据源读取文档内容,或者将文档内容存入ODBC数据源。这为C/S结构下创建共享的办公系统,文档管理,知识管理解决方案提供了更强大的接口。 8 状态栏,智能Web...
ASP.NET是微软.NET战略中的一个重要成员,除了可以使用Visual C#、VB.NET、VisualC++.NET、JScript.NET等语言编写外,还可以使用第三方的.NET接口(如COBOL.NET、 Perl.NET等)进行编写。本书通过100个精彩实例...
实例22读取Config 22Web配置文件 实例23显示BrowseCaps配置段内容 实例24写入文件操作与应用 实例25文件读操作及应用 实例26文件删除与应用 实例27ASP NET中异常处理及其应用 实例28AutoPostBack技术及其应用 ...