Python Forum

Full Version: insert row and write to xlsx in python
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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