Cell値のテキスト幅を取得

Cell値のテキスト幅を取得

開発者は、レイアウトにデータを配置するために、セルの値の幅を計算する必要がある場合があります。 Aspose.Cells はCellsHelper.GetTextWidth メソッドを使用すると、開発者はセルの値のテキスト幅を取得できます。次のサンプル コードは、使用方法を示しています。CellsHelper.GetTextWidth セルの値のテキスト幅にアクセスします。

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

ソースファイル

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// The path to the output directory.
String sourceDir = Utils.Get_SourceDirectory();Workbook workbook = new Workbook(sourceDir + "GetTextWidthSample.xlsx");
System.out.println("Text width: " + CellsHelper.getTextWidth(workbook.getWorksheets().get(0).getCells().get("A1").getStringValue(), workbook.getDefaultStyle().getFont(), 1));