2017-05-05 59 views
-2

我有一个.XLS表格,其中每个单元格都具有纯文本值(带有换行符)。 我需要使用bash/perl来将特定单元格的值(按行号和列号)回显到文本文件中。脚本的 理念:Perl/Bash:将特定.XLS单元格的值回复到文本文件

inputxls="$1" column="$2" row="$3" outputtextfile="$4"

调用脚本: 脚本table.xls 5 3 celltext.txt

输出到文本文件将是:

foo bar bar foo (尊重新行)

这是一个与只填充文本的.xls一起工作,没有必要与数学一起工作。 任何想法?

+1

可能重复[在Perl中解析Excel文件的最佳方法是什么?](http://stackoverflow.com/questions/429193/whats-the-best-way-to-parse-excel-file -in-perl的)。请注意,这是一个老问题,但如果它确实是XLS,而不是XLSX,它仍然是正确的。此外还有其他模块。 – 2017-05-05 13:58:47

+0

我找不到答案如何输出特定的单元格(按行和列数)。 – nagualcode

+0

最重要的答案包括一个从特定单元格获取数据的完整工作示例。提示:相关函数称为get_cell。 – 2017-05-05 19:07:34

回答

0
#!/usr/bin/perl 
use strict; 
use warnings; 
use Spreadsheet::Read; 



    sub get_cell { 
    # send the file the sheet and the cell as 
    # command line arguments 
    my ($file, $sheet, $cell) = @ARGV; 
    return 0 unless $file =~ /.*\.xls/i; 
    my $book = ReadData ($file); 
    return $book->[$sheet]{$cell}; 
} 

    my $output_file = 'test.txt'; 

    open (FH, '>>', $output_file) or die "Canoot open ' $output_file' $!"; 
    print FH get_cell(); 
相关问题