Python Forum
Writing to existing excel sheet - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Writing to existing excel sheet (/thread-30212.html)



Writing to existing excel sheet - jksvend - Oct-12-2020

Hi all,

Trying to insert a value into an existing spreadsheet.

I get an error in this line (worksheet = writer.sheets['Sheet1'])

Hope some on is able to help. Thanks

import pandas as pd
File2 =r'C:\template.xlsx'

Total_refund = 100

writer = pd.ExcelWriter(File2, engine='xlsxwriter')
workbook = writer.book
worksheet = writer.sheets['Sheet1']
worksheet.write('D15', Total_refund)
worksheet.write('G15', Total_refund)
writer.save()