I have made a button to write the last week of data from a dataset to an excel file. It works great except each time I press it it overwrites the last time I pressed it in the excel file. I would like a button that creates a new file or a new sheet in the file each time I export the data. How would I do this? Here is my code below:
params = {"StartDate":system.date.now(),"EndDate":system.date.addHours(system.date.now(), 7)}
results = system.db.runNamedQuery("Downtime/FEXW/WestExitDTTrueOEEExcel", params)
spreadsheet = system.dataset.toExcel(True, [results])
filePath = "C:\Users\pjolesbr\OneDrive - Clarios\Projects\Downtime Project\OEE MTTR MTBF.xlsx"
system.file.writeFile(filePath, spreadsheet)