简体   繁体   English

如何使用Python带Xlwings Excel文件前景

[英]How to bring xlwings excel file foreground using Python

I am using xlwings to modify an excel file in Python 3.6. 我正在使用xlwings在Python 3.6中修改Excel文件。 xlwings opens the excel instance and runs my python script, as a results the Excel file would go to the background of my pycharm window. xlwings打开excel实例并运行我的python脚本,结果Excel文件将转到我的pycharm窗口的背景。

Is there any straightforward way to bring the excel file to the foreground at the end of the program? 有什么简单的方法可以在程序结束时将excel文件置于前台?

My code is similar to this: 我的代码与此类似:

import xlwings as xw

wb = xw.Book('Excel.xlsx')
sheet_ranges = wb.sheets['Sheet1']

def updatingExcel(input):
    value = 'Hello World'
    sheet_ranges.range('H' + str(i + 3)).value = value
return value

    print(updatingExcel(anyinput)

I understand that if I run the.py file outside pycharm this issue most probably won't occur as the screen terminates itself. 我了解,如果我在pycharm外部运行.py文件,则该问题很可能不会在屏幕终止时发生。 However I would appreciate your input. 不过,我感谢您的投入。

Use app.activate with steal_focus=True , see: http://docs.xlwings.org/en/stable/api.html#xlwings.App.activate app.activatesteal_focus=True ,请参阅: http : steal_focus=True

for example: 例如:

import xlwings as xw
wb = xw.Book()
wb.app.activate(steal_focus=True)

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

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