Accedere alla casella di testo per nome
Contents
[
Hide
]
In precedenza, i riquadri di testo venivano accessi per indice dalla collezione Workheet.getTextBoxes() ma ora puoi accedere anche al riquadro di testo per nome da questa collezione. Questo è un modo conveniente e rapido per accedere al tuo riquadro di testo se conosci già il suo nome.
Accedi al riquadro di testo per nome
Il seguente codice di esempio crea prima una casella di testo e le assegna un testo e un nome. Poi nelle righe successive, accediamo alla stessa casella di testo per nome e stampiamo il suo testo.
This file contains 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()); |
Output della console
Ecco l’output della console del codice di esempio sopra.
This is MyTextBox