Created
February 5, 2014 09:42
-
-
Save vicendominguez/8820203 to your computer and use it in GitHub Desktop.
Dump a excel file (xlsx) to terminal (grep after to search words)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
# with a "grep" in terminal you can search words in a excel | |
use strict; | |
use warnings; | |
use Text::Iconv; | |
my $converter = Text::Iconv -> new ("utf-8", "windows-1251"); | |
# Text::Iconv is not really required. | |
# This can be any object with the convert method. Or nothing. | |
use Spreadsheet::XLSX; | |
my $excel = Spreadsheet::XLSX -> new ('/systems/ipaddr.xlsx', $converter); | |
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}; | |
printf "\n"; | |
foreach my $col ($sheet -> {MinCol} .. $sheet -> {MaxCol}) { | |
my $cell = $sheet -> {Cells} [$row] [$col]; | |
if ($cell) { | |
# printf("( %s , %s ) => %s\n", $row, $col, $cell -> {Val}); | |
printf("%s ", $cell -> {Val}); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment