开发者

Python or Perl for creating an Excel spreadsheet on Linux

开发者 https://www.devze.com 2023-02-06 05:19 出处:网络
I have a Python program running on a Linux machine that writes out data to a CSV file. The client now wants the CSV data written to an Excel file. The Excel file needs to be based on a template - comp

I have a Python program running on a Linux machine that writes out data to a CSV file. The client now wants the CSV data written to an Excel file. The Excel file needs to be based on a template - company Logo etc. It also needs to highlight certain rows if a date field is in a certain range.

The program is proprietary so I don't want to use anything that will make it com开发者_JAVA百科e under the GPL.

Is there a Python solution that meets these requirements? Would it be better to write a separate Perl script to process the CSV output and create the Excel file. My skill level in both languages is about the same.


The perl libraries are Excel::Writer::XLSX (for .xlsx) or Spreadsheet::WriteExcel (for .xls).


I dont know how complex the template is, but check out http://sourceforge.net/projects/pyexcelerator/

Its a library to create excel files in python.


If you want to attempt this in Perl, have a look at Spreadsheet::Wright

It has detailed examples and also allows you to highlight certain rows by making them bold, changing the colors, etc.

Specifically, this is the example that should help you:

my $sp=Spreadsheet::Wright->new(
    file        => 'employees.xls',
    styles      => {
        important => { font_weight => 'bold' },
    },
);
$sp->addrow(
    { content => 'First Name', font_weight => 'bold' },
    { content => 'Last Name',  font_weight => 'bold' },
    { content => 'Age',        style => 'important' },
);
$sp->addrow("John","Doe",34);
$sp->addrow("Susan","Smith",28);
0

精彩评论

暂无评论...
验证码 换一张
取 消