Appliquer des effets de exposant et d indice sur les polices
Contents
[
Hide
]
Aspose.Cells pour Python via .NET fournit la fonctionnalité d’appliquer des effets d’exposant (texte au-dessus de la ligne de base) et d’indice (texte en dessous de la ligne de base).
Travailler avec l’effet d’exposant et d’indice
Appliquez l’effet d’exposant en définissant la propriété is_superscript de l’objet Style.font sur true. Pour appliquer un indice, définissez la propriété is_subscript de l’objet Style.font sur true.
Les exemples de code suivants montrent comment appliquer un exposant et un indice au texte.
Code Python pour appliquer l’effet exposant au texte
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Code Python pour appliquer l’effet indice au texte
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |