名前でテキスト ボックスにアクセスする
Contents
[
Hide
]
以前は、テキスト ボックスは、Workheet.getTextBoxes()コレクションですが、このコレクションから名前でテキスト ボックスにアクセスできるようになりました。テキスト ボックスの名前が既にわかっている場合、これはテキスト ボックスにアクセスするための便利で迅速な方法です。
名前でテキスト ボックスにアクセスする
次のサンプル コードでは、最初にテキスト ボックスを作成し、テキストと名前を割り当てます。次に、次の行で、同じテキスト ボックスに名前でアクセスし、そのテキストを出力します。
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
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(AccessTextBoxName.class); | |
Workbook workbook = new Workbook(); | |
Worksheet sheet = workbook.getWorksheets().get(0); | |
int idx = sheet.getTextBoxes().add(10, 10, 10, 10); | |
// Create a texbox with some text and assign it some name | |
TextBox tb1 = sheet.getTextBoxes().get(idx); | |
tb1.setName("MyTextBox"); | |
tb1.setText("This is MyTextBox"); | |
// Access the same textbox via its name | |
TextBox tb2 = sheet.getTextBoxes().get("MyTextBox"); | |
// Displaying the text of the textbox accessed by its name | |
System.out.println(tb2.getText()); |
コンソール出力
上記のサンプル コードのコンソール出力を次に示します。
This is MyTextBox