管理单元格HTML字符串
Contents
[
Hide
]
可能的使用场景
当您需要为特定单元格设置样式化数据时,可以将HTML字符串分配给该单元格。当然,您也可以获取单元格的HTML字符串。Aspose.Cells提供了这一功能。Aspose.Cells提供以下属性和方法,帮助您实现您的目标。
使用 Aspose.Cells 获取和设置 HTML 字符串
此示例演示如何:
- 创建一个工作簿并添加一些数据。
- 获取第一个工作表中的特定单元格。
- 将HTML字符串设置给单元格。
- 获取单元格的HTML字符串。
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
//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); |
示例代码生成的输出
以下截图显示了上述示例代码的输出。