获取单元值的文本宽度
Contents
[
Hide
]
获取单元值的文本宽度
有时,开发者可能需要计算单元格值的宽度以安排布局。Aspose.Cells for Node.js via C++提供 CellsHelper.getTextWidth(string, Font, number) 方法,允许开发者获取单元格值的文本宽度。以下示例代码演示了如何使用 CellsHelper.getTextWidth(string, Font, number) 访问单元格值的文本宽度。
以下代码片段中使用的源文件,请参考附件。
示例代码
This file contains hidden or 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
const AsposeCells = require("aspose.cells.node"); | |
const path = require("path"); | |
// The path to the documents directory. | |
const sourceDir = path.join(__dirname, "data"); | |
let workbook = new AsposeCells.Workbook(sourceDir + "GetTextWidthSample.xlsx"); | |
console.log("Text width: " + AsposeCells.CellsHelper.getTextWidth(workbook.getWorksheets().get(0).getCells().get("A1").getStringValue(), workbook.getDefaultStyle().getFont(), 1)); |