Temp
SELECT
DATEPART(YEAR, transaction_date) AS Year,
SUM(amount) AS YTD_Sales
FROM
sales
WHERE
transaction_date >= DATEADD(MONTH, -10, DATEFROMPARTS(YEAR(GETDATE()), 1, 1))
AND transaction_date <= GETDATE()
GROUP BY
DATEPART(YEAR, transaction_date)
import os
import xlwings as xw
from openpyxl import load_workbook
from datetime import date
def refresh_excel_file(file_path):
# Open the Excel file with xlwings
wb = xw.Book(file_path)
# Refresh all connections in the workbook (e.g., data connections, queries, etc.)
wb.api.RefreshAll()
# Generate the filename with today's date
file_name, file_ext = os.path.splitext(os.path.basename(file_path))
today_date = date.today().strftime("%Y-%m-%d")
new_file_name = f"{file_name}_{today_date}{file_ext}"
# Save the workbook with today's date appended to the filename
new_file_path = os.path.join(os.path.dirname(file_path), new_file_name)
wb.save(new_file_path)
# Close the workbook
wb.close()
if __name__ == "__main__":
# Replace 'your_excel_file.xlsx' with the path to your actual Excel file
excel_file_path = "your_excel_file.xlsx"
refresh_excel_file(excel_file_path)