Alexander Starbuck
Alexander Starbuck

Reputation: 1159

Connecting to existing workbook throws error in xlwings

When I try to connect to an existing workbook and verify that the connection works, like so:

import xlwings as xw

wb = xw.Workbook('/users/edchigliak/sites/xlwings/htz/google/sem_google_realizacija_2016.xlsm')

print(wb.sheet(1).name)

terminal on Mac OSX Yosemite throws this error:

OSERROR: -1728 MESSAGE: The object you are trying to access does not exist
COMMAND: app(u'/Applications/MicrosoftExcel.app').workbooks['sem_google_realizacija_2016.xlsm'].name.get()

Workbook does get opened, it prompts for a permission to enable macros and data connections, so all is well there. It seems to me as if I am trying to call a .name() method (or property?) on MicrosoftExcel.app instead of from xlwings library?

What I ultimately wish to do (to go through the whole process):

  1. connect to this existing .xlsm
  2. read 'Sheet14.RangeF:F' and 'Sheet14.RangeI:I' into a python dict
  3. verify that this has been successful

Please advise how I can go about this.

Upvotes: 0

Views: 1988

Answers (1)

Felix Zumstein
Felix Zumstein

Reputation: 7070

First make sure you've got the path right, e.g. try to run open /users/edchigliak/sites/xlwings/htz/google/sem_google_realizacija_2016.xlsm in your Terminal to see if it opens correctly.

Second, you've got the syntax wrong for the sheet. It should be like this:

 import xlwings as xw
 wb = xw.Workbook(...)
 print(xw.Sheet(1).name)

Note that it automatically refers to the last instantiated Workbook. If you want to explicitly specify the workbook, you currently need to do it like this:

xw.Sheet(1, wkb=wb).name

But this syntax might be revised in the nearer future.

Upvotes: 1

Related Questions