1

I am trying to read an excel workbook and running into a windows path error. I have tried os and pathlib. The codes shows different variations.

def main():

    infilename = ('c:\Testing\Python\EET_Report.xlxs')
    tried infilename = pathlib.Path('c:/Testing/Python/EET_Report.xlxs')
    tried infilename = pathlib.PureWindowsPath('c:/Testing/Python/EET_Report.xlxs')


    # open file
    inwb = xlrd.open_workbook(infilename)

The error I am getting when running the program:

No such file or directory: 'c:\\Testing\\Python\\EET_Report.xlxs'
martineau
  • 119,623
  • 25
  • 170
  • 301
edbeck
  • 61
  • 5
  • try ```infilename = (r'c:\Testing\Python\EET_Report.xlxs')``` – lc74 Jun 21 '19 at 19:26
  • 1
    As @jjramsey said, you might have a mistake on the file extension. Workbook file should have `.xlsx` extension https://learn.microsoft.com/en-us/deployoffice/compat/office-file-format-reference – Andra Jun 21 '19 at 19:33

2 Answers2

3

The extension on that filename should probably be "xlsx", not "xlxs".

jjramsey
  • 1,131
  • 7
  • 17
-1

You might meed to unescape some characters using backslash

def main():

infilename = ('c:\/Testing\/Python\/EET_Report.xlxs')
tried infilename = pathlib.Path('c:\/Testing\/Python\/EET_Report.xlxs')
tried infilename = pathlib.PureWindowsPath('c:\/Testing\/Python\/EET_Report.xlxs')


# open file
inwb = xlrd.open_workbook(infilename)
Andra
  • 1,282
  • 2
  • 11
  • 34
  • While this code snippet may be the solution, including an explanation really helps to improve the quality of your post. Remember that you are answering the question for readers in the future, and those people might not know the reasons for your code suggestion. – Eric Leschinski Jun 22 '19 at 02:34