Python Forum

Full Version: openpyxl incorrect delete rows
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
When I delete lines through openpyxl, they are not deleted correctly. In some places they even stay. Need to delete rows completely, as excel does. Thank you.

import openpyxl

this_book = openpyxl.open( "example.xlsx" )
this_book.active = 1

def result_i():
    return 10

i = result_i()

if i < 255:
    this_book.active.delete_rows(i, 255-i)

this_book.save("result.xlsx")
this_book.close()
[Image: aVyPZ.png]

Example:
https://drive.google.com/file/d/1KINvDVn...sp=sharing
Not sure what the problem is (i.e. what you consider problem). It works as expected - it's visible also from your [poor] screenshot. it removes line 10-254 and in the result line 10 is the former line 255. However it does not change the formulas in columns H:W (as expected)
(Jul-18-2021, 03:20 PM)buran Wrote: [ -> ]Not sure what the problem is (i.e. what you consider problem). It works as expected - it's visible also from your [poor] screenshot. it removes line 10-254 and in the result line 10 is the former line 255. However it does not change the formulas in columns H:W (as expected)

[Image: ezgif-6-4cc4f2e3355f.gif]
Please, explain in writing exactly what the problem is.
As I said
(Jul-18-2021, 03:20 PM)buran Wrote: [ -> ]it removes line 10-254 and in the result line 10 is the former line 255. However it does not change the formulas in columns H:W (as expected)
(Jul-18-2021, 08:23 PM)buran Wrote: [ -> ]Please, explain in writing exactly what the problem is.
As I said
(Jul-18-2021, 03:20 PM)buran Wrote: [ -> ]it removes line 10-254 and in the result line 10 is the former line 255. However it does not change the formulas in columns H:W (as expected)

The cell A2 doesnt make smaller, despite I'm using rows removal.
(Jul-18-2021, 08:36 PM)VladislavM Wrote: [ -> ]The cell A2 doesnt make smaller, despite I'm using rows removal.
But you are deleting rows 10-254, why would that affect A2 or any of the rows 1-9???
(Jul-19-2021, 05:19 AM)buran Wrote: [ -> ]
(Jul-18-2021, 08:36 PM)VladislavM Wrote: [ -> ]The cell A2 doesnt make smaller, despite I'm using rows removal.
But you are deleting rows 10-254, why would that affect A2 or any of the rows 1-9???

Because Microsof Office detele merged cell. I understand my wrong, thank you.