简体   繁体   English

如何在Perl中读取Excel文件?

[英]How can I read Excel files in Perl?

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. 目的是要有一个表,用户可以在其中输入一些数据(ftp目标或文件名)到表中。 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. 它的实现不必太优雅……只需要它或多或少地读取数据行即可。

The Spreadsheet::ParseExcel module can read Excel files. Spreadsheet :: ParseExcel模块可以读取Excel文件。 The documentation includes examples how to use it. 该文档包括如何使用它的示例。

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

Check out the synopsis in these modules: 查看这些模块中的概要:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM