获取单元值的文本宽度

获取单元值的文本宽度

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

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

源文件

示例代码

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
Workbook workbook = new Workbook(sourceDir + "GetTextWidthSample.xlsx");
Console.WriteLine("Text width: " + CellsHelper.GetTextWidth(workbook.Worksheets[0].Cells["A1"].StringValue, workbook.DefaultStyle.Font, 1));