我正在尝试打开现有的 Excel 2013 文件,添加数据,然后保存它(相同名称),然后关闭它,然后关闭 Excel。该代码将打开文件,选择正确的工作表并写入数据,但是当我尝试保存它时,出现属性错误。我错过了图书馆或其他什么吗?这是代码:
import win32com.client as win32
def Inventory_Status():
excel = win32.gencache.EnsureDispatch('Excel.Application') # opens Excel
wb = excel.Workbooks.Open(r'C:/pytest/Test.xlsx') # opens "Test" file
wb.Sheets(2).Select() # select 2nd worksheet "Aisle_2"
excel.Visible = True
excel.Range("A1").Select()
excel.ActiveCell.Value = "1234" # Fill in test data #
wb.save()
wb.Close()
excel.Quit()
Inventory_Status()
raise AttributeError("'%s' object has no attribute '%s'" % (repr(self), attr))
AttributeError: '<win32com.gen_py.Microsoft Excel 15.0 Object Library._Workbook instance at 0x5901424>' object has no attribute 'save'
大写's'
on the save()
method.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)