简体   繁体   English

如何从 ZA7F5F35426B627411FCA430Z 中的 Windows 异步打开 Excel 工作簿中的 Excel 与 openpy1

[英]How to asynchronously open an Excel Workbook in Excel in Windows from Python with openpyxl

My need is to create a new Excel Workbook in Python (3.6), insert data and leave this Workbook OPEN in Excel for the user to work with.我需要在 Python (3.6) 中创建一个新的 Excel 工作簿,插入数据并在 Excel 中将此工作簿保持打开状态,供用户使用。

I'm using openpyxl, but unfortunately, there's no workbook method to open the Workbook in Excel.我正在使用openpyxl,但不幸的是,在Excel中没有打开工作簿的工作簿方法。

I tried saving the Workbook in Windows' TEMP folder and then shell out to open this file using os.system(tempExcelFile) and it does open the file, but my Python program is waiting for this process to terminate and even then hangs.我尝试将工作簿保存在 Windows 的 TEMP 文件夹中,然后 shell 使用os.system(tempExcelFile)打开此文件,它确实打开了该文件,但我的 Python 程序正在等待此进程终止,甚至挂起。

What solutions can you suggest to accomplish this simple task: create an Excel Workbook, open it in Excel on the Windows machine, and have the Python program continue without waiting for any signal coming back from Excel. What solutions can you suggest to accomplish this simple task: create an Excel Workbook, open it in Excel on the Windows machine, and have the Python program continue without waiting for any signal coming back from Excel.

Thanks!谢谢!

Here's the solution I found working eventually:这是我最终发现的解决方案:

excelFile = tempfile.gettempdir() + "\\" + "Employees.xlsx"
wkb.save(excelFile)
subprocess.Popen(excelFile, shell=True)

I'm storing the Excel file in Windows Temp folder, and opening it there.我将 Excel 文件存储在 Windows Temp 文件夹中,并在那里打开它。 Excel remains open for the user with the file to work with, and the Python program completes asynchronously (the UI remains for the user to call for other operations on the data). Excel 对用户保持打开状态,用户可以使用该文件使用该文件,并且 Python 程序异步完成(UI 仍然供用户调用以对数据进行其他操作)。

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

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