2

I need to output some text into excel format with openpyxl. I want some of my texts as subscripts and others as superscripts.

I have checked the documentation for openpyxl but can't find anything about that. I did find the openpyxl.cell.text module here.

This code runs fine

wb = OP.Workbook()
ws = wb.active

c = OP.cell.text.InlineFont(vertAlign='subscript')
ws.cell(row=1, column=1, value='ab')

wb.save('example.xlsx')

But I don't know how I can use c to make text appear as subscript.

chidimo
  • 2,684
  • 3
  • 32
  • 47

1 Answers1

0

Make sure you import the right modules.

This one works:

from openpyxl import Workbook
from openpyxl.styles import PatternFill, Border, Side, Alignment, Protection, Font
wb = Workbook()
ws = wb.active
a = ws['A1']
ws['A1'] =  'appel'
a.font = Font(bold=True, vertAlign='subscript')
wb.save('test.xlsx')