0

I am building a programme to automate a process in Excel using xlwings.

The files I have to access include .xlsx, .xlsb and .xlsm formats

I have the following command:

wb = xw.Book(r"some_directory\file1.xlsx")

which runs fine.

But when I run any of the next two commands:

wb = xw.Book(r"some_directory\file2.xlsb")

I get the following error:

Input In [10], in <cell line: 1>() ----> 1 wb = xw.Book(r"some_directory\file2.xlsb")

File ~\Anaconda3\lib\site-packages\xlwings\main.py:682, in Book.init(self, fullname, update_links, read_only, format, password, write_res_password, ignore_read_only_recommended, origin, delimiter, editable, notify, converter, add_to_mru, local, corrupt_load, impl) 680 if not app: 681 app = App(add_book=False) --> 682 impl = app.books.open(fullname, update_links, read_only, format, password, write_res_password, 683 ignore_read_only_recommended, origin, delimiter, editable, notify, converter, 684 add_to_mru, local, corrupt_load).impl 685 elif len(candidates) > 1: 686 raise Exception("Workbook '%s' is open in more than one Excel instance." % fullname)

File ~\Anaconda3\lib\site-packages\xlwings\main.py:4278, in Books.open(self, fullname, update_links, read_only, format, password, write_res_password, ignore_read_only_recommended, origin, delimiter, editable, notify, converter, add_to_mru, local, corrupt_load) 4276 try: 4277 impl = self.impl(name) -> 4278 if not os.path.samefile(impl.fullname, fullname): 4279 raise ValueError( 4280 "Cannot open two workbooks named '%s', even if they are saved in different locations." % name 4281
) 4282 except KeyError:

File ~\Anaconda3\lib\genericpath.py:100, in samefile(f1, f2) 94 def samefile(f1, f2): 95 """Test whether two pathnames reference the same actual file or directory 96 97 This is determined by the device number and i-node number and 98 raises an exception if an os.stat() call on either pathname fails. 99 """ --> 100 s1 = os.stat(f1) 101 s2 = os.stat(f2) 102 return samestat(s1, s2)

OSError: [WinError 123] The filename, directory name, or volume label syntax is incorrect: 'some_directory\file2.xlsb'

How do I access file2.xlsb using xlwings?

Tipo33
  • 181
  • 13
  • @BigBen, the commands works only with the .xlsx file. When I tried using the .xlsb file or even the .xlsm file, I get this error – Tipo33 Oct 20 '22 at 15:49
  • 1
    I just edited my question and included the full stack trace – Tipo33 Oct 20 '22 at 15:56
  • Is this workbook saved in a OneDrive location? – BigBen Oct 20 '22 at 15:56
  • Yes it is, along with the other files I have mentioned. – Tipo33 Oct 20 '22 at 16:03
  • I read an `.xlsb` just fine from a local directory, and suspect that something with your OneDrive is causing this error. – BigBen Oct 20 '22 at 16:04
  • The error suggests that you are trying to open a workbook that has the same name as a workbook that is already open: `"Cannot open two workbooks named '%s', even if they are saved in different locations."` – Rawson Jan 13 '23 at 12:11
  • @Rawson I was only opening one file then but still faced this issue. – Tipo33 Feb 09 '23 at 21:26

1 Answers1

0

The problem may have been to do with the way that OneDrive was set up in the environment I was working in. I managed to open the file in a server that was outside this environment.

Tipo33
  • 181
  • 13