国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Perl > 正文

Perl操作Excel的示例代碼

2020-02-23 19:47:29
字體:
來源:轉載
供稿:網友

Perl操作Excel的示例代碼,在Linux或者Unix上操作(生成)Excel,CPAN上提供了Spreadsheet::WriteExcel 和 Spreadsheet::ParseExcel這兩個模塊,下面就跟隨武林技術小編來看看 Spreadsheet::WriteExcel 和 Spreadsheet::ParseExcel的使用方法。

首先,要在服務器上安裝相應的模塊。
安裝 Excel 模塊的 PPM 命令

復制代碼 代碼如下:

ppm> install OLE::Storage_Lite
ppm> install Spreadsheet::ParseExcel
ppm> install Spreadsheet::WriteExcel


來看兩個例子吧。
例1:讀取excel文件

?

復制代碼 代碼如下:

?


#!/usr/bin/perl -w
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文件

?

復制代碼 代碼如下:

?


#!/usr/bin/perl -w

use Spreadsheet::WriteExcel;

# 創建一個新的EXCEL文件
my $workbook = Spreadsheet::WriteExcel->new('test.xls');

# 添加一個工作表
$worksheet = $workbook->add_worksheet();

# 新建一個樣式
$format = $workbook->add_format(); # Add a format
$format->set_bold();#設置字體為粗體
$format->set_color('red');#設置單元格前景色為紅色
$format->set_align('center');#設置單元格居中

#使用行號及列號,向單元格寫入一個格式化和末格式化的字符串
$col = $row = 0;
$worksheet->write($row, $col, 'Hi Excel!', $format);
$worksheet->write(1, $col, 'Hi Excel!');

# 使用單元格名稱(例:A1),向單元格中寫一個數字。
$worksheet->write('A3', 1.2345);
$worksheet->write('A4', '=SIN(PI()/4)');
exit;

?以上就是Perl操作Excel的示例代碼,清楚明白了嗎,更多關于Perl的內容請繼續關注武林技術頻道。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 绩溪县| 阿勒泰市| 织金县| 太湖县| 普格县| 惠水县| 和顺县| 泰安市| 凤城市| 伽师县| 襄垣县| 西林县| 雅江县| 岚皋县| 靖远县| 塔城市| 南郑县| 和顺县| 水城县| 京山县| 前郭尔| 黄陵县| 花莲县| 墨脱县| 三门峡市| 阿图什市| 普洱| 安徽省| 嘉善县| 松溪县| 景洪市| 元阳县| 德州市| 巩留县| 永泰县| 湖北省| 洛阳市| 海阳市| 清镇市| 双峰县| 醴陵市|