Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

variable says one thing, but does another!

Status
Not open for further replies.

Jiggerman

Programmer
Sep 5, 2002
62
GB
I'm sorry to have to write in with such a seemingly simple problem, but like a tree I'm stumped!

This script takes in an excel file location, splits it up by the slashes, puts the file name backto gether with the slashes the other way round, and doubles the amount of slashes, ergo C:/hello/Perl/People.xls becomes C:\\hello\\Perl\\People.xls, This is so the Win32 OLE module will read the file. I have managed to convert the file location like said, and can print out an example of it, but when I try and use the variable to open the excel file, it's looking for the file with a \ Missing, hmmm Curious.

--CODE--
@tempsplit = split(/\//, $excelFile);
$nameConcat = "";
$flag = 1;
foreach $name (@tempsplit){
if($flag == 1){
$nameConcat = "$nameConcat"."$name";
$flag = 0;
}else{
$nameConcat = "$nameConcat"."\\\\"."$name";
}
}
print "Excel name : $nameConcat\n";
$Book = $Excel->Workbooks->Open("$nameConcat"); # open Excel file
# my $Book = $Excel->Workbooks->Open("R:\\engbodan\\asmit386\\perlStuff\\AimsAutomation\\teachMe\\Tester.xls"); # open Excel file
$Sheet = $Book->Worksheets(1); # select worksheet number 1
$array = $Sheet->Range("A8:B9")->{'Value'}; # get the contents
$Book->Close;
----

--Results--
Excel name : R:\\engbodan\\asmit386\\perlStuff\\AimsAutomation\\Tester\\Excel\\t
est.xls
Tk::Error: OLE exception from "Microsoft Excel":

'R:\\engbodan\\asmit386\\perlStuff\\AimsAutomation\\Tester\\Excel\test.xls'
could not be found. Check the spelling of the file name, and verify that the
file location is correct.
----

Thanks for any help.
 
Jiggerman,

Try this line
Code:
$file=~ s /\//\\\\/g;

HTH
Paul
 
I'm afraid that it still comes up with the same error. The Test line that prints out the new address line comes up with the correct address, but when the script tryes to open it, it doesn't open the line it was given, eg, the script has been told to open R:\\engbodan\\asmit386\\perlStuff\\AimsAutomation\\Tester\\Excel\\test.xls, but instead tries to open 'R:\\engbodan\\asmit386\\perlStuff\\AimsAutomation\\Tester\\Excel\test.xls'. The differance between the two being a missing "\" before the test.xls file.

If I hard code the excel file address into the code it works fine though?!

hmm

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top