Unable to create spreadsheet in cgi script

hi folks,

I am trying to download xlsx from cgi page in browser but not sure where I made a mistake.

the cgi script contains the code for creating xlsx and just by clicking on the image I should be able to

#!/usr/bin/perl -w
use Excel::Writer::XLSX;
use DBI;
use DBD::mysql;
use CGI;
use CGI qw(:standard);
use CGI::Carp qw ( fatalsToBrowser );

 $q=new CGI;


$report_year = $q->param('Field_year');
$report_month = $q->param('Field_month');
$report_year = $q->param('Field_year');
$string="$report_month"." "."$report_year"." "."Network Availability Report";

$report_name="Network_Availability_Report_".$report_month."_".$report_year.".xlsx";
   
my $workbook   = Excel::Writer::XLSX->new("$report_name");
my $worksheet  = $workbook->add_worksheet($report_month);


print "Content-type: text/html\n\n";
print '<html>';
print '<head>';
print '<title>Hello Word - First CGI Program</title>';
print '</head>';
print '<body>';
print "<h2>$report_month</h2>";
print "<h2>$report_year</h2>";
#print qq~<a href="http://25.209.200.143/$report_name"><img src="http://25.209.200.143/tcs/images/xlsx.png" width=40 height=40></a>~;
print '</body>';
print '</html>';

1;

If I click on the image then I need to open the spreadsheet.

I have managed to execute the same in windows and able to display it on windows.

Now I am deploying the code in unix but failed to display this cgi script.

Error

Can't call method "add_worksheet" on an undefined value at /srv/www/cgi-bin/gnsncc/temp_final_report.cgi line 20.

I made sure that all the scripts has 755 permissions.

I am executing the scripts from cgi-bin folder.

Could anyone please let me know what went wrong.

Regards,
J

The examples say use strict. Excel::Writer::XLSX - search.cpan.org

You might want to add a debug print of $report_name to ensure it is valid as a path.