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

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

開発者は、時折、データを整理するためにセルの値の幅を計算する必要があります。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));