Update an Excel sheet in real time using Python

前端 未结 4 1089
野性不改
野性不改 2021-02-15 08:35

Is there a way to update a spreadsheet in real time while it is open in Excel? I have a workbook called Example.xlsx which is open in Excel and I have the following python code

4条回答
  •  北荒
    北荒 (楼主)
    2021-02-15 08:47

    I have actually figured this out and its quite simple using xlwings. The following code opens an existing Excel file called Example.xlsx and updates it in real time, in this case puts in the value 45 in cell B2 instantly soon as you run the script.

    import xlwings as xw
    
    wb = xw.Book('Example.xlsx')
    sht1 = wb.sheets['Sheet']
    sht1.range('B2').value = 45
    

提交回复
热议问题