我有一个我想打开的excel模板,然后每月写一次。
有没有办法将数据写入特定行? 这是我被困住的地方,我可以让它写入那个新文件,但它用空白写入其他行?有没有办法做到这一点?
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()