从单元格获取HTML5字符串

可能的使用场景

Aspose.Cells返回单元格的HTML字符串,使用GetHtmlString方法接受一个布尔型参数。如果你传递false作为参数,它将返回标准的HTML,但如果你传递true作为参数,它将返回HTML5字符串。

从单元格获取HTML5字符串

以下示例代码创建一个工作簿对象,并在第一个工作表的A1单元格中添加一些文本。然后使用GetHtmlString方法从A1单元格获取普通的HTML和HTML5字符串,并将它们打印在控制台上。

示例代码

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
//Create workbook.
Workbook wb = new Workbook();
//Access first worksheet.
Worksheet ws = wb.Worksheets[0];
//Access cell A1 and put some text inside it.
Cell cell = ws.Cells["A1"];
cell.PutValue("This is some text.");
//Get the Normal and Html5 strings.
string strNormal = cell.GetHtmlString(false);
string strHtml5 = cell.GetHtmlString(true);
//Print the Normal and Html5 strings on console.
Console.WriteLine("Normal:\r\n" + strNormal);
Console.WriteLine();
Console.WriteLine("Html5:\r\n" + strHtml5);

控制台输出

 Normal:

<Font Style="FONT-FAMILY: Arial;FONT-SIZE: 10pt;COLOR: #000000;">This is some text.</Font>

Html5:

<div Style="FONT-FAMILY: Arial;FONT-SIZE: 10pt;COLOR: #000000;">This is some text.</div>