Recently to mark a large set of corpus, in order to facilitate labeling, the trigger word in the text of the position of red, in order to identify. The text of the same cell in the table that writes different Rich text is as follows:
Import Xlsxwriterworkbook = Xlsxwriter. Workbook (' tttt.xlsx ') worksheet = Workbook.add_worksheet () worksheet.set_column (' a:a ', ') #第一列宽度Format = Workbook.add _format ({' Font_name ': ' Kaiti ', ' font_size ': +, ' bold ': True}) #设置一个默认的格式RedFormat = Workbook.add_format ({' Font_name ': ' Kaiti ', ' font_size ': +, ' bold ': True, ' color ': ' red '} #在默认格式上加上颜色BlueFormat = Workbook.add_format ({' Font_name ': ' Kaiti ', ' font_size ': +, ' bold ': True, ' color ': ' Blue '} #在默认格式上加上颜色worksheet. write_rich_string (' A1 ', Format, ' This is ', Redformat, ' Red ', Blueformat, ' Blue ') #写入三种格式workbook. Close ()
#摘抄于: HTTPS://SEGMENTFAULT.COM/U/CHQBGE
The final result is
Python xlsxwriter writing different rich text in the same cell