1

I'm curious if there's a way to insert a new row (that would push all the existing rows down) in an existing openpyxl worksheet? (I'm looking to insert at the first row if it helps)

I looked through all the docs and didn't see anything mentioned.

Greg
  • 45,306
  • 89
  • 231
  • 297

1 Answers1

0

This is currently not directly possible in openpyxl because it would require the reassigning of all cells below the new row.

You can do it yourself by iterating through the relevant rows (starting at the end) and writing a new row with the values of the previous row. Then you create a row of cells where you wan them.

Charlie Clark
  • 18,477
  • 4
  • 49
  • 55
  • No longer true as of [openpyxl 2.5](https://openpyxl.readthedocs.io/en/stable/api/openpyxl.worksheet.worksheet.html). Use `insert_rows(idx, amount=1)` – virtualxtc Jul 16 '18 at 10:45