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

Hi team i having following error pls help me

Can't call method "worksheet" on an undefined value at /var/www/cgi-bin/Daily_Transaction_Reports_folder/Scripts_Folder/RCAB_Trans_Report.pl line 60.


This is my script i define worksheet and i m giving correct file name and path


Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2. use IO::Handle;
  3. use DBI;
  4. use Spreadsheet::SimpleExcel;
  5. use Spreadsheet::WriteExcel;
  6. use Spreadsheet::ParseExcel;
  7. use Spreadsheet::ParseExcel::SaveParser;
  8. use Spreadsheet::ParseExcel::Format;
  9. use Spreadsheet::WriteExcel::Format;
  10. use Time::Local qw( timelocal_nocheck );
  11. use POSIX qw(strftime);
  12. use Time::Local qw( timegm_nocheck );
  13. #use warnings;
  14.  
  15. # Parameters
  16.  
  17. my $driver = "mysql";
  18. my $database = "insalldatadb";
  19. my $host = "172.24.16.62";
  20. my $port = "3323";
  21. my $dsn = "DBI:$driver:database=$database;host=$host;port=$port";
  22. my $userid = "solreaduser";
  23. my $password = '^rfvbnhy7*';
  24. #my $date=strftime '%Y%m%d',localtime();
  25. my $date=strftime "%Y%m%d",localtime(time() - 24*60*60);
  26.  
  27. my $sqlFile = "/var/www/cgi-bin/Daily_Transaction_Reports_folder/Scripts_Folder/RCAB_Report.sql";
  28.  
  29.  
  30. # Connect Database
  31.  
  32. my $dbh = DBI->connect($dsn, $userid, $password ) or die $DBI::errstr;
  33.  
  34. # Execute SQL
  35.  
  36. open (SQL,"$sqlFile");
  37.  
  38. my $sql = $dbh->prepare(<SQL>);
  39.  
  40. my $out = $sql->execute()
  41. or die "Unable to execute sql: $sql->errstr";
  42.  
  43.  
  44.  
  45. #Month_Name
  46. my @month_name = qw(January Febuary March April May June July August September October November December);
  47. print "$month_name\n";
  48. my ( $day, $month, $year ) = (localtime)[ 3, 4, 5 ];
  49. $year = $year + 1900;
  50. my $mnth = "$month_name[$month]_$year";
  51. print "$mnth\n";
  52.  
  53. # Open existing spread-sheet with SaveParser
  54.  
  55. my $read_excel   = Spreadsheet::ParseExcel::SaveParser->new();
  56. my $excel_data = $read_excel->Parse("/var/www/cgi-bin/Daily_Transaction_Reports_folder/Ouput_Folder/RCAB_Daily_Transactions_$mnth.xls");
  57.  
  58. # Get the first worksheet
  59.  
  60. my $worksheet = $excel_data->worksheet("$mnth");
  61.  
  62. #Add format
  63.  
  64.  
  65.  
  66.  
  67. #my $format = $excel_data->AddFormat('Verdana');
  68.  
  69. # Get Last date of month
  70.  
  71. my @time_data;
  72.  
  73. @time_data = localtime();
  74.  
  75. $time_data[4]++;   # Next month.
  76. $time_data[3] = 0; # Last day of previous month.
  77.  
  78. @time_data = localtime(timelocal_nocheck(@time_data));
  79.  
  80. my $last_day = $time_data[3];
  81.  
  82. my $var1 = ("%d\n",$last_day);
  83.  
  84.  
  85. open(STDIN_0, '/var/www/cgi-bin/Daily_Transaction_Reports_folder/Scripts_Folder/RCAB_Column.txt');
  86. $col_index= <STDIN_0>;
  87. $var=++$col_index;
  88.  
  89.  
  90. if ( $var > $var1 )
  91. {
  92. my $start = 1;
  93. open(STDIN_1, '>', '/var/www/cgi-bin/Daily_Transaction_Reports_folder/Scripts_Folder/RCAB_Column.txt');
  94. print STDIN_1 "$start\n";
  95. }
  96. else
  97. {
  98. open(STDIN_1, '>', '/var/www/cgi-bin/Daily_Transaction_Reports_folder/Scripts_Folder/RCAB_Column.txt');
  99. print STDIN_1 "$var\n";
  100. }
  101.  
  102. my $row = 1;
  103. my $col = 1;
  104. my $i = 0;
  105.  
  106. open(STDIN_0, '/var/www/cgi-bin/Daily_Transaction_Reports_folder/Scripts_Folder/Excel_Column.txt');
  107. $index= <STDIN_0>;
  108.  
  109. #Add dates
  110. my @time_data;
  111.  
  112. @time_data = localtime();
  113.  
  114. $time_data[4]++;   # Next month.
  115. $time_data[3] = 0; # Last day of previous month.
  116.  
  117. @time_data = localtime(timelocal_nocheck(@time_data));
  118.  
  119. my $last_day = $time_data[3];
  120. my $var = ("%d\n",$last_day);
  121.  
  122. my ($y, $m, $d) = (localtime)[5,4,3];
  123. $y += 1900;
  124. $m += 1;
  125.  
  126. my $ds = 1;
  127. my $de = (gmtime(timegm_nocheck(0,0,0, (1-1), ($m+1)-1, $y)))[3];
  128.  
  129. $date2 = sprintf('%02d%02d%04d', $m,$ds,$y);
  130.  
  131. my @m = (3,4,7,8,11,12,15,16,19,20,21,24,25,26,29,30,33,34,37,40,43,44,45,46,47,48);
  132. #my $i = 0;
  133.  
  134. do {
  135. while (my @row = $sql->fetchrow_array()) {
  136.  
  137.   $worksheet->AddCell($m[$i], $col_index, $row[i]);
  138.   $i++;
  139.  }
  140. };
  141. my $workbook1 = $excel_data->SaveAs("/var/www/cgi-bin/Daily_Transaction_Reports_folder/Ouput_Folder/RCAB_Daily_Transactions_$mnth.xls");
  142.  
  143.  
  144. #format
  145. my $format2 = $workbook1->add_format();
  146. $format2->set_align('center');
  147. $format2->set_font('Verdana');
  148. my $worksheet = $workbook1->sheets("$index");
  149.  
  150. #Formula
  151. $worksheet->write(B4, "=SUM(C4:AG4)", $format2);
  152. $worksheet->write(B5, "=SUM(C5:AG5)", $format2);
  153. $worksheet->write(B8, "=SUM(C8:AG8)", $format2);
  154. $worksheet->write(B9, "=SUM(C9:AG9)", $format2);
  155. $worksheet->write(B12, "=SUM(C12:AG12)", $format2);
  156. $worksheet->write(B13, "=SUM(C13:AG13)", $format2);
  157. $worksheet->write(B16, "=SUM(C16:AG16)", $format2);
  158. $worksheet->write(B17, "=SUM(C17:AG17)", $format2);
  159. $worksheet->write(B20, "=SUM(C20:AG20)", $format2);
  160. $worksheet->write(B21, "=SUM(C21:AG21)", $format2);
  161. $worksheet->write(B22, "=SUM(C22:AG22)", $format2);
  162. $worksheet->write(B25, "=SUM(C25:AG25)", $format2);
  163. $worksheet->write(B26, "=SUM(C26:AG26)", $format2);
  164. $worksheet->write(B27, "=SUM(C27:AG27)", $format2);
  165. $worksheet->write(B30, "=SUM(C30:AG30)", $format2);
  166. $worksheet->write(B31, "=SUM(C31:AG31)", $format2);
  167. $worksheet->write(B34, "=SUM(C34:AG34)", $format2);
  168. $worksheet->write(B35, "=SUM(C35:AG35)", $format2);
  169. $worksheet->write(B38, "=SUM(C38:AG38)", $format2);
  170. $worksheet->write(B41, "=SUM(C41:AG41)", $format2);
  171. $worksheet->write(B44, "=SUM(C44:AG44)", $format2);
  172. $worksheet->write(B45, "=SUM(C45:AG45)", $format2);
  173. $worksheet->write(B46, "=SUM(C46:AG46)", $format2);
  174. $worksheet->write(B47, "=SUM(C47:AG47)", $format2);
  175. $worksheet->write(B48, "=SUM(C48:AG48)", $format2);
  176. $worksheet->write(B49, "=SUM(C49:AG49)", $format2);
  177.  
  178. my $format3 = $workbook1->add_format();
  179. $format3->set_bold();
  180. $format3->set_align('center');
  181. $format3->set_font('Verdana');
  182. $format3->set_bg_color('Gray');
  183. $format3->set_pattern();
  184.  
  185. my $format14 = $workbook1->add_format(num_format => '@');
  186.  
  187. my $inc = 1;
  188. my $col = 2;
  189. my $test = 0;
  190.  
  191.  
  192. while( $inc <= $var ){
  193. $worksheet->write_string(0,$col, $date2, $format3, $format14);
  194. $date3 = $date2 + 10000;
  195. $date2 = $test.$date3;
  196. $inc = $inc + 1;
  197. $col++;
  198. }
  199.  
  200.  
  201. $workbook1->close();
