从 Cell 获取 HTML5 字符串
Contents
[
Hide
]
从 Cell 获取 HTML5 字符串
使用 Aspose.Cells for Python via Java,您可以从单元格中获取 HTML 字符串。这可以通过使用[getHtmlString(布尔值 html5)](https://reference.aspose.com/cells/python/asposecells.api/cell#getHtmlString(boolean)API提供的方法。如果你通过错误的作为参数,它将返回 Normal HTML 但如果你通过真的作为参数,它将返回 HTML5 字符串。
下面的示例代码创建一个工作簿对象并在第一个工作表的单元格 A1 中添加一些文本。然后它使用[getHtmlString(布尔值 html5)](https://reference.aspose.com/cells/python/asposecells.api/cell#getHtmlString(boolean)方法并打印它们。
示例代码
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
# 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>