473,409 Members | 1,979 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,409 software developers and data experts.

Wrinting into an Excel Sheet File

Hi all , i need to write into an excel sheet file the data retreived from the database. i have the script but the problem is that i can't get the data written in the excel file.

Can anybody help pleeeassse.

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl 
  2. use strict;
  3. use warnings;
  4. use DBI;
  5. use DBD::mysql;
  6. use lib qw(.);
  7. use Bugzilla;
  8. use Bugzilla::Bug;
  9. use Bugzilla::Util;
  10. use Bugzilla::Constants;
  11. use Time::Local;
  12. use Spreadsheet::WriteExcel;
  13.  
  14.  
  15. my $dbh = DBI->connect('DBI:mysql:database=bugs;host=localhost', 'jinny', 'jinny') or die "Connection Error";
  16.  
  17. my $Excelfile = "./Report.xls";
  18.  
  19. #create a new instance
  20. my $excel = Spreadsheet::WriteExcel->new("$Excelfile");
  21. my $worksheet = $excel->addworksheet("Bugs Report");
  22. my $now = localtime time;
  23. $worksheet->write(0, 0, "Report generated on :$now" );
  24.  
  25. my $stmt = "SELECT * FROM bugs ORDER BY bug_id";
  26.  
  27.  
  28. my $sth = $dbh->prepare($stmt);
  29. my @data;
  30.  
  31. $sth->execute() or die $dbh->errstr;
  32.  
  33. while ( @data = $sth->fetchrow_array()){
  34.     my $bug_id = $data[1];
  35.     my $assigned_to = $data[2];
  36.     my $bug_file_loc = $data[3];
  37.     my $bug_severity = $data[4];
  38.     my $bug_status = $data[5];
  39.     my $creation_ts = $data[6];
  40.     my $delta_ts = $data[7];
  41.     my $short_desc = $data[8];
  42.     my $op_sys = $data[9];
  43.     my $priority = $data[10];
  44.     my $product_id = $data[11];
  45.     my $rep_platform = $data[12];
  46.     my $reporter = $data[13];
  47.     my $version = $data[14];
  48.     my $component_id = $data[15];
  49.     my $resolution = $data[16];
  50.     my $target_milestone = $data[17];
  51.     my $qa_contact = $data[18];
  52.     my $status_whiteboard = $data[19];
  53.     my $votes = $data[20];
  54.     my $keywords = $data[21];
  55.     my $lastdiffed = $data[22];
  56.     my $everconfirmed = $data[23];
  57.     my $reporter_accessible = $data[24];
  58.     my $cclist_accessible = $data[25];
  59.     my $estimated_time = $data[26];
  60.     my $remaining_time= $data[27];
  61.     my $deadline = $data[28];
  62.     my $alias= $data[29];
  63.     my $row = 0;
  64.     my $col = 0;
  65.     foreach my $stmt (@data) {
  66.         $worksheet->write($row++, @data);
  67.         last;
  68.     }
  69. }
  70.  
  71. $sth->finish();
  72. $dbh->disconnect();
  73.  
  74.  
Aug 31 '07 #1
6 1871
numberwhun
3,509 Expert Mod 2GB
Just a couple of quick questions back at you:

1. What errors were you getting when executing, if any?

2. Do you have Micro$oft Excel installed on this machine?

Regards,

Jeff
Aug 31 '07 #2
Hi Jeff, how r u?

As answers to ur quesrtions, i am not guetting any errors, there is no syntax errors but there is no retreival for the data as well.
I have also Microsoft Excel installed on my machine.

Regards
Sep 3 '07 #3
just wanna add that i get in the excel sheet file in the first row a data that is far from being the data of the database:

Report generated on :Mon Sep 3 09:31:40 2007 2 2 8 12 15 6 9 5 8 2 6 2 19 12 5 22 17 18 14 14 14 14 21 14 28 14 14 2 15 14 6 28 23 14 14 9 9 21 13 8 8 13 14 22 15 23 23 14 22 28 28 28 14 15 15 22 2 14 14 5 9 14 14 14 5 14 14 12 14 14 14 14 28 14 14 8 14 14 14 8 14 14 14 14 14 14 28 8 22 15 28 28 15 28 14 21 21 21 14 14 8 14 14 5 14 14 14 15 21 14 14 14 34 12 14 2 2 2 2 14 23 14 6 14 21 21 14 35 14 19 13 19 19 19 19 19 26 21 14 19 17 18 9 31 32 32 14 31 14 35 32 12 22 14 2 2 30 30 31 30 32 13 13 23 23 23 14 14 28 28 28 30 28 28 9 28 28 32 2 31 28 2 6 2 21 30 9 14 14 30 30 30 30 14 14 30 28 28 31 12 14 28 31 9 9 9 2 9 31 30 30 32 2 20 6 2 30 2 17 17 19 18 26 23 19 26 19 26 19 26 11 11 20 33 33 33 20 20 20 20 20 20 33 20 33 30 9 30 32 30 31 9 15 15 30
Sep 3 '07 #4
It's ok i have done this , thank u all very much for ur help , i appreciate it very much.
Sep 3 '07 #5
numberwhun
3,509 Expert Mod 2GB
It's ok i have done this , thank u all very much for ur help , i appreciate it very much.
That's great, but for those of use scratching our heads, what was the issue and what was your solution?
Sep 3 '07 #6
That's great, but for those of use scratching our heads, what was the issue and what was your solution?
Hi all,
I have a select stmt like this..
$q= "select empl_no,empl_name,doj,attnd as total,uninformed as .......id,1 from salary where category='$cat' and month='$cmprmonth' order by id";

and i am binding the vaues to variables, $empl_no.. etc.,... and iam printing all the values in table format on web page.

But I want to write into an excel sheet in a same table format when i click on the button.. because i want to take a print out from that excel report.

how to do it? please tell me its urgent... help me out in this...

regards,
greet
Nov 19 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

13
by: Allison Bailey | last post by:
Hi Folks, I'm a brand new Python programmer, so please point me in the right direction if this is not the best forum for this question.... I would like to open an existing MS Excel spreadsheet...
9
by: Paul | last post by:
Hi all Arggghhh........... The problem.....I want the user to be able to create an excel document and name particular cells in the document where they want the data to be placed and then save...
3
by: Mads Petersen | last post by:
I'm stuck in this code. Hope you can and will help me. I launch it from excel. I have made the following code work, but not as i whant. I need the ranges to be working with something like xlDown....
3
by: rlntemp-gng | last post by:
RE: Access 2003/Excel 2003 Problem: After I close the Access application completely, I go out to the Task Manager and there is an Excel.exe object still sitting out there. My Access...
11
by: poolboi | last post by:
hi guys, below is a script that i need yr help on i got this to print out a csv to excel i'm trying to modify it to read a .txt file to convert an excel hm...doesn't seem to work still any idea...
1
by: manishabh77 | last post by:
I will be obliged if anybody can help me with this problem: I am trying to extract data from an excel sheet that matches IDs given in column 4 of the excel sheet.I have stored those query IDs in an...
2
by: pulavarthipraveen | last post by:
Overview: We have a requirement in the c#.NET 1.0 windows application. There will be some input text file in the user’s machine. The user should browse and select the input text file and also select...
7
by: TG | last post by:
hi! I am trying to create a sql server table from an excel sheet. Here is the code I have: 'This procedure the xlsx file and dumps it to a table in SQL Server
8
blazedaces
by: blazedaces | last post by:
So I have a program below which writes an excel file with multiple sheets based on inputs of sheet names, data, cell types, etc. It uses Apache POI, which is currently the only thing I found...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.