获取单元值的文本宽度
Contents
[
Hide
]
获取单元值的文本宽度
有时,开发人员可能需要计算单元值的宽度,以便在某种布局中排列数据。Aspose.Cells for Python via .NET 提供了 CellsHelper.get_text_width 方法,允许开发人员获取单元值的文本宽度。以下示例代码说明了如何使用 CellsHelper.get_text_width 访问单元值的文本宽度。
以下代码片段中使用的源文件,请参考附件。
示例代码
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
import io | |
import aspose.cells | |
from aspose.cells import Workbook, Worksheet, Cells, CellsHelper | |
# For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
workbook = Workbook("Sample.xlsx"); | |
a1_cell_value = workbook.worksheets[0].cells.get("A1").string_value | |
print("Text width: " + str(CellsHelper.get_text_width(a1_cell_value, workbook.default_style.font, 1.0))) |