简体   繁体   English

如何使用 xlwings 保存工作簿?

[英]How do I save a workbook using xlwings?

I have an excel worksheet, some buttons and some macros.我有一个 Excel 工作表、一些按钮和一些宏。 I use xlwings to make it work.我使用 xlwings 使其工作。 Is there a way to save the workbook through xlwings ?有没有办法通过 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

Workbook.save()现在已作为v0.3.2一部分实现:请参阅文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM