I'm attempting to create a Python script that subscripts or superscripts specific characters in an Excel cell's content. I was using OpenPyxl, but I've read that it only permits changes that affect the entire cell, so if that's the case, I'm willing to switch to another package.
I need each cell's two characters that follow the "T" to be a subscript for reference. So, format the string "T12+0.10" or "(T12+17.00" so that the "12" is a subscript, as seen in the illustration below.
Here's what I have so far:
style = XFStyle()
style.font = fnt
style.borders = borders
substyle = fnt.ESCAPEMENT_SUBSCRIPT
superstyle = fnt.ESCAPEMENT_SUPERSCRIPT
def compare(contents):
s = ""
for i in contents:
nextchar=contents[i+1].value
if i.value.contains ("T"):
j = i + 1, substyle
s += str(s + j)
else:
s += str(i)
wb = op.load_workbook("file_name.xlsx")
ws = wb["Sheet3"]
for row in ws.iter_rows("C{}:C{}".format(ws.min_row, ws.max_row)):
for cell in row:
contents = cell.value
compare(contents)