Wednesday, March 6, 2013

dump xlsx in terminal and with "grep" tool you can search words

I worked in a company with the network inventory in a Excel. It was useful to search names and ips from linux terminal.

It dumps the xlsx file to console and I was using "grep" to search words or IP or whatever you want . May be you can get something else:
#!/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});
}
}
}
}
view raw dumpxlsx.pl hosted with ❤ by GitHub
:)