从 Cell 获取 HTML5 字符串

可能的使用场景

Aspose.Cells 返回单元格的 HTML 字符串getHtmlString(布尔值 html5)方法。如果你通过错误的作为参数,它将返回 Normal HTML 但如果你通过真的作为参数,它将返回 HTML5 字符串。

从 Cell 获取 HTML5 字符串

下面的示例代码创建一个工作簿对象并在第一个工作表的单元格 A1 中添加一些文本。然后它使用getHtmlString(布尔值 html5)方法并将它们打印在控制台上。

示例代码

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
//Create workbook.
Workbook wb = new Workbook();
//Access first worksheet.
Worksheet ws = wb.getWorksheets().get(0);
//Access cell A1 and put some text inside it.
Cell cell = ws.getCells().get("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.
System.out.println("Normal:\r\n" + strNormal);
System.out.println();
System.out.println("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>