Gestisci Stringa Html Celle
Possibili Scenari di Utilizzo
Quando hai bisogno di impostare dati formattati per una cella specifica, puoi assegnare una stringa html alla cella. Naturalmente, puoi anche ottenere la stringa HTML della cella. Aspose.Cells offre questa funzionalità. Aspose.Cells fornisce le proprietà e i metodi seguenti per aiutarti a raggiungere i tuoi obiettivi.
Ottieni e imposta la stringa HTML usando Aspose.Cells
Questo esempio mostra come:
- Creare un workbook e aggiungere alcuni dati.
- Ottenere la cella specifica nella prima scheda di lavoro.
- Impostare una stringa HTML nella cella.
- Ottenere la stringa HTML della cella.
//Instantiating an Workbook object | |
Workbook workbook = new Workbook(); | |
//Obtaining the reference of the newly added worksheet | |
Worksheet ws = workbook.Worksheets[0]; | |
Cells cells = ws.Cells; | |
//Setting the value to the cells | |
Cell cell = cells["A1"]; | |
cell.PutValue("Fruit"); | |
cell = cells["B1"]; | |
cell.PutValue("Count"); | |
cell = cells["C1"]; | |
cell.PutValue("Price"); | |
cell = cells["A2"]; | |
cell.PutValue("Apple"); | |
cell = cells["A3"]; | |
cell.PutValue("Mango"); | |
cell = cells["A4"]; | |
cell.PutValue("Blackberry"); | |
cell = cells["A5"]; | |
cell.PutValue("Cherry"); | |
Cell c3 = cells["C3"]; | |
//set html string for C3 cell. | |
c3.HtmlString = "<b>test bold</b>"; | |
Cell c4 = cells["C4"]; | |
//set html string for C4 cell. | |
c4.HtmlString = "<i>test italic</i>"; | |
//get the html string of specific cell. | |
Console.WriteLine(c3.HtmlString); | |
Console.WriteLine(c4.HtmlString); |
Output generato dal codice di esempio
Lo screenshot seguente mostra l’output del codice di esempio precedente.