获取 Cell 值的文本宽度
Contents
[
Hide
]
获取 Cell 值的文本宽度
有时,开发人员可能需要计算单元格值的宽度,以便在某些布局中排列数据。 Aspose.Cells 提供了CellsHelper.GetTextWidth允许开发人员获取单元格值的文本宽度的方法。下面的示例代码说明了如何使用CellsHelper.GetTextWidth访问单元格值的文本宽度。
附上以下代码片段中使用的源文件供您参考。
示例代码
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-.NET | |
Workbook workbook = new Workbook(sourceDir + "GetTextWidthSample.xlsx"); | |
Console.WriteLine("Text width: " + CellsHelper.GetTextWidth(workbook.Worksheets[0].Cells["A1"].StringValue, workbook.DefaultStyle.Font, 1)); |