从单元格获取HTML5字符串

从单元格获取HTML5字符串

使用Aspose.Cells for Python via Java,您可以从单元格获取HTML字符串。这可以通过使用API提供的getHtmlString(boolean html5)方法实现。如果将false作为参数传递,它将返回普通HTML,但如果将true作为参数传递,它将返回HTML5字符串。

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

示例代码

# Load the Sample Workbook
workbook = Workbook()
# Access first worksheet
worksheet = workbook.getWorksheets().get(0)
# Access cell A1 and put some text inside it.
cell = worksheet.getCells().get("A1")
cell.putValue("This is some text.")
# Get the Normal and Html5 strings.
strNormal = cell.getHtmlString(False)
strHtml5 = cell.getHtmlString(True)
# Print the Normal and Html5 strings
print("Normal:\r\n" + strNormal)
print("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>