Hantera Cells Html sträng
Möjliga användningsscenario
När du behöver ställa in stylad data för en specifik cell kan du tilldela en html-sträng till cellen. Självklart kan du också få HTML-strängen från cellen. Aspose.Cells erbjuder denna funktion. Aspose.Cells tillhandahåller följande egenskaper och metoder för att hjälpa dig uppnå dina mål.
Hämta och ange html-sträng med hjälp av Aspose.Cells
Detta exempel visar hur man:
- Skapa en arbetsbok och lägg till lite data.
- Hämta den specifika cellen i den första kalkylbladet.
- Ange html-sträng till cellen.
- Hämta HTML-sträng av cellen.
//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); |
Utdata genererad av provkoden
Följande skärmbild visar utdata av ovanstående provkod.