2017-05-05 60 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(); 
相關問題