Perl/Bash:将特定.XLS单元格的值回显到文本文件中
我有一个.XLS表,其中每个单元格都有纯文本值(带换行符)。 我需要使用bash/perl将特定单元格的值(按行号和列号)回显到文本文件中。 剧本构思:Perl/Bash:将特定.XLS单元格的值回显到文本文件中,perl,xls,Perl,Xls,我有一个.XLS表,其中每个单元格都有纯文本值(带换行符)。 我需要使用bash/perl将特定单元格的值(按行号和列号)回显到文本文件中。 剧本构思: inputxls=“$1” column=“$2” row=“$3” OutputExtFile=“$4” 调用脚本: 脚本table.xls 5 3 celltext.txt 文本文件的输出为: foo 酒吧 酒吧 foo (关于新线路) 这是为了处理只填充文本的.xls,不需要处理数学。 有什么想法吗?可能是重复的。请注意,这是一个老问题,
inputxls=“$1”
column=“$2”
row=“$3”
OutputExtFile=“$4”
调用脚本:
脚本table.xls 5 3 celltext.txt
文本文件的输出为:
foo
酒吧
酒吧
foo
(关于新线路)
这是为了处理只填充文本的.xls,不需要处理数学。
有什么想法吗?可能是重复的。请注意,这是一个老问题,但如果它真的是XLS,而不是XLSX,它仍然是正确的。还有其他模块。我找不到关于如何输出特定单元格(按行数和列数)的答案。上面的答案包括一个从特定单元格获取数据的完整工作示例。提示:相关函数称为get_cell。
#!/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();