473,387 Members | 1,582 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,387 software developers and data experts.

retreiving data to an excel file via a webpage

hello all,

I'm trying to write a code to retreive data from a database to an excel file, I achieved my code and everything is going good by running it through unix, but when I create a webpage to help users to extract data via internet I got an internal server error! anyone can help me???

thank you..

Expand|Select|Wrap|Line Numbers
  1.  
  2. #!/usr/bin/perl
  3.  
  4. use strict;
  5. use warnings;
  6. use DBI;
  7. use DBD::mysql;
  8. use lib qw(.);
  9. use Time::Local;
  10. use Spreadsheet::WriteExcel;
  11.  
  12. my $query_string = $ENV{'QUERY_STRING'};
  13.  
  14.  
  15. my $query_string = "b.bug_id=on&b.assigned_to=on&pf.login_name=on&b.creation_ts=on&b.short_desc=on&pd.name=on&b.rep_platform=on";
  16.  
  17. # Split the name-value pairs
  18. my @pairs = split('&', $query_string);
  19.  
  20.  
  21. my $dbh = DBI->connect('DBI:mysql:database=bugs;host=localhost', 'jinny', 'jinny',{RaiseError => 1, PrintError => 0}) or die $DBI::errstr;
  22.  
  23. #create a new instance
  24. my $now = localtime time;
  25.  
  26. my $workbook = Spreadsheet::WriteExcel->new("Report.xls");
  27. my $worksheet= $workbook->add_worksheet('report');
  28. $worksheet->write(0, 0, "Report generated on :$now");
  29.  
  30.  
  31. my $stmt = "SELECT ";
  32. my $counter = 0;
  33. foreach my $pair (@pairs)
  34. {
  35.    (my $name, my $value) = split('=', $pair);
  36.    $stmt = $stmt."$name, ";
  37.    $worksheet->write(1, $counter, "$name" );
  38.    $counter ++;
  39. }
  40.  
  41.   chop ($stmt);
  42.   chop ($stmt);
  43.  
  44. $stmt = $stmt." FROM bugs b, profiles pf, products pd WHERE b.assigned_to= pf.userid AND b.product_id = pd.id ORDER BY bug_id";
  45.  
  46. my $sth = $dbh->prepare($stmt);
  47.  
  48. $sth->execute();
  49. my $row=0;
  50. my $col=0;
  51. if($sth->rows){
  52. ++$row;
  53. while ( my $array_ref = $sth ->fetchrow_arrayref){
  54.  
  55.    $worksheet->write_row(++$row,$col,$array_ref);
  56.       }
  57.  
  58.       print "Content-Type: text/html\n\n";
  59.       print "<html><head>";
  60.       print "<title>Report</title>";
  61.       print "<body>";
  62.                 print "Data retrieved";
  63.       print "</body>";
  64.       print "</html>";
  65.  
  66.  
  67. }
  68. else {
  69.  
  70.  
  71.       print "Content-Type: text/html\n\n";
  72.       print "<html><head>";
  73.       print "<title>Report</title>";
  74.       print "<body>";
  75.                      print "No data retrieved \n";
  76.       print "</body>";
  77.       print "</html>";
  78. }
  79.  
  80. $sth->finish();
  81. $dbh->disconnect();
  82.  
Sep 10 '07 #1
1 1835
my internal server error is:

Can't call method "add_worksheet" on an undefined value at /home/yrizk/bin/report.cgi line 28.
Sep 10 '07 #2

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

Similar topics

1
by: marty | last post by:
I have a webpage that displays data from a SQL database in table format. I found information on how to create a way to allow a user to download this information to Excel using 'Header()' in the...
4
by: RK | last post by:
Hi, In my application, I need to copy data from an Excel file into a SQL table. The article related to this can be found at http://support.microsoft.com/default.aspx?scid=kb%3Ben-us%3B306572 ...
0
by: Pauravi | last post by:
Hi I want to export web controls value into the Excel file. Detail : I have a text box where user can type the filename and on click of button a dialog box should appear that will ask user to...
1
by: Alex | last post by:
Hi, Everyday, I download data from a webpage and manually input data into my MS Access database. I am thinking of automate the routine by a VB script. The webpage I am visiting will return a...
3
by: MJ | last post by:
Is there a VB.NET (1.1 or 2.0) equivalent for Excel's ? Below is a copy of an example of the Excel VBA that I have been using to pull some data off a webpage. I've got a couple of simple...
2
by: chalres | last post by:
i'd like to make some word and excel file from webpage this word file is the same as the webpage how can i make it?
10
by: sanou | last post by:
Hi does anyone know if the following is possible? I have an excel spreadsheet with values that i need transferred to a certain website's form. for instance, i have a value in excel spreadsheet...
1
by: roger.rigsby | last post by:
Ok I know how to get the data I want from mysql but I need to actually do something with this data and then send it back to mySQL. Company heads love the spreadsheet view so this is serious...
8
by: KeithChang | last post by:
Hi, I'm building a web application in VB.NET 1.1 where users will upload Excel files at this webpage and the web application will transfer the data from the uploaded Excel file into MS SQL 2000....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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...

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.