セル名と行/列インデックス間の変換
行と列のインデックスから Cell の名前を取得
行と列のインデックスがあれば、セルの名前を見つけることができます。この記事では、その方法について説明します。
Aspose.Cells はCellsHelper.cellIndexToName メソッドを使用すると、行と列のインデックスを指定すると、開発者はセルの名前を取得できます。
次のサンプル コードは、使用方法を示しています。CellsHelper.cellIndexToName 既知の行と列のインデックスで指定されたセルの名前にアクセスします。コードは次の出力を生成します。
Cell [0, 0] の名前: A1
Cell [4, 0] の名前: A5
Cell [0, 4] の名前: E1
Cell [2, 2] の名前: C3
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
String cellname = CellsHelper.cellIndexToName(0, 0); | |
System.out.println("Cell Name at [0, 0]: " + cellname); | |
cellname = CellsHelper.cellIndexToName(4, 0); | |
System.out.println("Cell Name at [4, 0]: " + cellname); | |
cellname = CellsHelper.cellIndexToName(0, 4); | |
System.out.println("Cell Name at [0, 4]: " + cellname); | |
cellname = CellsHelper.cellIndexToName(2, 2); | |
System.out.println("Cell Name at [2, 2]: " + cellname); |
Cell 名前から行と列のインデックスを取得
名前からセルの行と列のインデックスを見つけることができます。この記事では、その方法について説明します。
Aspose.Cells はCellsHelper.cellNameToIndex メソッドを使用すると、開発者はセルの名前から行と列のインデックスを取得できます。
次のサンプル コードは、使用方法を示しています。CellsHelper.cellNameToIndex セルの名前から行と列のインデックスを取得します。コードは次の出力を生成します。
Cell C6 の行インデックス: 5
Cell C6 の列インデックス: 2
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
int[] cellIndices = CellsHelper.cellNameToIndex("C6"); | |
System.out.println("Row Index of Cell C6: " + cellIndices[0]); | |
System.out.println("Column Index of Cell C6: " + cellIndices[1]); |
安全なシート名を作成する
実行時にシート名を割り当てる必要がある場合があります。このシナリオでは、シート名に次のような追加の文字が含まれる場合があります。<>+(?”. シート名として許可されていない文字は、ユーザーが事前に設定した文字に置き換える必要があります。同様に、長さが 31 文字を超える場合は、切り詰める必要があります。Apache POI は安全な名前を作成する特定の機能を提供するため、Aspose.Cells によって同様の機能が提供され、これらすべての問題が処理されます。次のサンプル コードは、この機能を示しています。
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// Long name will be truncated to 31 characters | |
String name1 = CellsHelper.createSafeSheetName("this is first name which is created using CellsHelper.CreateSafeSheetName and truncated to 31 characters"); | |
// Any invalid character will be replaced with _ | |
String name2 = CellsHelper.createSafeSheetName(" <> + (adj.Private ? \" Private\" : \")", '_');//? shall be replaced with _ | |
// Display first name | |
System.out.println(name1); | |
//Display second name | |
System.out.println(name2); |
コンソール出力
これは名前です。
<> + (adj.プライベート_「プライベート」