如何在Perl中读取Excel文件?

时间:2023-01-15 12:36:35

I am looking for some examples/advice on how to write a Perl script to read data from an excel file then use the data read in (as a string hopefully) and pass it to another Perl file (as an argument).

我正在寻找一些关于如何编写Perl脚本以从excel文件读取数据然后使用读入的数据(希望作为字符串)并将其传递给另一个Perl文件(作为参数)的示例/建议。

The goal is to have a table in which the user can type some data (ftp destination or filename) into the table. Then my program will grab that data at do some automation with it. It does not have to be very elegant in implementation ... Just need it to read rows of data more or less.

目标是有一个表,用户可以在表中键入一些数据(ftp目标或文件名)。然后我的程序将使用它自动获取数据。它的实现不一定非常优雅......只需要它或多或少地读取数据行。

3 个解决方案

#1


13  

The Spreadsheet::ParseExcel module can read Excel files. The documentation includes examples how to use it.

Spreadsheet :: ParseExcel模块可以读取Excel文件。该文档包括如何使用它的示例。

#2


8  

You can use Spreadsheet::Read which will delegate to the appropriate module to read spreadsheets in a variety of formats such as Excel, OpenOffice and CSV.

您可以使用Spreadsheet :: Read,它将委派给相应的模块,以读取各种格式的电子表格,如Excel,OpenOffice和CSV。

On the other hand, given your problem description, I think you would be much better off using a standard configuration file format:

另一方面,鉴于您的问题描述,我认为使用标准配置文件格式会好得多:

#!/usr/bin/perl

use Config::Std;

read_config 'ftp.ini' => my %config;

for my $file ( keys %config ) {
    print "File: '$file'\n";
    print "$_: ", $config{$file}->{$_}, "\n"
        for qw( site protocol remote_name);
}

ftp.ini:

ftp.ini:

[c:\Documents and Settings\user\My Documents\this.txt]
site = ftp.example.com
protocol = ftp
remote_name = that.txt

#3


6  

Check out the synopsis in these modules:

查看这些模块中的概要:

#1


13  

The Spreadsheet::ParseExcel module can read Excel files. The documentation includes examples how to use it.

Spreadsheet :: ParseExcel模块可以读取Excel文件。该文档包括如何使用它的示例。

#2


8  

You can use Spreadsheet::Read which will delegate to the appropriate module to read spreadsheets in a variety of formats such as Excel, OpenOffice and CSV.

您可以使用Spreadsheet :: Read,它将委派给相应的模块,以读取各种格式的电子表格,如Excel,OpenOffice和CSV。

On the other hand, given your problem description, I think you would be much better off using a standard configuration file format:

另一方面,鉴于您的问题描述,我认为使用标准配置文件格式会好得多:

#!/usr/bin/perl

use Config::Std;

read_config 'ftp.ini' => my %config;

for my $file ( keys %config ) {
    print "File: '$file'\n";
    print "$_: ", $config{$file}->{$_}, "\n"
        for qw( site protocol remote_name);
}

ftp.ini:

ftp.ini:

[c:\Documents and Settings\user\My Documents\this.txt]
site = ftp.example.com
protocol = ftp
remote_name = that.txt

#3


6  

Check out the synopsis in these modules:

查看这些模块中的概要: