Using an XLRD module and Python to determine the font style of a cell (italic or not)

I am trying to analyze data in an Excel spreadsheet using XLRD to determine which cell values ​​are in italics. This information will be used to set a flag as to whether the value is an estimated or reported value. The following is sample data:

owner_name          year    Jan     Feb     Mar     Apr     May     Jun     Jul     Aug     Sep     Oct     Nov     Dec
Alachua, city of    1978    17.4    15.7    16.7    18.3    18.9    18.9    19.2    17.4    19.5    19.8    17.1    16.4
Archer, city of     1978    5.6      3.6     4.3     4.5     4.7     4.8     5.3     5.3     5.4     5.6     3.9     2.8

I did not use XLRD to any extent other than playing with some of the basic functions to understand how to extract data from a spreadsheet. Now I need to add this extra bit of functionality to identify the highlighted cell values.

Thanks in advance for your help ...

EDIT: XLRD provided me with the functionality I needed; thanks to John Machin for the answer. Here is the code:

import xlrd

book = xlrd.open_workbook('fl_data.xls',formatting_info=True)
sh = book.sheet_by_index(0)

for row in range(0,sh.nrows):
    font = book.font_list
    cell_val = sh.cell_value(row,1)
    cell_xf = book.xf_list[sh.cell_xf_index(row,1)]

    print cell_val,font[cell_xf.font_index].italic
+5
2

xlrd ( , pyexcel):

google python-excel. , , 99% .

0

, "timmorgan", . , excel, , . excel, get_range, . .

#--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
0

All Articles