I have written a Python code (below) that reads a self-updating, real-time Excel (.xlsm) and converts it into a CSV every 1 second. But the code doesn't seem to overwrite the previous excel with the newer one, which it should do. Am I missing something?
My ultimate goal is to sync the Excel with the CSV so that all relative changes in Excel reflects in the CSV in real-time. Any help/suggestions on it would be highly appreciated.
import pandas as pd
import time
from timeloop import Timeloop
from datetime import timedelta
tl = Timeloop()
excel_file_path='I:/Live Stats/Corona.xlsm'
csv_file_path ='N:/My Drive/Corona_Live.csv'
primaryexcelsheet='Stats'
read_Excelfile =pd.read_excel(excel_file_path,sheet_name=primaryexcelsheet)
@tl.job(interval=timedelta(seconds=1))
def sample_job_every_1s():
def format_csv(excel_file_path,csv_file_path):
read_Excelfile =pd.read_excel(excel_file_path,sheet_name=primaryexcelsheet)
read_Excelfile.to_csv(csv_file_path,index=None,header=True)
format_csv(excel_file_path,csv_file_path)
if __name__ == "__main__":
tl.start(block=True)
question from:
https://stackoverflow.com/questions/65623620/connect-excel-worksheet-to-csv-using-python-pandas 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…