openpyxl overwrites all data instead of update the excel sheet
<p>I'm trying to read a string from a text file and write it into an excel sheet without overwriting. I found somewhere that to update excel sheets, openpyxl in used. But my script just overwrites the entire sheet. I want other data to be the same.</p>
<p>python script:</p>
<pre><code>from openpyxl import Workbook     
file_name=&quot;D:\\a.txt&quot;    
content={}    
with open(file_name) as f:
    for line in f:
        (key,value)=line.split(&quot;:&quot;)
        content[key]=value

wb=Workbook()
ws=wb.active
    r = 2
for item in content:
    ws.cell(row=r, column=3).value = item
    ws.cell(row=r, column=4).value = content[item]
    r += 1
    
wb.save(&quot;D:\\Reports.xlsx&quot;)
</code></pre>
<p>Excel sheet before script:</p>
<p><a href="https://i.stack.imgur.com/KL3AF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KL3AF.png" alt="enter image description here" /></a></p>
<p>Excel sheet after script :</p>
<p><a href="https://i.stack.imgur.com/IJVuv.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/IJVuv.png" alt="enter image description here" /></a></p>
<p>How do I write the data to excel with overwriting other things ? Help.</p>