Hello Monks I am working on developing a perl API where I have designed the API script to extract a data from DB depending on the i/p given at the front end.Now I want to generate an excel file depending on the i/p that I will give in browser window.Below is the program which works fine and generates excel sheet if I entered the i/p from console window but gives an error like "Can't call method "add_worksheet" on an undefined value at /var/www/cgi-bin/excel_report.cgi line 57." If I try to give i/p through web browser.The corresponding code is as follows:
#!/usr/bin/perl -w
use CGI ':standard';
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
use DateTime::Format::ISO8601 qw( );
use strict;
use Spreadsheet::WriteExcel;
use lib "/view/sawans1_insert_data/vobs/pp/pptai/api/NightlyDB";
use API;
my @test_run_id;
my @total_passed;
my @date;
my $option_type;
my $user_input;
my $test_run_id;
my $test_run_list_ref;
my $sdt = DateTime::Format::ISO8601->parse_datetime(param('start_date'
+));
my $edt = DateTime::Format::ISO8601->parse_datetime(param('end_date'))
+;
for (my $dt = $sdt->clone(); $dt<=$edt; $dt->add( days => 1 )){
push @date,$dt->ymd();
}
$user_input->{pp_branch} = param('pp_branch');
# Create a new Excel workbook
my $file = "test_run.xls";
my $workbook = Spreadsheet::WriteExcel->new($file);
# Add a worksheet
my $worksheet = $workbook->add_worksheet();
# Add and define a format
my $format = $workbook->add_format(); # Add a format
$format->set_bold();
$format->set_color('red');
$format->set_align('center');
# Write a formatted and unformatted string, row and column notatio
+n.
my $col = my $row1 = 0;
$worksheet->write(0, 0, 'Date', $format);
$worksheet->write(0, 1, 'Nightly Web ID', $format);
$worksheet->write(0, 2, 'Number Of Tests Passed', $format);
my $row = 1;
my $i = 0;
foreach (@date){
#create hash reference variable for every date in array @date
$user_input->{start_date} = $_;
$user_input->{end_date} = $_;
#Call get_test_run function to create test run list refer
+ences
$test_run_list_ref = &API::get_test_run($user_input);
#For each such reference calculate # of objects by addition
foreach my $tr_obj (@$test_run_list_ref){
push @total_passed, $tr_obj->number_of_passed();
$tr_obj->nightly_web_id();
$worksheet->write($row,0, $_);
$worksheet->write($row,1,$test_run_id[$i]);
$worksheet->write($row,2,$total_passed[$i]);
$row++;
$i++;
}
}
print header(
-attachment=>'test_run.xls',
);
Kindly Let me know if anybody found out where I am mistaking !!!!