如何使用Perl在Excel XLS文件上保存数据? [英] How to save data on excel xls file using perl?

查看:57
本文介绍了如何使用Perl在Excel XLS文件上保存数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用像这样的perl将excel文件另存为.csv:

I'm able to save the excel file as .csv using perl like this :

print "Content-type: application/vnd.ms-excel\n";
print "Content-Disposition: attachment;filename=\"file name.xls\"\n\n";    
print"Fruits, Cost";       

#然后循环播放结果.

但是我需要将其另存为.xls,因为我想使用颜色.有人可以帮忙吗?

Yet I need to save this as .xls cause I want to use colours. Any one can help?

推荐答案

我强烈建议电子表格::WriteExcel 满足您的需求.该库完全用Perl编写,因此您需要做的就是将CPAN库上传到您的网站并指定特定位置.图书馆文档和下面的代码片段将帮助您入门.

I highly recommend Spreadsheet::WriteExcel for your needs. The library is entirely written in Perl, so all you need to do is upload the CPAN library to your web site and specify the specific location. The library documentation and the code snippet below should get you started.

#!/usr/bin/perl -w
use strict;
use lib qw(./lib);   # Place for the downloaded WriteExcel library
use Spreadsheet::WriteExcel;

# Send headers
print "Content-type: application/vnd.ms-excel\n";
print "Content-disposition: attachment;filename=rollcharts.org.xls\n\n";

# Create a new workbook and add a worksheet
my $workbook  = Spreadsheet::WriteExcel->new("-");
my $worksheet = $workbook->add_worksheet("Colorful Example");

# Create a new format with red colored text
my $format = $workbook->add_format();
$format->set_color('red');

# Add header    
$worksheet->write(0, 0, "Fruit.", $format);
$worksheet->write(0, 1, "Cost", $format);

# Add Data
$worksheet->write(1, 0, "Apple");
$worksheet->write(1, 1, "10.25");

# Close Workbook
$workbook->close();

这篇关于如何使用Perl在Excel XLS文件上保存数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