Python Forum
insert row and write to xlsx in python - 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: insert row and write to xlsx in python (/thread-32713.html)



insert row and write to xlsx in python - scttfnch - Feb-28-2021

I had assumed inserting a row and writing to an xlsx file in python would be fairly simple, though i am struggling to actualize the results I had intended.

the variable values I am trying to write into the sheet are printing fine, so it appears just to be a matter of my capacity to successfully use openpyxl.

I have tried running the code with the workbook open and closed, but neither of the attempts seem to be printing to the single active sheet in the workbook.


gdx_wkbk = openpyxl.load_workbook("GDX_chain.xlsx")
    gdx_sht = gdx_wkbk.active
    gdx_sht.insert_rows(2)
    gdx_sht["A2"] = datetime.today().strftime('%m-%d-%Y')
    gdx_sht["B2"] = oi_call_sum
    gdx_sht["C2"] = oi_put_sum
    gdx_sht["D2"] = vol_call_sum
    gdx_sht["E2"] = vol_put_sum
    gdx_wkbk.save('GDX_chain.xlsx')
Shocked