May 5 '16 #1
2 3499
RonB
589 Expert Mod 512MB
First, you left out the 2 most important modules (pragmas) which should be in every perl script.
Expand|Select|Wrap|Line Numbers
  1. use strict;
  2. use warnings;
  3.  
If you add those pragmas, you'll find that your code has a bunch of compilation errors. Ignoring those errors is never the right thing to do.

c:\test>perl -Mwarnings -Mstrict -c pandairaj94.pl
"my" variable @time_data masks earlier declaration in same scope at pandairaj94.pl line 110.
"my" variable $last_day masks earlier declaration in same scope at pandairaj94.pl line 119.
"my" variable $worksheet masks earlier declaration in same scope at pandairaj94.pl line 148.
"my" variable $col masks earlier declaration in same scope at pandairaj94.pl line 188.
Argument "i" isn't numeric in array element at pandairaj94.pl line 137.
Global symbol "$month_name" requires explicit package name at pandairaj94.pl line 47.
Global symbol "$col_index" requires explicit package name at pandairaj94.pl line 86.
Global symbol "$var" requires explicit package name at pandairaj94.pl line 87.
Global symbol "$col_index" requires explicit package name at pandairaj94.pl line 87.
Global symbol "$var" requires explicit package name at pandairaj94.pl line 90.
Global symbol "$var" requires explicit package name at pandairaj94.pl line 99.
Global symbol "$index" requires explicit package name at pandairaj94.pl line 107.
Global symbol "$date2" requires explicit package name at pandairaj94.pl line 129.
Global symbol "$col_index" requires explicit package name at pandairaj94.pl line 137.
Global symbol "$index" requires explicit package name at pandairaj94.pl line 148.
Global symbol "$date2" requires explicit package name at pandairaj94.pl line 193.
Global symbol "$date3" requires explicit package name at pandairaj94.pl line 194.
Global symbol "$date2" requires explicit package name at pandairaj94.pl line 194.
Global symbol "$date2" requires explicit package name at pandairaj94.pl line 195.
Global symbol "$date3" requires explicit package name at pandairaj94.pl line 195.
Bareword "i" not allowed while "strict subs" in use at pandairaj94.pl line 137.
Bareword "B4" not allowed while "strict subs" in use at pandairaj94.pl line 151.
Bareword "B5" not allowed while "strict subs" in use at pandairaj94.pl line 152.
Bareword "B8" not allowed while "strict subs" in use at pandairaj94.pl line 153.
Bareword "B9" not allowed while "strict subs" in use at pandairaj94.pl line 154.
Bareword "B12" not allowed while "strict subs" in use at pandairaj94.pl line 155.
Bareword "B13" not allowed while "strict subs" in use at pandairaj94.pl line 156.
Bareword "B16" not allowed while "strict subs" in use at pandairaj94.pl line 157.
Bareword "B17" not allowed while "strict subs" in use at pandairaj94.pl line 158.
Bareword "B20" not allowed while "strict subs" in use at pandairaj94.pl line 159.
Bareword "B21" not allowed while "strict subs" in use at pandairaj94.pl line 160.
Bareword "B22" not allowed while "strict subs" in use at pandairaj94.pl line 161.
Bareword "B25" not allowed while "strict subs" in use at pandairaj94.pl line 162.
Bareword "B26" not allowed while "strict subs" in use at pandairaj94.pl line 163.
Bareword "B27" not allowed while "strict subs" in use at pandairaj94.pl line 164.
Bareword "B30" not allowed while "strict subs" in use at pandairaj94.pl line 165.
Bareword "B31" not allowed while "strict subs" in use at pandairaj94.pl line 166.
Bareword "B34" not allowed while "strict subs" in use at pandairaj94.pl line 167.
Bareword "B35" not allowed while "strict subs" in use at pandairaj94.pl line 168.
Bareword "B38" not allowed while "strict subs" in use at pandairaj94.pl line 169.
Bareword "B41" not allowed while "strict subs" in use at pandairaj94.pl line 170.
Bareword "B44" not allowed while "strict subs" in use at pandairaj94.pl line 171.
Bareword "B45" not allowed while "strict subs" in use at pandairaj94.pl line 172.
Bareword "B46" not allowed while "strict subs" in use at pandairaj94.pl line 173.
Bareword "B47" not allowed while "strict subs" in use at pandairaj94.pl line 174.
Bareword "B48" not allowed while "strict subs" in use at pandairaj94.pl line 175.
Bareword "B49" not allowed while "strict subs" in use at pandairaj94.pl line 176.
pandairaj94.pl had compilation errors.
Now, regarding your error message. It would appear that line 56
Expand|Select|Wrap|Line Numbers
  1. my $excel_data = $read_excel->Parse("/var/www/cgi-bin/Daily_Transaction_Reports_folder/Ouput_Folder/RCAB_Daily_Transactions_$mnth.xls");
