3

I want to read in many Excel documents and I would like to receive at least one important bit of information on the format. However, I am afraid that there is no tool for it, so my hope is on you!

Each excel file that I am reading in contains a few cells that of which the content is strikethrough. For those who don't know the word (I didn't know it either), strikethrough means that there is a horizontal line through the content.

I have figured out that I will need to read in my documents with xlrd to be able to identify the fonts. However, I have been going over a list of possibilities and none of them contains a check on strikethrough.

Student NL
  • 303
  • 2
  • 13

2 Answers2

4

You have to open the workbook with formatting_info kwarg as True. Then, get the XF object of the cells and get the Font object. The struck_out attribute is what you're looking for. An example:

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)
Vatsal Juneja
  • 339
  • 1
  • 5
  • 19
1
from openpyxl import load_workbook
book = load_workbook('xyz.xlsx')
sheet = book.get_sheet_names()[0] #This will consider **Sheet1** of our excel file
ws = book.get_sheet_by_name(sheet)
for row in ws.iter_rows():
    for cell in row:
        if cell.font.strike:
            print(cell.value)
akank9
  • 11
  • 3