I'm trying to extract from an Excel file the content of a cell (essentially text) and the format of the text. The Excel I am dealing with looks like the screenshot below :
Texts in cells may be bold, italic or stroke and I need to extract the text and the format into a python string. For example, if a cell contains :
- line 1
- line 2
- line 3
I would like to obtain a string Python that's look like :
- line 1 /n- **line 2**/n- *line 3**
in order to get the text and the format information.
I've tried to find a solution using openpyxl, but it seems that it is only possible to apply and not extract format cell. Library xlrd seems not fitted for xlsx. I am currently trying with pyexcel library.
Do you have any idea ? Thanks.
You can import Font from openpyxl and check if a cell is written in bold by using cell.font.bold
, it gives a True or False.
cell=sheet[A2]
bold_status=cell.font.bold
italic_status=cell.font.italic
More info on the fonts in openpyxl: http://openpyxl.readthedocs.io/en/2.5/api/openpyxl.styles.fonts.html
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.