セル値のテキスト幅を取得する
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)); |