更改 Excel 文本框或形状的字符间距

更改Excel文本框或形状的字符间距

以下示例代码将excel文件中文本框的字符间距更改为4,并将其保存到磁盘上。

以下屏幕截图显示了在执行代码之前 示例的excel文件 的外观。

todo:image_alt_text

以下屏幕截图显示了在执行代码之后 输出的excel文件 的外观。

todo:image_alt_text

// 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);