File: parse.pl

package info (click to toggle)
libspreadsheet-parseexcel-perl 0.6500-1.1%2Bdeb11u1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,852 kB
  • sloc: perl: 9,442; makefile: 12
file content (64 lines) | stat: -rwxr-xr-x 1,509 bytes parent folder | download | duplicates (6)
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/perl
use strict;
use warnings;

use Spreadsheet::ParseExcel;
use Getopt::Long qw(GetOptions);

my $file;
my $help;
my $dump;

my ($row, $col);

GetOptions(
    "file=s" => \$file,
    "help"   => \$help,

    "dump"   => \$dump,
    "row=i"  => \$row,
    "col=i"  => \$col,
) or usage();
usage() if $help;
usage() if not $file;

my $excel = Spreadsheet::ParseExcel::Workbook->Parse($file);
if ($dump) {
    foreach my $sheet (@{$excel->{Worksheet}}) {
        printf("Sheet: %s\n", $sheet->{Name});
        $sheet->{MaxRow} ||= $sheet->{MinRow};
        foreach my $row ($sheet->{MinRow} .. $sheet->{MaxRow}) {
            $sheet->{MaxCol} ||= $sheet->{MinCol};
            foreach my $col ($sheet->{MinCol} ..  $sheet->{MaxCol}) {
                my $cell = $sheet->{Cells}[$row][$col];
                if ($cell) {
                    printf("( %s , %s ) => %s\n", $row, $col, $cell->{Val});
                }
            }
        }
    }
}
if (defined $row and defined $col) {
    foreach my $sheet (@{$excel->{Worksheet}}) {
        printf("Sheet: %s\n", $sheet->{Name});
        my $cell = $sheet->{Cells}[$row][$col];
        printf("( %s , %s ) => '%s'\n", $row, $col, $cell->{Val});
        printf("( %s , %s ) => '%s'\n", $row, $col, $cell->Value);
    }
}


sub usage {
    print <<"END_USAGE";
Usage: $0
        --file FILENAME
        --dump

        --row  ROW
        --col  COL

        --help
END_USAGE
    exit;
}