-1

I am just trying to write in the excel sheet 'Hello'.

Getting the following error:

IOError: [Errno 2] No such file or directory: u'C:Python27ExcelBook.xls'

Open Excel            C:\Python27\ExcelBook.xls
Put String To Cell    Sheet1  0    0     Hello
Save Excel            C:\Python27\ExcelBook.xls

This is the correct path but not sure where the 'u' coming from...

erikrunia
  • 2,371
  • 1
  • 15
  • 22

3 Answers3

2

Take a close look at the error:

No such file or directory: u'C:Python27ExcelBook.xls'

Notice that the error says C:Python27..., not C:\Python27\...

Robot uses the backslash as an escape character, so when you do C:\Python27\ExcelBook.xls, all the keyword sees is C:Python27ExcelBook.xls.

Use forward slashes, or use double-backslashes.

Open Excel C:\\Python27\\ExcelBook.xls 

-or-

Open Excel C:/Python27/ExcelBook.xls

This is covered in the user guide, in a section titled Escaping

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
  • Thank you Bryan for replying. I think they did not work for me. When I try C:\\Python27\\ExcelBook.xls the out put is: IOError: [Errno 2] No such file or directory: u'C:\\Python27\\ExcelBook.xls' When I try C:/Python27/ExcelBook.xls, the output is: IOError: [Errno 2] No such file or directory: u'C:/Python27/ExcelBook.xls' I think the latter solution looks better but the 'u' is puzzling to me. Not sure if I am doing anything else wrong. – Jahid Ullah Jul 14 '18 at 02:01
1

The u'some_text' is to indicate it is a unicode string [What's the u prefix in a Python string?. Maybe try opening with something like:

filename = str(whatEverYourStringNameWas)
# open...
# or:
filename = bytes(whateverYourStringNameWas, 'ASCII')
# open...
bowzerfood
  • 29
  • 4
  • Thank you for your reply. I am sorry I am new to RIDE robot framework and not sure how I can implement above solution. Will you please elaborate. Thanks! – Jahid Ullah Jul 14 '18 at 02:09
1

Yes it works double backslash, in case not working please change the file excess by right clicking on the file in advance section.