Apply Superscript and Subscript Effects on Fonts

Working with Superscript and Subscript

Apply the superscript effect by setting the Style.font object’s is_superscript property to true. To apply subscript, set the Style.font object’s is_subscript property to true.

The following code examples show how to apply super and subscript to text.

Python code to Apply Superscript effect on text

from aspose.cells import SaveFormat, Workbook
from os import os, path
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET
# The path to the documents directory.
dataDir = RunExamples.GetDataDir(".")
# Create directory if it is not already present.
IsExists = path.isdir(dataDir)
if notIsExists:
os.makedirs(dataDir)
# Instantiating a Workbook object
workbook = Workbook()
# Adding a new worksheet to the Excel object
workbook.worksheets.add()
# Obtaining the reference of the newly added worksheet by passing its sheet index
worksheet = workbook.worksheets[0]
# Accessing the "A1" cell from the worksheet
cell = worksheet.cells.get("A1")
# Adding some value to the "A1" cell
cell.put_value("Hello")
# Setting the font Superscript
style = cell.get_style()
style.font.is_superscript = True
cell.set_style(style)
# Saving the Excel file
workbook.save(dataDir + "Superscript.out.xls", SaveFormat.AUTO)

Python code to Apply Subscript effect on text

from aspose.cells import SaveFormat, Workbook
from os import os, path
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET
# The path to the documents directory.
dataDir = RunExamples.GetDataDir(".")
# Create directory if it is not already present.
IsExists = path.isdir(dataDir)
if notIsExists:
os.makedirs(dataDir)
# Instantiating a Workbook object
workbook = Workbook()
# Adding a new worksheet to the Excel object
workbook.worksheets.add()
# Obtaining the reference of the newly added worksheet by passing its sheet index
worksheet = workbook.worksheets[0]
# Accessing the "A1" cell from the worksheet
cell = worksheet.cells.get("A1")
# Adding some value to the "A1" cell
cell.put_value("Hello")
# Setting the font Subscript
style = cell.get_style()
style.font.is_subscript = True
cell.set_style(style)
# Saving the Excel file
workbook.save(dataDir + "Subscript.out.xls", SaveFormat.AUTO)