セル値のテキスト幅を取得する

セル値のテキスト幅を取得する

時には、レイアウトを整えるためにセルの値の幅を計算する必要があります。Aspose.Cells for Node.js via C++は、そのためのCellsHelper.getTextWidth(string, Font, number)メソッドを提供しており、開発者はセルの値のテキスト幅を取得できます。以下のサンプルコードは、そのCellsHelper.getTextWidth(string, Font, number)を使用してセルの値のテキスト幅をアクセスする方法を示しています。

以下のコードスニペットで使用されるソースファイルは参照用に添付されています。

ソースファイル

サンプルコード

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));