failed which left $excel_data undefined when it was used in line 60.

Try adding some error handling to line 56. But before you do that, you should add the pragmas and fix those other errors.
May 6 '16 #2
RonB
589 Expert Mod 512MB
Besides the errors I've already pointed out, there are a number of other things you're doing which are poor coding practices thus reducing the quality of your code.
May 6 '16 #3

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

Similar topics

1
by: timVerizon | last post by:
Hoping someone can help here.. Our application (C#.Net) was receiving IBM.Data.DB2.DB2Exceptions ERROR SQL0904N Unsuccessful execution caused by an unavailable resource. Reason code: '', type...
1
by: chanmm | last post by:
I hit the problem in my WinXP can someone help me: The Web server reported the following error when attempting to create or open the Web project located at the following URL:...
1
by: Greg Burns | last post by:
--------------------------- Microsoft Development Environment --------------------------- The Web server reported the following error when attempting to create or open the Web project located at...
2
by: Error when creating new asp.net applicat | last post by:
Hi, I'm getting this error when I create a asp.net application. The Web server reported the following error when attempting to create or open the Web projects located at the following URL:...
10
by: Shawn | last post by:
JIT Debugging failed with the following error: Access is denied. JIT Debugging was initiated by the following account 'PLISKEN\ASPNET' I get this messag in a dialog window when I try to open an...
2
by: mike_li | last post by:
On Window 2000 Professional Server DB2 UDB Level: DB2 code release "SQL07029" with level identifie "030A0105" and informational tokens "DB2 v7.1.0.98", "n040510" and "WR21337". In the...
2
by: harish | last post by:
Hello all, I am trying to use C# assembly /dll (which has public methods and events), ... trying to use it through a VB6 client.. I get the error, JIT Debugging failed with the following...
0
by: Shailesh Patel | last post by:
Hi, I get the following error. Retrieving the COM class factory for component with CLSID {F84433FF-2369-4427-B6FB-3CBA67EDA7EB} failed due to the following error: 80040154 ASP.NET(VB.NET)...
3
by: jkbalaji | last post by:
Hi, while running the command "make all" for English morphological analyser, i get the following error.I am using ubuntu 9.10. cc -O -DUNIX -DBSD -g -I/home/English/src/java/morph-1.5/hash...
1
by: Dilshad | last post by:
java.sql.SQLException: Syntax error (missing operator) in query expression having this error while trying to delete record from database as follows plz help me with this. try { ...
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: 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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.