Manage Cells Html String

Possible Usage Scenarios

When you need to set styled data for specific Cell, you can assign a html string to the Cell. Of course, you can also obtain the HTML string of the cell. Aspose.Cells offers this feature. Aspose.Cells provides the following properties and methods to help you achieve your goals.

Get and set html string using Aspose.Cells

This example shows how to:

  1. Create a workbook and add some data.
  2. Get the specific Cell in the first worksheet.
  3. Set html string to the Cell.
  4. Get html string of the Cell.
//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 generated by the sample code

The following screenshot shows the output of the above sample code.

todo:image_alt_text