获取单元值的文本宽度

获取单元值的文本宽度

有时,开发人员可能需要计算单元格值的宽度,以便在某些布局中安排数据。Aspose.Cells提供了 CellsHelper.GetTextWidth 方法,允许开发人员获取单元格值的文本宽度。以下示例代码演示了如何使用 CellsHelper.GetTextWidth 访问单元格值的文本宽度。

以下代码片段中使用的源文件,请参考附件。

源文件

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// The path to the output directory.
String sourceDir = Utils.Get_SourceDirectory();Workbook workbook = new Workbook(sourceDir + "GetTextWidthSample.xlsx");
System.out.println("Text width: " + CellsHelper.getTextWidth(workbook.getWorksheets().get(0).getCells().get("A1").getStringValue(), workbook.getDefaultStyle().getFont(), 1));