2

I have the following Excel sheet with the following cells:

    'A'   'B'   'C' 
1    S     2     T
2    E     F     D
3    K     L     M
4    N     D     F
5    P     E     M 

I would like to delete the first j lines from column 'B', where j is a list length.

list=['2','F','L']   

Any idea how this can be accomplished?

I would prefer to use openpyxl for this action.

Best regards,

Dan

2
  • Show your effort. Commented Jan 17, 2018 at 16:12
  • @MegaIng I was close enough from the first time, but I have tried a stupid method, so I posted the question here. Thanks anyway. Commented Jan 17, 2018 at 18:22

1 Answer 1

4

Found out the solution. Maybe someone else would need it:

import openpyxl
wb=openpyxl.load_workbook('/media/sf_vboxshared/x.xlsx')
sheet=wb.get_sheet_by_name('Sheet1')
list=['2','F','L']
j=len(list)
for j in range(1,j+1):
        sheet.cell(row=j, column=2).value=None

And to check the output can be used:

for rowOfCellObjects in sheet['A1':'D6']:
        for cellObj in rowOfCellObjects:
                print(cellObj.coordinate, cellObj.value)

Best regards, Dan

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.