名前でテキスト ボックスにアクセスする
Contents
[
Hide
]
名前でテキスト ボックスにアクセスする
以前は、テキスト ボックスは、Worksheet.TextBoxesコレクションですが、このコレクションから名前でテキスト ボックスにアクセスできるようになりました。テキスト ボックスの名前が既にわかっている場合、これはテキスト ボックスにアクセスするための便利で迅速な方法です。
次のサンプル コードでは、最初にテキスト ボックスを作成し、テキストと名前を割り当てます。次に、次の行で、同じテキスト ボックスに名前でアクセスし、そのテキストを出力します。
C# 名前でテキスト ボックスにアクセスするコード
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-.NET | |
// Create an object of the Workbook class | |
Workbook workbook = new Workbook(); | |
// Access first worksheet from the collection | |
Worksheet sheet = workbook.Worksheets[0]; | |
// Add the TextBox to the worksheet | |
int idx = sheet.TextBoxes.Add(10, 10, 10, 10); | |
// Access newly created TextBox using its index & name it | |
TextBox tb1 = sheet.TextBoxes[idx]; | |
tb1.Name = "MyTextBox"; | |
// Set text for the TextBox | |
tb1.Text = "This is MyTextBox"; | |
// Access the same TextBox via its name | |
TextBox tb2 = sheet.TextBoxes["MyTextBox"]; | |
// Display the text of the TextBox accessed via name | |
Console.WriteLine(tb2.Text); | |
Console.WriteLine("Press any key to continue..."); | |
Console.ReadKey(); |
サンプル コードによって生成されたコンソール出力
上記のサンプル コードのコンソール出力を次に示します。
This is MyTextBox