Deleting Records From An Excel Based On The Format Of The Column
Hope everyone's having a great day! I am trying to read data from an excel but before that i want to remove records that are struckthrough(strikethrough :-string format just like b
Solution 1:
This can also be done with openpyxl.
from openpyxl import load_workbook
wb = load_workbook("strikethrough.xlsx")
ws = wb.active # wb.sheetnames[0] will do, toofor row in ws:
for cell in row:
value = cell.value # Note, empty cells have a value of Noneif cell.font.strike:
value = ""print(value)
#print(cell.font) # See more attributes
wb.close()
With this as my spreadsheet:
I get this output:
HeaderA
HeaderB
Row2 ColA
Row3 ColA
Row3 ColB
NoneNone
Above cell is empty
None
Solution 2:
- open the workbook passing the parameter formatting_info=True.
- Get the XF object of the cells and get the Font object.
- You will find your value in the attribute The struck_out
workbook = xlrd.open_workbook(filename, formatting_info=True)
sh = workbook.sheet_by_name(sheet)
xf = workbook.xf_list[sh.cell_xf_index(row, col)]
font = workbook.font_list[xf.font_index]
if font.struck_out:
print(row, col)
Post a Comment for "Deleting Records From An Excel Based On The Format Of The Column"