Home > Code > VB.NET > How to Apply Superscript & Subscript Effects on Fonts in Worksheet

How to Apply Superscript & Subscript Effects on Fonts in Worksheet

by sher azam   on Oct 07, 2015   Category: VB.NET   |  Views: 667    |  Points: 25   |  Gold 


This technical tip show how developers can apply Superscript and Subscript effects on Fonts in Excel Workshet inside Android Apps. Superscript - characters that are raised above font's baseline - and subscript - characters lowered below the baseline - are used for many different reasons. Such as superscript is often used for trademark and copyright signs: Aspose TM and Subscript is probably best known from mathematical formulas and chemical descriptions: Uranium 234. Both are frequently used in mathematical notation. Aspose.Cells provides the functionality to set superscript and subscript effects on text. The code examples below show how to apply superscript and subscript effects on text using Aspose.Cells.

//Setting Superscript Effect


File sdDir = Environment.getExternalStorageDirectory();
String sdPath = sdDir.getCanonicalPath();

//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(sdPath + "/Superscript.xls");


//Setting Subscript Effect

File sdDir = Environment.getExternalStorageDirectory();
String sdPath = sdDir.getCanonicalPath();

//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(sdPath + "/Subscript.xls");

More about Aspose.Cells for Java

- Homepage of Aspose.Cells for Java: http://www.aspose.com/java/excel-component.aspx

- Download Aspose.Cells for Java: http://www.aspose.com/community/files/72/java-components/aspose.cells-for-java/default.aspx



Post Code  |  Code Snippet Home

User Responses


No response found, be the first to review this code snippet.

Submit feedback about this code snippet

Please sign in to post feedback

Latest Posts