在 Cell 中添加 HTML 富文本
Contents
[
Hide
]
Aspose.Cells支持将面向Microsoft Excel的HTML转换为XLS/XLSX格式。这意味着,Microsoft Excel生成的HTML可以使用Aspose.Cells转换回XLS/XLSX格式。
同样,如果有一些简单的HTML,Aspose.Cells可以将其转换为HTML Rich Text。 Aspose.Cells提供Cell.HtmlString属性可以采用这样一个简单的 HTML 并将其转换为格式化的单元格文本。
下面的代码示例向您展示了如何在单元格内添加 HTML 富文本。请查看输出 Excel 文件的屏幕截图。
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-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
Workbook workbook = new Workbook(); | |
Worksheet worksheet = workbook.Worksheets[0]; | |
Cell cell = worksheet.Cells["A1"]; | |
cell.HtmlString = "<Font Style=\"FONT-WEIGHT: bold;FONT-STYLE: italic;TEXT-DECORATION: underline;FONT-FAMILY: Arial;FONT-SIZE: 11pt;COLOR: #ff0000;\">This is simple HTML formatted text.</Font>"; | |
workbook.Save(dataDir + "output_out.xlsx"); |