Accedi alla casella di testo per nome
Contents
[
Hide
]
Accedi alla casella di testo per nome
In precedenza, si accedeva alle caselle di testo tramite l’indice dal fileFoglio di lavoro.Caselle di testoraccolta ma ora puoi anche accedere alla casella di testo per nome da questa raccolta. Questo è un modo comodo e veloce per accedere alla tua casella di testo se ne conosci già il nome.
Il codice di esempio seguente crea innanzitutto una casella di testo e le assegna testo e nome. Quindi, nelle righe successive, accediamo alla stessa casella di testo con il suo nome e stampiamo il suo testo.
C# codice per accedere alla casella di testo per nome
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(); |
Output della console generato dal codice di esempio
Ecco l’output della console del codice di esempio precedente.
This is MyTextBox