473,326 Members | 2,010 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,326 software developers and data experts.

Writing data to excel..using DB query..pls help

Hi ..I am very new to perl..can some one help me with this script pls..

I am Querying database and writing data to excel..

Here is my script:

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl -w
  2. use strict;
  3. use DBI;
  4. use DBD::DB2;
  5. use DBD::DB2::Constants;
  6. use Time::Local;
  7. use Spreadsheet::WriteExcel;
  8.  
  9. my $region = ("NORTH", "SOUTH", "WEST");
  10.  
  11. # Connect and turn autocommit off
  12. my $dbh = DBI->connect( 'dbi:DB2:eastdit', 'fttpdit', 'dit1234', { AutoCommit => 0 } )
  13.     or die "$DBI::errstr";
  14.  
  15. my $Excelfile = "/tmp/VWReport.xls";
  16.  
  17. #create a new instance
  18. my $excel = Spreadsheet::WriteExcel->new("$Excelfile");
  19. my $worksheet = $excel->addworksheet("VWFalloutNorth");
  20. my $now = localtime time;
  21. $worksheet->write(0, 0, "Report generated on :$now" );
  22. my $stmt = "select activity,duration,duedate,errorcode, startdate, order,assignedto from ivapp.voicewing_south_1";
  23.  
  24. my $sth = $dbh->prepare($stmt);
  25. my @data;
  26.  
  27. $sth->execute() or die $dbh->errstr;
  28.  
  29. while ( @data = $sth->fetchrow_array()){
  30.     my $activity = $data[1];
  31.     my $duration = $data[2];
  32.     my $duedate = $data[3];
  33.     my $errorcode = $data[4];
  34.     my $startdate = $data[5];
  35.     my $order = $data[6];
  36.     my $assignedto = $data[7];
  37.     my $row = 0;
  38.     my $col = 0;
  39.     foreach my $stmt (@data) {
  40.         $worksheet->write($row++, @data);
  41.         last;
  42.     }
  43. }
  44.  
  45. print "DONE \n";
  46. $sth->finish();
  47. $dbh->disconnect();
  48.  
plsssssssssssss help me with this..greatly helpfull if you can modify the script and post it
Aug 21 '07 #1
1 2518
thx guys...it worked for me in another way
Aug 22 '07 #2

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

Similar topics

0
by: Mzkhan | last post by:
Hi , Here is the situation: I am creating a web page from a perl script.. this web page has checkboxes which are from an oracle table - From this page I am creating sql query and passing the...
2
by: Fred | last post by:
Hi. How do I import while mapping an excel table to an access table please??? I've searched around and all I can find is a software product or code that does the same thing as the access...
1
by: Steven Stewart | last post by:
I have a user who has been using Excel for a while to keep statistics and print reports. She finds using it cumbersome because of long formulas and a lot of copying and pasting. I have designed...
6
by: Paul | last post by:
I was wondering if anyone has had an issue where using vba code to read an excel file and import the data into an access table some records are not imported from the excel file. It seems looking at...
7
by: Darren | last post by:
I have been attempting to create a reservation planning form in excel that imports Data from an Access database and inserts that information automaticly into the correct spreed sheet and the...
11
by: Mr. Smith | last post by:
Hello all, My code can successfully open, write to, format and save several worksheets in a workbook then save it by a given name, close and quit excel. My problem is that if I try and do it...
2
by: aland | last post by:
I've got an Excel spread sheet with one row of id's and I'd like to use these in a query and put the results into Excel. Basically I'd like to do something like SELECT txtFileTitle, txtFileYear...
8
by: jquest | last post by:
Hi Again; I have had help from this group before and want to thank everyone, especially PCDatasheet. My database includes a field called HomePhone, it uses the (xxx)xxx-xxx format to include...
1
by: =?Utf-8?B?ZmhpbGxpcG8=?= | last post by:
We have a code snippet that downloads data to Excel. it is writing row by row. This causes a performance issue. Any ideas on how to speed this up will be appreciated. Please find below an...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.