Can not locate object method "AddCell" via package "Spreadsheet::

A

Arindam

"Hi,
I am trying to to learn PERL, I am using it for an Automation Tool,
Selenium RC. My target is to open google. If the operation is
successful, I will open an existing excel sheet and write PASS, if it
fails, It will write Fail. I have installed the required library. The
code is as follows:-

--------------
use strict;

use warnings;

use Time::HiRes qw(sleep);

use Test::WWW::Selenium;

use Test::More "no_plan";

use Test::Exception;

use Spreadsheet::WriteExcel;

use Spreadsheet::parseExcel;

use Spreadsheet::parseExcel::SaveParser;

print "\n\n **Enter You Browser Choice :: ";

my $browser = <STDIN>;

my $row;

my $col;

my $count;

my $sheet;

$row = 0;

$col = 0;

$sheet = 0;

$count = 1;

my $sel = Test::WWW:: Selenium->new( host => "localhost",
port => 4444,
browser => "*$browser",
browser_url => "http://www.google.uk/" );

my $parser = new Spreadsheet::parseExcel;

my $template = $parser->Parse("test_result.xls");

$template->AddCell(0, $row+1, $col, $browser);

if($sel->open_ok("http://www.google.co.uk/")){

$template->AddCell(0, $row+1, $col+1, "Home Page
:http://www.shopzilla.co.uk/"); $template->AddCell(0, $row, $col+2,
"Pass");

}

