How do I save a workbook using xlwings?

江枫思渺然 提交于 2019-12-07 01:40:27

问题


I have an excel worksheet, some buttons and some macros. I use xlwings to make it work. Is there a way to save the workbook through xlwings ? I want to extract a specific sheet after doing an operation, but the saved sheet is the extracted sheet before the operation without the generated data.

My code for extracting the sheet I need is the following:

Set objFSO = CreateObject("Scripting.FileSystemObject")

src_file = objFSO.GetAbsolutePathName(Wscript.Arguments.Item(0))
sheet_name = Wscript.Arguments.Item(1)
dir_name = Wscript.Arguments.Item(2)
file_name = Wscript.Arguments.Item(3)

Dim objExcel
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = False

Dim objWorkbook
Set objWorkbook = objExcel.Workbooks(src_file)

objWorkbook.Sheets(sheet_name).Copy
objExcel.DisplayAlerts = False

objExcel.ActiveWorkbook.SaveAs dir_name + file_name + ".xlsx", 51
objExcel.ActiveWorkbook.SaveAs dir_name + file_name + ".csv", 6

objWorkbook.Close False
objExcel.Quit

回答1:


Workbook.save() has now been implemented as part of v0.3.2: see the docs.



来源:https://stackoverflow.com/questions/27281914/how-do-i-save-a-workbook-using-xlwings

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!