1import pandas as pd
2import xlsxwriter
3import pyodbc
4
5
6conn = pyodbc.connect('Driver={SQL Server}; Server=ServerIP; uid=UID; pwd=Password; Trusted_Connection=No;')
7 with pd.ExcelWriter("Output.xlsx", engine="xlsxwriter", options = {'strings_to_numbers': True, 'strings_to_formulas': False}) as writer:
8 try:
9 df = pd.read_sql("Select * from Orders", conn)
10 df.to_excel(writer, sheet_name = "Sheet1", header = True, index = False)
11 print("File saved successfully!")
12 except:
13 print("There is an error")
14