-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathXLSgrep
More file actions
executable file
·39 lines (33 loc) · 958 Bytes
/
Copy pathXLSgrep
File metadata and controls
executable file
·39 lines (33 loc) · 958 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#! /usr/bin/perl
# XLSgrep - search inside Microsoft Excel files
#
# Usage: XLSgrep <search_pattern> file1 file2 ... fileX
# cat file.xls | XLSgrep <search_pattern>
#
# Example: XLSgrep "[A-Z]\d{4,5}" cells.xls
#
# Written by Jon Allen (JJ) <jj@jonallen.info>
# http://perl.jonallen.info/projects/xlstools
#
# This program is free software - you may distribute it
# and/or modify it under the same terms as Perl itself.
# See http://perldoc.perl.org/index-license.html for details.
use strict;
use warnings;
use open IN => ":bytes";
use Spreadsheet::ParseExcel;
my $pattern = shift @ARGV or die("Search pattern must be supplied\n");
my $excel = Spreadsheet::ParseExcel->new(
NotSetCell => 1,
CellHandler => sub {
my ($workbook,$sheet_index,$row,$col,$cell) = @_;
if (my $value = $cell->Value) {
chomp $value;
print "$value\n" if ($value =~ /$pattern/);
}
}
);
undef $/;
while (<>) {
$excel->Parse(\$_);
}