我对编程/python 比较陌生,所以如果能得到任何帮助,我将不胜感激。我想通过 COM 使用 Excel 将 excel 文件保存为特定格式。这是代码:
import win32com.client as win32
def excel():
app = 'Excel'
x1 = win32.gencache.EnsureDispatch('%s.Application' % app)
ss = x1.Workbooks.Add()
sh = ss.ActiveSheet
x1.Visible = True
sh.Cells(1,1).Value = 'test write'
ss.SaveAs(Filename="temp.xls", FileFormat=56)
x1.Application.Quit()
if __name__=='__main__':
excel()
我的问题是,如果我没有明确知道它的代码,我该如何指定 FileFormat?浏览文档后,我找到了关于 FileFormat 对象的参考资料。我对如何访问XlFileFormat 对象并以我可以找到它的枚举值的方式导入它一无所知。
谢谢!