Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 82 lines (61 sloc) 1.58 kb
84a255a @j3nnn1 subiendo otro viejo perl script
authored
1 #!/usr/bin/perl -w
14fd632 @j3nnn1 Encabezado listo
authored
2 #%%% made by j3nnn
3 #%%% license: GPLv3
a19c7f8 @Jenn2 Modificado comillas dobles por simples gracias a barney
Jenn2 authored
4
84a255a @j3nnn1 subiendo otro viejo perl script
authored
5
14fd632 @j3nnn1 Encabezado listo
authored
6 use strict;
84a255a @j3nnn1 subiendo otro viejo perl script
authored
7 use Spreadsheet::WriteExcel::FromDB;
8 use Spreadsheet::WriteExcel;
9 use DBI;
10 use DBD::mysql;
11 use Data::Dumper;
12
a19c7f8 @Jenn2 Modificado comillas dobles por simples gracias a barney
Jenn2 authored
13 require '../configs/configtabletoexcelv1.pl';
84a255a @j3nnn1 subiendo otro viejo perl script
authored
14
15 our $dsn;
16 our $user;
17 our $password;
18 my $dbh;
19 my $sth;
20
21 #conexion a BD
22 $dbh = DBI->connect($dsn, $user, $password);
23
24 #Obteniendo listado de tablas
25
ae78a05 @j3nnn1 una tonteria
authored
26 $sth = $dbh->prepare(q{show tables});
84a255a @j3nnn1 subiendo otro viejo perl script
authored
27 $sth->execute();
28 my $data = $sth->fetchall_arrayref();
29 my $sizearray = $#$data;
30
31 #declarando variables a utilizar
32
33 my @result;
34 my @tablas;
35 my @name; #nombre del campo de la tabla
36 my $i;
37 my $j=0;
38 my $k;
39 my $l;
40 my $workbook;
41 my $worksheet;
42 my $format;
43 my @datos;
44
45 #armando consulta de las tablas
46
47 for ($i=0; $i<$#$data; $i++) {
48
49 $sth = $dbh->prepare(qq{select * from $data->[$i][0]});
50 $sth->execute();
51 @name = $sth->{NAME};
52 #@tablas = $sth->fetchall_arrayref();
53
54 #contenido de tablas es pasado a una hoja de excel
55
56 $workbook = Spreadsheet::WriteExcel->new(qq{$data->[$i][0].xls});
57 $worksheet = $workbook->add_worksheet();
58 # aplicando formato del encabezado.
59
60 $format = $workbook->add_format();
61
62 $format->set_bold();
63 $format->set_color('black');
64
65 # worksheet añadiendo encabezado de tabla
66 for ($j=0; $j<=($#name+1); $j++){
67
68 $worksheet->write(0, $j, "$name[0][$j]", $format);
69 }
70
71 # worksheet añadiendo datos
72 $k=1;
73 while (@datos = $sth->fetchrow_array() ) {
74 for ($l=0; $l<($#datos + 1); $l++){
75 $worksheet->write($k,$l, $datos[$l]);
76 }
77
78 $k++;
79 }
80 exit 0;
81 }
Something went wrong with that request. Please try again.