Delete row il excel file with Openpyxl

1,918 views
Skip to first unread message

manel....@ensi-uma.tn

unread,
Dec 7, 2017, 6:55:02 AM12/7/17
to openpyxl-users
Hello

I did not find the command to delete a row having a specific cell value in excel with openPyxl

Can anyone help me 
Thanks in advance

Alper Paksoy

unread,
Dec 7, 2017, 12:02:04 PM12/7/17
to openpyxl-users
I don't think there is a command which allows you to directly delete a row or column from a sheet in openpyxl. As for checking on the cell values, you have to loop through cells individually in your sheet(s) and check the cell values individually. 

You can then copy the rows which do not have a cell with that value to another location in the same sheet or to a new sheet in the same file or to another sheet in another or new excel file. Hope this helps.

Alper

P.S. I recommend Chapter 12 of the book "Automate the Boring Stuff with Python" if you want a nice tutorial on openpyxl. The web version of all of the book is available publicly for free at https://automatetheboringstuff.com. Charlie Clark (one of the authors of openpyxl) has some reservations on some of the example code shared in that chapter but I still think the chapter is a good tutorial on openpyxl (and the book overall provides a very good introduction to Python in my view).

Manel Mrabet

unread,
Dec 7, 2017, 3:04:32 PM12/7/17
to openpyx...@googlegroups.com
Thank you for your attention, It is a good idea to copy the rows that have not this value in a new file because there is no command to delete a row with a specific value

Garanti sans virus. www.avg.com

--
You received this message because you are subscribed to a topic in the Google Groups "openpyxl-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/openpyxl-users/ABclapKW5QE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to openpyxl-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

eshter...@gmail.com

unread,
May 10, 2018, 3:20:57 AM5/10/18
to openpyxl-users
sheet.delete_rows(row_index,num)

在 2017年12月7日星期四 UTC+8下午7:55:02,Manel Mrabet写道:

hamad....@gmail.com

unread,
Feb 23, 2020, 1:54:26 AM2/23/20
to openpyxl-users
This command will delete the contain of the row, leaving behind an empty cell
Reply all
Reply to author
Forward
0 new messages