Change Character Spacing of Excel TextBox or Shape
Contents
[
Hide
]
You can change the character spacing of excel textbox or shape using the FontSetting.TextOptions.Spacing property.
Change Character Spacing of Excel TextBox or Shape
The following sample code changes the character spacing of the text box in an excel file to point 4 and then saves it on disk.
The following screenshot shows how the sample excel file looks before the execution of the code.
The following screenshot shows how the output excel file looks after the execution of the code.
This file contains 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
// 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.getSharedDataDir(ChangeCharacterSpacing.class) + "articles/"; | |
// Load your excel file inside a workbook obect | |
Workbook wb = new Workbook(dataDir + "character-spacing.xlsx"); | |
// Access your text box which is also a shape object from shapes collection | |
Shape shape = wb.getWorksheets().get(0).getShapes().get(0); | |
// Access the first font setting object via GetCharacters() method | |
ArrayList<FontSetting> lst = shape.getCharacters(); | |
FontSetting fs = lst.get(0); | |
// Set the character spacing to point 4 | |
fs.getTextOptions().setSpacing(4); | |
// Save the workbook in xlsx format | |
wb.save(dataDir + "CCSpacing_out.xlsx", SaveFormat.XLSX); |