从单元格获取HTML5字符串
Contents
[
Hide
]
可能的使用场景
Aspose.Cells for Python via .NET使用get_html_string(html5)方法返回单元格的HTML字符串,该方法接受一个布尔参数。如果将false作为参数传递,它将返回普通的HTML,但如果将true作为参数传递,它将返回HTML5字符串。
从单元格获取HTML5字符串
以下示例代码创建一个工作簿对象,并在第一个工作表的A1单元格中添加一些文本。然后使用get_html_string(html5)方法从A1单元格获取普通的HTML和HTML5字符串,并将它们打印在控制台上。
示例代码
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
from aspose.cells import Workbook | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# Create workbook. | |
wb = Workbook() | |
# Access first worksheet. | |
ws = wb.worksheets[0] | |
# Access cell A1 and put some text inside it. | |
cell = ws.cells.get("A1") | |
cell.put_value("This is some text.") | |
# Get the Normal and Html5 strings. | |
strNormal = cell.get_html_string(False) | |
strHtml5 = cell.get_html_string(True) | |
# Print the Normal and Html5 strings on console. | |
print("Normal:\r\n" + strNormal) | |
print() | |
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>