Sport Girl
09-03-2007, 08:29 AM
Hi everybody,
can anyone help me, please this is urgent.
I have the task to retreive data from a MySQL database to an excel sheet file.
I have done the code with no syntax errors but the fact is that i can't get the data retreived or written in the excel sheet file.
I really need ur help please.
[CODE]
#!/usr/bin/perl
use strict;
use warnings;
use DBI;
use DBD::mysql;
use lib qw(.);
use Bugzilla;
use Bugzilla::Bug;
use Bugzilla::Util;
use Bugzilla::Constants;
use Time::Local;
use Spreadsheet::WriteExcel;
my $dbh = DBI->connect('DBI:mysql:database=bugs;host=localhost', '***', '***') or die "Connection Error";
my $Excelfile = "./Report.xls";
#create a new instance
my $excel = Spreadsheet::WriteExcel->new("$Excelfile");
my $worksheet = $excel->addworksheet("Bugs Report");
my $now = localtime time;
$worksheet->write(0, 0, "Report generated on :$now" );
my $stmt = "SELECT * FROM bugs ORDER BY bug_id";
my $sth = $dbh->prepare($stmt);
my @data;
$sth->execute() or die $dbh->errstr;
while ( @data = $sth->fetchrow_array()){
my $bug_id = $data[1];
my $assigned_to = $data[2];
my $bug_file_loc = $data[3];
my $bug_severity = $data[4];
my $bug_status = $data[5];
my $creation_ts = $data[6];
my $delta_ts = $data[7];
my $short_desc = $data[8];
my $op_sys = $data[9];
my $priority = $data[10];
my $product_id = $data[11];
my $rep_platform = $data[12];
my $reporter = $data[13];
my $version = $data[14];
my $component_id = $data[15];
my $resolution = $data[16];
my $target_milestone = $data[17];
my $qa_contact = $data[18];
my $status_whiteboard = $data[19];
my $votes = $data[20];
my $keywords = $data[21];
my $lastdiffed = $data[22];
my $everconfirmed = $data[23];
my $reporter_accessible = $data[24];
my $cclist_accessible = $data[25];
my $estimated_time = $data[26];
my $remaining_time= $data[27];
my $deadline = $data[28];
my $alias= $data[29];
my $row = 0;
my $col = 0;
foreach my $stmt (@data) {
$worksheet->write($row++, @data);
last;
}
}
$sth->finish();
$dbh->disconnect();
can anyone help me, please this is urgent.
I have the task to retreive data from a MySQL database to an excel sheet file.
I have done the code with no syntax errors but the fact is that i can't get the data retreived or written in the excel sheet file.
I really need ur help please.
[CODE]
#!/usr/bin/perl
use strict;
use warnings;
use DBI;
use DBD::mysql;
use lib qw(.);
use Bugzilla;
use Bugzilla::Bug;
use Bugzilla::Util;
use Bugzilla::Constants;
use Time::Local;
use Spreadsheet::WriteExcel;
my $dbh = DBI->connect('DBI:mysql:database=bugs;host=localhost', '***', '***') or die "Connection Error";
my $Excelfile = "./Report.xls";
#create a new instance
my $excel = Spreadsheet::WriteExcel->new("$Excelfile");
my $worksheet = $excel->addworksheet("Bugs Report");
my $now = localtime time;
$worksheet->write(0, 0, "Report generated on :$now" );
my $stmt = "SELECT * FROM bugs ORDER BY bug_id";
my $sth = $dbh->prepare($stmt);
my @data;
$sth->execute() or die $dbh->errstr;
while ( @data = $sth->fetchrow_array()){
my $bug_id = $data[1];
my $assigned_to = $data[2];
my $bug_file_loc = $data[3];
my $bug_severity = $data[4];
my $bug_status = $data[5];
my $creation_ts = $data[6];
my $delta_ts = $data[7];
my $short_desc = $data[8];
my $op_sys = $data[9];
my $priority = $data[10];
my $product_id = $data[11];
my $rep_platform = $data[12];
my $reporter = $data[13];
my $version = $data[14];
my $component_id = $data[15];
my $resolution = $data[16];
my $target_milestone = $data[17];
my $qa_contact = $data[18];
my $status_whiteboard = $data[19];
my $votes = $data[20];
my $keywords = $data[21];
my $lastdiffed = $data[22];
my $everconfirmed = $data[23];
my $reporter_accessible = $data[24];
my $cclist_accessible = $data[25];
my $estimated_time = $data[26];
my $remaining_time= $data[27];
my $deadline = $data[28];
my $alias= $data[29];
my $row = 0;
my $col = 0;
foreach my $stmt (@data) {
$worksheet->write($row++, @data);
last;
}
}
$sth->finish();
$dbh->disconnect();