Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use strict;
- use warnings;
- use DBI;
- use Spreadsheet::WriteExcel;
- # uso: perl nomefile.pl > nomexls.xls
- my $DBI_driver='mysql';
- my $database='prova';
- my $host='localhost';
- my $port='3306';
- my $user='root';
- my $password='';
- my $dbh;
- my $dsn="DBI:$DBI_driver:database=$database;host=$host;port=$port";
- die "$DBI::errstr" if (!($dbh=DBI->connect($dsn,$user,$password)));
- my $statement=q[select * from utente];
- my $ary_ref = $dbh->selectall_arrayref($statement);
- binmode(STDOUT);
- my $workbook = Spreadsheet::WriteExcel->new(\*STDOUT);
- my $worksheet = $workbook->add_worksheet('pippo');
- foreach my $riga (0 .. scalar(@$ary_ref)) {
- my $elem=$ary_ref->[$riga];
- next if (!defined $elem);
- foreach my $col (0 .. scalar (@$elem)) {
- $worksheet->write($riga, $col, $elem->[$col]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement