Presenta la información de la tabla Excel en forma de tabla html.

0 views
Skip to first unread message

Ricardo de Jesús Pelcastre Cervantes

unread,
Sep 4, 2006, 11:24:26 AM9/4/06
to pozarica
#!/usr/bin/perl
#
# Presenta la información de la tabla Excel
# en forma de tabla html
#
# Joaquín Ferrero. 2006/07/12T00:59:00Z
#

### Librerías
use CGI qw':standard *table *td *th';
use Spreadsheet::ParseExcel;

### Condiciones de ejecución
#use warnings;
#use strict;
$|++; # No output buffering

### Conexión con la hoja de cálculo
my $libro;
# Se podría pasar como argumento...
# $libro = shift @ARGV;
# Aquí lo leemos de uno determinado
$libro = 'BODEGAS.xls';

# Conexión
my $oExcel = Spreadsheet::ParseExcel->new;
my $oBook = $oExcel->Parse( $libro );

# Creación de la página web
print
header,
start_html("Tabla de Excel $libro"),
h1("Tabla de Excel $libro"),hr,
;

# Información del libro
print
"FICHERO :", $oBook->{File} , br,
"#HOJAS :", $oBook->{SheetCount} , br,
"AUTOR :", $oBook->{Author} , br,
;

# Bucle por todas las hojas del libro
for (my $iSheet=0; $iSheet < $oBook->{SheetCount} ; $iSheet++) {
my $oWkS = $oBook->{Worksheet}[$iSheet];
print "--------- HOJA:", $oWkS->{Name}, br;
print start_table({-border=>1});

# Bucle por todas las filas
for(
my $iR = $oWkS->{MinRow};
defined $oWkS->{MaxRow} && $iR <= $oWkS->{MaxRow};
$iR++
) {
print start_Tr,"\n";

# Bucle por todas las columnas
for(
my $iC = $oWkS->{MinCol};
defined $oWkS->{MaxCol} && $iC <= $oWkS->{MaxCol};
$iC++
) {
my $oWkC = $oWkS->{Cells}[$iR][$iC];
print start_th, $oWkC->{Val}, end_th if $iR ==
$oWkS->{MinRow};
print start_td, $oWkC->{Val}, end_td unless $iR ==
$oWkS->{MinRow};
#print "( $iR , $iC ) =>", $oWkC->Value, br if $oWkC;
# Dato con formato
#print "( $iR , $iC ) =>", $oWkC->{Val}, br if $oWkC;
# Dato original
print "\n"; # For Humans, only
}
print end_Tr,"\n";
}
print end_table;
}

print end_html;

Reply all
Reply to author
Forward
0 new messages