-
Notifications
You must be signed in to change notification settings - Fork 2
/
git-xlsx-textconv.pl
executable file
·56 lines (43 loc) · 1.34 KB
/
git-xlsx-textconv.pl
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
#!/usr/bin/env perl
use strict;
use warnings;
use Spreadsheet::XLSX;
my $xlsx_file = shift;
die "usage: $0 file.xlsx" unless $xlsx_file && $xlsx_file =~ /\.xlsx\z/;
my $xlsx = Spreadsheet::XLSX->new($xlsx_file);
for my $sheet (@{ $xlsx->{Worksheet} }) {
sheet_walk($sheet);
}
sub sheet_walk {
my $sheet = shift;
my $sheet_name = $sheet->{Name};
$sheet_name =~ s/([\[\]])/\\$1/g;
for my $row ($sheet->{MinRow}..($sheet->{MaxRow} || $sheet->{MinRow})) {
my @cells;
if (defined $sheet->{Cells}[$row] && ref($sheet->{Cells}[$row]) eq 'ARRAY') {
for my $cell (@{ $sheet->{Cells}[$row] }) {
if ($cell && defined $cell->{Val}) {
my $val = $cell->{Val};
$val =~ s/\\/\\\\/g;
$val =~ s/\r/\\r/g;
$val =~ s/\n/\\n/g;
$val =~ s/\t/\\t/g;
push @cells, $val;
} else {
push @cells, '';
}
}
}
printf "[%s]: %s\n", $sheet_name, join("\t", @cells);
}
}
__END__
=head1 name
git-xlsx-textconv.pl - git text converter for xlsx file
=head1 README
show README.md
=head1 LICENSE
Copyright (C) Kazuhiro Osawa 2014-
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut