vicendominguez

dump xlsx in terminal and with grep you can search words

Mar 6th, 2013
382
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.19 KB | None | 0 0
  1. #!/usr/bin/env perl
  2. # with a "grep" in terminal you can search words in a excel
  3.  
  4.  use strict;
  5.  use warnings;
  6.  use Text::Iconv;
  7.  my $converter = Text::Iconv -> new ("utf-8", "windows-1251");
  8.  
  9.  # Text::Iconv is not really required.
  10.  # This can be any object with the convert method. Or nothing.
  11.  
  12.  use Spreadsheet::XLSX;
  13.  
  14.  my $excel = Spreadsheet::XLSX -> new ('/Sistemas/direccionamiento.xlsx', $converter);
  15.  
  16.  foreach my $sheet (@{$excel -> {Worksheet}}) {
  17.  
  18.         printf("Sheet: %s\n", $sheet->{Name});
  19.        
  20.         $sheet -> {MaxRow} ||= $sheet -> {MinRow};
  21.        
  22.          foreach my $row ($sheet -> {MinRow} .. $sheet -> {MaxRow}) {
  23.          
  24.                 $sheet -> {MaxCol} ||= $sheet -> {MinCol};
  25.                 printf "\n";
  26.                
  27.                 foreach my $col ($sheet -> {MinCol} ..  $sheet -> {MaxCol}) {
  28.                
  29.                         my $cell = $sheet -> {Cells} [$row] [$col];
  30.  
  31.                         if ($cell) {
  32. #                            printf("( %s , %s ) => %s\n", $row, $col, $cell -> {Val});
  33.                             printf("%s            ", $cell -> {Val});
  34.                         }
  35.  
  36.                 }
  37.  
  38.         }
  39.  
  40.  }
Add Comment
Please, Sign In to add comment