如何使用xlwings保存工作簿? [英] How do I save a workbook using xlwings?

查看:835
本文介绍了如何使用xlwings保存工作簿?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个excel工作表,一些按钮和一些宏.我使用xlwings使其工作.有没有办法通过xlwings保存工作簿?我想在执行操作后提取特定的工作表,但是保存的工作表是在操作之前提取的工作表,而没有生成的数据.

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

推荐答案

Workbook.save()现在已作为v0.3.2的一部分实现:请参见

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

这篇关于如何使用xlwings保存工作簿?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