问题遇到的现象和发生背景
问题相关代码,请勿粘贴截图
import xlwings as xw
import time
app=xw.App(visible=False)
wb=app.books.open('data.xlsx')
wb=app.books.add()
ws=wb.sheets.add('t')
ws=wb.sheets[0]
ws.range('a1').value='hzx'
wb.close()
time.sleep(3)
wb.save(r'/Users/houzhixian/Desktop/phzx21.xlsx')
# app.quit()
运行结果及报错内容
EventError Traceback (most recent call last)
~/opt/anaconda3/lib/python3.9/site-packages/aeosa/appscript/reference.py in call(self, *args, **kargs)
481 try:
--> 482 return self.AS_appdata.target().event(self._code, params, atts, codecs=self.AS_appdata).send(timeout, sendflags)
483 except aem.EventError as e:
~/opt/anaconda3/lib/python3.9/site-packages/aeosa/aem/aemsend.py in send(self, timeout, flags)
91 errormsg = _defaultcodecs.unpack(errormsg)
---> 92 raise EventError(errornum, errormsg, eventresult)
93 if kae.keyAEResult in eventresult: # application has returned a value
EventError: Command failed: The object you are trying to access does not exist (-1728)
The above exception was the direct cause of the following exception:
CommandError Traceback (most recent call last)
/var/folders/tv/dt3jjn2s4j33tvvvld49v6lh0000gn/T/ipykernel_1238/961393794.py in
10 wb.close()
11 time.sleep(3)
---> 12 wb.save(r'/Users/houzhixian/Desktop/phzx21.xlsx')
13 # app.quit()
~/opt/anaconda3/lib/python3.9/site-packages/xlwings/main.py in save(self, path)
872 path = utils.fspath(path)
873 with self.app.properties(display_alerts=False):
--> 874 self.impl.save(path)
875
876 @property
~/opt/anaconda3/lib/python3.9/site-packages/xlwings/_xlmac.py in save(self, path)
293
294 def save(self, path):
--> 295 saved_path = self.xl.properties().get(kw.path)
296 source_ext = os.path.splitext(self.name)[1] if saved_path else None
297 target_ext = os.path.splitext(path)[1] if path else '.xlsx'
~/opt/anaconda3/lib/python3.9/site-packages/aeosa/appscript/reference.py in call(self, *args, **kargs)
662
663 def call(self, *args, **kargs):
--> 664 return self.get(*args, **kargs)
665
666 # Following methods will be called by its-based generic references when resolving themselves into real references; end-users and other clients shouldn't call them directly.
~/opt/anaconda3/lib/python3.9/site-packages/aeosa/appscript/reference.py in call(self, *args, **kargs)
516 return
517 raise CommandError(self, (args, kargs), e, self.AS_appdata) from e
--> 518 raise CommandError(self, (args, kargs), e, self.AS_appdata) from e
519
520 def AS_formatcommand(self, args):
CommandError: Command failed:
OSERROR: -1728
MESSAGE: The object you are trying to access does not exist
COMMAND: app('/Applications/Microsoft Excel.app', newinstance=(0, 782527)).workbooks['工作簿3'].properties.get()