else{

$template->AddCell(0, $row+1, $col+3, "Fail");
---------------

After running the program, I am getting the following error:-
Can not locate object method "AddCell" via package "Spreadsheet::
ParseExcel ::Workbook"

I would be grateful, if anyone could give me some guidance to
resolve the problem.

Thanking You in Anticipation,
Arindam Pattanayak

===================="
 
Z

Zebee Johnstone

In comp.lang.perl.misc on Sun, 30 May 2010 13:48:33 -0700 (PDT)
Arindam said:
"Hi,
I am trying to to learn PERL, I am using it for an Automation Tool,
Selenium RC. My target is to open google. If the operation is
successful, I will open an existing excel sheet and write PASS, if it
fails, It will write Fail. I have installed the required library. The
code is as follows:-

use Spreadsheet::WriteExcel;
use Spreadsheet::parseExcel;
use Spreadsheet::parseExcel::SaveParser;
my $parser = new Spreadsheet::parseExcel;
my $template = $parser->Parse("test_result.xls");

$template->AddCell(0, $row+1, $col, $browser);


After running the program, I am getting the following error:-
Can not locate object method "AddCell" via package "Spreadsheet::
ParseExcel ::Workbook"

I know nothing about those modules, but it looks to me like one called
"ParseExcel" is reading not writing.

If you want to write, should you be creating an object with WriteExcel
not ParseExcel?

and if you do
perldoc Spreadsheet::parseExcel
is there mention of AddCell? Or is that only in perldoc
Spreadsheet::WriteExcel?


Zebee
 
J

Jim Gibson

Arindam said:
"Hi,
I am trying to to learn PERL, I am using it for an Automation Tool,
Selenium RC. My target is to open google. If the operation is
successful, I will open an existing excel sheet and write PASS, if it
fails, It will write Fail. I have installed the required library. The
code is as follows:-

--------------
use strict;
use warnings;
....

use Spreadsheet::WriteExcel;
use Spreadsheet::parseExcel;
use Spreadsheet::parseExcel::SaveParser;
....

my $parser = new Spreadsheet::parseExcel;

This object should be of class Spreadsheet::parseExcel::SaveParser, as
you will be calling methods of that class below (AddCell), not of
Spreadsheet::parseExcel.
 
J

Justin C

"Hi,
I am trying to to learn PERL, I am using it for an Automation Tool,
Selenium RC. My target is to open google. If the operation is
successful, I will open an existing excel sheet and write PASS, if it
fails, It will write Fail. I have installed the required library. The
code is as follows:-

[snipped a complete mess of irrelevance]

Please post a *minimal* example of the problem - refer to the posting
guidlines which are posted to the group very frequently.

Your problem is that your template object comes from
Spreadsheet::parseExcel, this module doesn't know how to create
anything, only read existing Excel files. You need to take information
obtained from your template and create a new Excel object using those
settings with Spreadsheet::WriteExcel. You then call the AddCell method
with this object.

For better answers to your questions please post according to the
guidelines.

Justin.
 
J

Justin C

Okay, here is the code. Yesterday I was running the following program on Window 7 Professional 64 bit. I thought the OS was the culprit. I got this code from CSPAN website. So, I don't think there could be something wrong with the code. I ran the same code on my home computer with Window XP Professional 32 bit but got the same error.

What I don't understand is I have specified SaveParser so why it wouldn't look for "AddCell" method there? Why it keeps looking for it in ParseExcel?

use strict;
use Spreadsheet::parseExcel;
use Spreadsheet::parseExcel::SaveParser;

my $parser = Spreadsheet::parseExcel->new();
my $workbook1 = $parser->parse('C:\readMe.xls');

if ( !defined $workbook1 ) {
die $parser->error(), ".\n";
}


my $worksheet1 = $workbook1->worksheet('Sheet1');
my $parser2 = Spreadsheet::parseExcel::SaveParser->new();
my $workbook2 = $parser2->parse('C:\writeMe.xls');

I got your code to work by changing the above line to:
my $workbook2 = $parser2->Parse('C:\writeMe.xls');
(note the upper-case 'P' ^ here)

I don't pretend to be an expert, but I've done some investigation and I
find that there are two methods defined: Parse, and parse, but they are
not the same! The one with the upper-case P is in
Spreadsheet::parseExcel::SaveParser, the other is in
Spreadsheet::parseExcel. Even if I strip your code down to it's barest
minimum which still shows the error (which is what you should have done,
and you may have found this for yourself):

#!/usr/bin/perl

use warnings;
use strict;
use Spreadsheet::parseExcel::SaveParser;

my $parser2 = Spreadsheet::parseExcel::SaveParser->new();
my $workbook2 = $parser2->parse('excel/xmas96.xls');

my $worksheet2 = $workbook2->worksheet('Sheet1');

$worksheet2->AddCell(20,0,'380');

__END__

I use modules in a lot of what I code, but when they are like this I
don't really understand what is going on. I mean, is S::pE::SP dependant
on S::pE? Could ...SaveParser be installed without S::pE? If I "use
S::pE::SP" does S::pE automatically get "used" as well? Or does
specifying ...SaveParser work like "use CGI qw/standard/" and only pull
in the methods specified?

I hope the OP gets something useful out of this, because all it's done
is make me more confused.

Justin.
 
P

Peter J. Holzer

I got your code to work by changing the above line to:
my $workbook2 = $parser2->Parse('C:\writeMe.xls');
(note the upper-case 'P' ^ here)

I don't pretend to be an expert, but I've done some investigation and I
find that there are two methods defined: Parse, and parse, but they are
not the same! The one with the upper-case P is in
Spreadsheet::parseExcel::SaveParser, the other is in
Spreadsheet::parseExcel.

They could even both be spelled the same.

$parser is an object of the class 'Spreadsheet::parseExcel', so
$parser->parse() calls Spreadsheet::parseExcel::parse.

$parser2 is an object of the class
'Spreadsheet::parseExcel::SaveParser', so $parser2->Parse() calls
Spreadsheet::parseExcel::SaveParser::parse().

I use modules in a lot of what I code, but when they are like this I
don't really understand what is going on. I mean, is S::pE::SP dependant
on S::pE? Could ...SaveParser be installed without S::pE?

Maybe. It depends on how S::pE::SP is written. The documentation of
S::pE::SP should answer your questions. If it doesn't mention S:pE at
all, then S::pE::SP is probably completely independent of S::pE.
If I "use
S::pE::SP" does S::pE automatically get "used" as well?

No. S::pE::SP may use S::pE, but if it does, any symbols exported by
S::pE are only imported into S::pE::SP, not into your current package.

Note that in object-oriented Perl, symbols are not usually exported:
Instead the full class name is used for class methods like new, and
instance methods are referenced via the object anyway. So if you use
class A and class A uses class B, you can use class B just as if you had
used it yourself.

hp
 
U

Uri Guttman

P> Is that all you had to say? You wrote your last email as if you
P> were so dying to solve my problem but got disappointed when you
P> didn't see the problem code? I think the administrators should ban
P> trolls like you. I am otta here

who are you refering to? there is no quote or attribution. for a
supposed perl trainee you aren't doing a good job listening to what
people tell you.

uri
 
J

Jürgen Exner

PerlTrainee said:
Is that all you had to say?

What did who say? It is a time-honored proven Usenet custom to quote
sufficient context such that any posting makes sense on its own.
You wrote your last email

Email? What does email have to do with Usenet?
as if you were so dying to solve my problem but got disappointed when you didn't see the problem code?

No idea what you are rambling about because you didn't provide any
context.
I think the administrators should ban trolls like you. I am otta here

What adminstrators? CLPM is -like the vast majority of Usenet- a
non-moderated group. What adminstrators are you talking about?

jue
 
J

J. Gleixner

PerlTrainee said:
Okay, here is the code. Yesterday I was running the following program on Window 7 Professional 64 bit. I thought the OS was the culprit. I got this code from CSPAN website. So, I don't think there could be something wrong with the code. I ran the same code on my home computer with Window XP Professional 32 bit but got the same error.

What I don't understand is I have specified SaveParser so why it wouldn't look for "AddCell" method there? Why it keeps looking for it in ParseExcel?

use strict;
use Spreadsheet::parseExcel;
use Spreadsheet::parseExcel::SaveParser;

my $parser = Spreadsheet::parseExcel->new();
my $workbook1 = $parser->parse('C:\readMe.xls');

if ( !defined $workbook1 ) {
die $parser->error(), ".\n";
}


my $worksheet1 = $workbook1->worksheet('Sheet1');
my $parser2 = Spreadsheet::parseExcel::SaveParser->new();
my $workbook2 = $parser2->parse('C:\writeMe.xls');

In addition to all of the other comments, The following:
if (!defined $workbook2) {
die $parser->error(),".\n";
}

will call the error method from the Spreadsheet::parseExcel
class. More than likely, you would want to call error from
the Spreadsheet::parseExcel::SaveParser class.

die $parser2->error;

Also, note the side effect when you add a newline to die's output.
 
J

Jim Gibson

PerlTrainee said:
I have installed the ParseExcel v0.57 module and I read on CSPAN that this
module contains SaveParser. So I don't think I need to install another
package. I am running Perl 5.12. Is it possible that this module does not
support this version of Perl?

The Spreadsheet::parseExcel::SaveParser (SPESP) module depends upon
these modules:

Spreadsheet::parseExcel;
Spreadsheet::parseExcel::SaveParser::Workbook;
Spreadsheet::parseExcel::SaveParser::Worksheet;
Spreadsheet::WriteExcel;

You can see this from the source, which can be displayed using the
command-line

perldoc -m Spreadsheet::parseExcel::SaveParser

or the web page

<http://cpansearch.perl.org/src/JMCNAMARA/Spreadsheet-ParseExcel-0.57/li
b/Spreadsheet/ParseExcel/SaveParser.pm>

It is possible you need to have compatible versions of all five modules
for the modules to work.

Note that SPESP was moribund for many years and has been taken over by
a new maintainer, who has placed the following warning in the source
code:

"Please note that this module is currently (versions 0.50-0.60)
undergoing a major restructuring and rewriting."

Thus, problems can be anticipated.

If you can't wait for these problems to be fixed, and if your
requirements are modest, you may be able to use the
Spreadsheet::parseExcel and SpreadSheet::WriteExcel modules to copy an
existing spreadsheet and updates it contents.
 
J

Justin C

[snip]
I got your code to work by changing the above line to:
my $workbook2 = $parser2->Parse('C:\writeMe.xls');
(note the upper-case 'P' ^ here)

I don't pretend to be an expert, but I've done some investigation and I
find that there are two methods defined: Parse, and parse, but they are
not the same! The one with the upper-case P is in
Spreadsheet::parseExcel::SaveParser, the other is in
Spreadsheet::parseExcel.

They could even both be spelled the same.

$parser is an object of the class 'Spreadsheet::parseExcel', so
$parser->parse() calls Spreadsheet::parseExcel::parse.

$parser2 is an object of the class
'Spreadsheet::parseExcel::SaveParser', so $parser2->Parse() calls
Spreadsheet::parseExcel::SaveParser::parse().

I use modules in a lot of what I code, but when they are like this I
don't really understand what is going on. I mean, is S::pE::SP dependant
on S::pE? Could ...SaveParser be installed without S::pE?

Maybe. It depends on how S::pE::SP is written. The documentation of
S::pE::SP should answer your questions. If it doesn't mention S:pE at
all, then S::pE::SP is probably completely independent of S::pE.
If I "use
S::pE::SP" does S::pE automatically get "used" as well?

No. S::pE::SP may use S::pE, but if it does, any symbols exported by
S::pE are only imported into S::pE::SP, not into your current package.

Note that in object-oriented Perl, symbols are not usually exported:
Instead the full class name is used for class methods like new, and
instance methods are referenced via the object anyway. So if you use
class A and class A uses class B, you can use class B just as if you had
used it yourself.

Thank you for the explanation.

Justin.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,152
Members
46,697
Latest member
AugustNabo

Latest Threads

Top