'Save excel workbook in Python

I am new in Python and I need to open all Excels in a folder (one by one), wait some time for SAS addin to load new data, then save it and close it. I tried to use some libraries, but I cant obtain the expected result.

Using subprocess:

import os
import subprocess

path = "C:\\Users\\...\\Desktop\\TEST_EXCEL"

for file in os.listdir(path):
    filename = os.path.join(path, file)
    if filename.endswith(".xlsx"):    
       proc = subprocess.Popen([filename], shell=True)
       time.sleep(60)
       subprocess.call(['taskkill', '/F', '/T', '/PID', str(proc.pid)])

Popen function open the Excel, then I wait 60 seconds, so the addin can load the data, and then close it. The problem is I cannot save the new data that was added.

I also tried with other libraries like openpyxl, but I was not able to open the Excel. I load Excel but it seems that it is not downloading new data if you dont open it.

Example with openpyxl:

import os
import openpyxl

path = "C:\\Users\\...\\Desktop\\TEST_EXCEL"

for file in os.listdir(path):
    filename = os.path.join(path, file)
    if filename.endswith(".xlsx"):    
       wb = openpyxl.load_workbook(filename)
       time.sleep(60)
       wb.save(filename)

Thanks for your help.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source