【问题标题】:Perl/Bash: Echo the value of an specific .XLS cell to a text filePerl/Bash:将特定 .XLS 单元格的值回显到文本文件
【发布时间】:2017-05-10 02:54:04
【问题描述】:

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

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

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

到文本文件的输出是:

foo bar bar foo (尊重换行)

这适用于仅填充文本的 .xls,无需使用数学。 有什么想法吗?

【问题讨论】:

  • What's the best way to parse Excel file in Perl? 的可能重复项。请注意,这是一个老问题,但如果它真的是 XLS,而不是 XLSX,它仍然是正确的。还有其他模块。
  • 我在那个答案中找不到如何输出特定单元格(按行号和列号)。
  • 最佳答案包括一个从特定单元格获取数据的完整工作示例。提示:相关函数称为get_cell。

标签: perl xls


【解决方案1】:
#!/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();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多