I have an excel:
JavaScript
x
7
1
A B C D
2
1 long short suggested_long suggested_short
3
2 -2.11 5.11 #N/A
4
3 -4.11 3.66 #REF! #N/A
5
4 93.44 7.55 0 0
6
5 1256.4 966.5 563.5 #REF!
7
So, long is in cell(A1), 5.11 is in cell(B2); I want to clear all the values in suggested_long and suggested_short but need to keep the column name rows as I need to insert data after cleaning all the values. Then the result should be:
JavaScript
1
7
1
A B C D
2
1 long short
3
2 -2.11 5.11
4
3 -4.11 3.66
5
4 93.44 7.55
6
5 1256.4 966.5
7
I know openpyxl can do like:
JavaScript
1
4
1
for row in ws['C1:D5']:
2
for cell in row:
3
cell.value = None
4
to delete the value in the cell, but I have uncertain number of cell values in suggested_long and suggested_short. I assume others may have the same problem, so I post it here, many thanks
Advertisement
Answer
Try this:
JavaScript
1
4
1
for row in ws['C2:D'+str(len(ws['D']))]:
2
for cell in row:
3
cell.value = None
4