Appliquer des effets de exposant et d indice sur les polices

Travailler avec l’effet d’exposant et d’indice

Appliquez l’effet exposant à l’aide de la propriété setSuperscript de l’objet Font. Pour appliquer l’indice, utilisez la méthode setSubscript de l’objet Font.

Les exemples de code suivants montrent comment appliquer l’exposant et l’indice au texte.

Application de l’exposant

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(ApplyingSuperscript.class);
// Instantiating a Workbook object
Workbook workbook = new Workbook();
// Accessing the added worksheet in the Excel file
Worksheet worksheet = workbook.getWorksheets().get(0);
Cells cells = worksheet.getCells();
// Adding some value to the "A1" cell
Cell cell = cells.get("A1");
cell.setValue("Hello");
// Setting the font name to "Times New Roman"
Style style = cell.getStyle();
Font font = style.getFont();
font.setSuperscript(true);
cell.setStyle(style);
// Saving the modified Excel file in default format
workbook.save(dataDir + "Superscript.xls");

Application de l’indice

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(ApplyingSubscript.class);
// Instantiating a Workbook object
Workbook workbook = new Workbook();
// Accessing the added worksheet in the Excel file
Worksheet worksheet = workbook.getWorksheets().get(0);
Cells cells = worksheet.getCells();
// Adding some value to the "A1" cell
Cell cell = cells.get("A1");
cell.setValue("Hello");
// Setting the font name to "Times New Roman"
Style style = cell.getStyle();
Font font = style.getFont();
font.setSubscript(true);
cell.setStyle(style);
// Saving the modified Excel file in default format
workbook.save(dataDir + "Subscript.xls");