I am using xlrd, xlwt, and xlutils on the Windows Vista OS with Python 2.7. I have a set of DNA sequences in an excel worksheet that are 100 characters long, with each sequence in a single cell. I am trying to highlight characters at specific positions within each of these sequences in excel (bold them or change color), but have not found a way to format individual characters within a cell. Applying a style applies it to the entire cell to my knowledge. Therefore I am trying to break the sequences down into individual components where some parts of the sequence will be modified with a style while others won't, and to then collate these back together into a single string in a single cell.
Code:
rb = open_workbook('Mybook', formatting_info=True) rs = rb.sheet_by_index(0) wb = copy(rb) ws = wb.get_sheet(0) minus35style = xlwt.easyxf('font: bold 1') # style I'd like for just one character for b in range(0, 368, 1): rscellin = rs.cell(b,9) f = rscellin.value tominus35 = str(f[0:34]) minus35 = str(f[35:36]) ws.write(b, 14, tominus35) ws.write(b, 14, minus35, minus35style) wb.save('Mybook')
My problem is that adding a style changes the whole cell, and I want just certain characters to be modified. Additionally, subsequent writing to the same cell overwrites what was there previously. Is there a way to modify individual characters in a single cell, or to add differently formatted text to an existing cell that already has text in it?
Please let me know if you require additional information that I've overlooked. I appreciate your time in advance.
Brett