使用XLWINGS打开工作簿而不使其可见 [英] Open a Workbook with XLWINGS without making it visible

查看:655
本文介绍了使用XLWINGS打开工作簿而不使其可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始使用XLWings(一点也不喜欢Excel,但这是我必须要做的事情).事实是,我无法找到使Python在不显示它的情况下打开工作簿的方法.

I am starting to use XLWings (not that I like Excel, at all, but it is something I HAVE TO do). The thing is that I cannot find the way to make Python open a Workbook without showing it.

似乎旧XLWings 0.6.4中工作簿的构造函数是xlwings.Workbook,其中一个参数是标志"app_visible"(请参见

It seems the constructor for Workbooks in the old XLWings 0.6.4 was xlwings.Workbook, and one of the arguments was a flag 'app_visible' (see http://docs.xlwings.org/en/v0.6.4/api.html).

但是,在新的v0.9.2工作簿中,工作簿已被Book取代,并且Book没有任何此类标记( http://docs.xlwings.org/en/stable/api.html ). App对象确实具有它,我认为那是要走的路.所以我编码:

However, in the new v0.9.2 Workbook has been replaced by Book, and Book does not have any such flag (http://docs.xlwings.org/en/stable/api.html). The App object does have it, and I thought that was the way to go. So I coded:

import xlwings as xw

app = xw.App(visible=False)
filename = os.path.join(PATH_EXCEL_SAMPLES, r"rangosConDatos_sample01.xls")
book = xw.Book(filename)
# Do stuff with the info in the book
book.close()  # Ya puedo cerrar el libro.
app.kill()

但是,遗憾的是,何时

book = xw.Book(filename)

执行后,应用的可见"属性突然变为True,并显示了该书.我不知道这是所需功能还是意外行为.无论如何,有什么想法我应该怎么做?

is executed the 'visible' attribute of app suddenly becomes True, and the book is shown. I do not know if this is a desired feature or an unexpected behaviour. Anyway, any ideas how should I do it?

推荐答案

这是我的工作代码片段:

Here is my working code fragment:

    import xlwings

    excel_app = xlwings.App(visible=False)
    excel_book = excel_app.books.open('PATH_TO_YOUR_XLSX_FILE')
    excel_book.save()
    excel_book.close()
    excel_app.quit()

这篇关于使用XLWINGS打开工作簿而不使其可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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