使用最新版本运行 xlwings 0.26.1(Anaconda 3.83 的最新版本)或 0.10.0(出于兼容性原因使用)时,Office 365 Excel
在运行时移动工作表后出现错误app.quit()
:
import xlwings as xw
import pythoncom
pythoncom.CoInitialize()
app = xw.apps.add()
app.display_alerts = False
app.screen_updating = False
wbSource = app.books.open('pathSourceTemp')
wsSource = wbSource.sheets['sourceSheet']
wbDestination = app.books.open('pathDestinationTemp')
wsDestination = None
#Grabs first sheet in destination
wsDestination = wbDestination.sheets[0]
#Copy sheet "before" destination sheet (which should be 1 sheet after the destination sheet)
wsSource.api.Copy(Before=wsDestination.api)
wbDestination.save()
#Close workbooks and app
wbDestination.close()
wbSource.close()
app.screen_updating = True
app.quit()
最后一行导致 Excel 抛出一个错误,我必须单击该错误才能继续该过程。