Python Forum
openpyxl incorrect delete rows
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
openpyxl incorrect delete rows
#1
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
Reply
#2
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)
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
(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]
Reply
#4
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)
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#5
(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.
Reply
#6
(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???
VladislavM likes this post
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#7
(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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Code is returning the incorrect values. syntax error 007sonic 6 1,137 Jun-19-2023, 03:35 AM
Last Post: 007sonic
  Pymysql delete specific rows in tableview stsxbel 2 1,049 Aug-18-2022, 09:50 AM
Last Post: ibreeden
  error 1102 (42000) incorrect database name 's' Anldra12 4 1,651 Jun-08-2022, 09:00 AM
Last Post: Anldra12
  Trying to delete rows above a specific datetime value cubangt 19 11,011 May-09-2022, 08:57 PM
Last Post: deanhystad
  The code I have written removes the desired number of rows, but wrong rows Jdesi1983 0 1,602 Dec-08-2021, 04:42 AM
Last Post: Jdesi1983
  Incorrect Type Error milkycow 4 2,828 Jun-25-2021, 06:04 AM
Last Post: milkycow
  Pandas DataFrame combine rows by column value, where Date Rows are NULL rhat398 0 2,082 May-04-2021, 10:51 PM
Last Post: rhat398
  Indexing [::-1] to Reverse ALL 2D Array Rows, ALL 3D, 4D Array Columns & Rows Python Jeremy7 8 6,963 Mar-02-2021, 01:54 AM
Last Post: Jeremy7
  Why is 0.1 * 0.2 arithmetically incorrect? Pedroski55 2 2,180 Nov-25-2020, 12:01 AM
Last Post: snippsat
  my openpyxl use is too slow, am I reading rows incorrectly? Clunk_Head 2 8,212 Apr-30-2020, 10:29 PM
Last Post: deac33

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020