Opening an Excel application from Python

I use 'xlwt' to write to Excel files as part of my Python project. I also need to open the Excel spreadsheet for display, and also close it. I found a function:

import webbrowser webbrowser.open('C:/Users/300231823/Desktop/GUI/simplenew4.xls') 

It seems to open the .xls file. How to close a file?

I am completely new to programming and I started using Python 3 weeks ago.

+6
source share
1 answer
 from win32com.client import Dispatch xl = Dispatch("Excel.Application") xl.Visible = True # otherwise excel is hidden # newest excel does not accept forward slash in path wb = xl.Workbooks.Open(r'C:\Users\300231823\Desktop\GUI\simplenew4.xls') wb.Close() xl.Quit() 

The win32com module is part of pywin32 .

+10
source

Source: https://habr.com/ru/post/890076/


All Articles