Using XLRD module and Python to determine cell font style (italics or not)

前端 未结 2 1169
野性不改
野性不改 2021-01-12 10:12

I\'m trying to parse data in an excel spreadsheet using XLRD to determine which cell values are italicized. This information will be used to set a flag as to whether the val

2条回答
  •  萌比男神i
    2021-01-12 10:20

    My solution here was based on a class written by 'timmorgan' which can be found here. The class requires that the excel document you wish to act upon be open. You then create the excel document object and then call the 'get_range' method which returns a range object. This range object can then be used to get at font properties of the cell specified.

    #--Requires excel document to be open
    import pyexcel
    book = pyexcel.ExcelDocument(visible=True) #--keeps excel open
    cell = 'r171'
    r = book.get_range(cell)
    val = book.get_value(cell)
    
    print val, r.font.italic, r.font.name
    

提交回复
热议问题