使用XLWINGS打开工作簿而不会显示它

问题描述 投票:18回答:1

我开始使用XLWings(并不是我完全喜欢Excel,但这是我必须要做的事情)。关键是我无法找到使Python打开工作簿而不显示它的方法。

似乎在旧的XLWings 0.6.4中工作簿的构造函数是xlwings.Workbook,其中一个参数是标志'app_visible'(请参见http://docs.xlwings.org/en/v0.6.4/api.html)。

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

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)

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

python excel visibility xlwings
1个回答
0
投票

例如,您可以尝试'打开'

with open ("write.csv", "a", newline='') as file:  
    fields=['score', 'name']                       
    writer=csv.DictWriter(file, fieldnames=fields)
    writer.writerow({'score' : score, 'name' : username})

with open ("write.csv", "r") as file:
    sortlist=[]
    reader=csv.reader(file)
    for i in reader:
        sortlist.append(i)
© www.soinside.com 2019 - 2024. All rights reserved.