I have an excel template that I would like to open, and then write to on a monthly basis.
Is there a way to write write the dataframe to a specific row? Here is where I'm stuck, I can get it to write into that new file but it over writes the other rows with blanks? Is there a way to do this?
df = pd.read_sql_query(sql, cnxn, params=[invoice])
df.rename(columns={'COMPANYNAME': 'Company/Name', 'ADDRESS': 'Address', 'CITY': 'City', 'STATE': 'State', 'SERVICEDESCRIPTION': 'Service Description', 'INVOICE#': 'Invoice #', 'SUBTOTAL': 'Sub-Total', 'TAXAMT': 'Tax Amt', 'TOTAL': 'Total', 'ORDER': 'Order No.'}, inplace=True)
file_name = 'BPS_Invoice_' + invoice + '.xlsx'
copyfile("BPS_template.xlsx", file_name)
# print(df.dtypes)
#
writer = pd.ExcelWriter(file_name)
df.to_excel(writer, sheet_name='sheet1', index=False, startrow=14)
writer.sheets['sheet1'].set_column('A:A', 30)
writer.sheets['sheet1'].set_column('B:B', 35)
writer.sheets['sheet1'].set_column('C:C', 15)
writer.sheets['sheet1'].set_column('D:D', 15)
writer.sheets['sheet1'].set_column('E:E', 15)
writer.sheets['sheet1'].set_column('F:F', 15)
writer.sheets['sheet1'].set_column('G:G', 15)
writer.save()