Ver Mensaje Individual
  #6 (permalink)  
Antiguo 11/07/2006, 19:40
jferrero
Colaborador
 
Fecha de Ingreso: mayo-2006
Ubicación: Valladolid
Mensajes: 525
Antigüedad: 18 años, 10 meses
Puntos: 11
Un ejemplo:

Código:
#!/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;
En poco más de 70 líneas, contando comentarios. Se podría haber hecho más corto, pero no quedaría claro salvo para los que utilizan SpreadSheet::ParseExcel con frecuencia...

Mira como queda...

O de forma más bonita