Ottieni la stringa HTML5 da Cell
Contents
[
Hide
]
Ottieni la stringa HTML5 da Cell
Utilizzando Aspose.Cells for Python via Java, è possibile ottenere la stringa HTML dalla cella. Ciò può essere ottenuto utilizzando ilgetHtmlString(booleano html5) metodo fornito dallo API. Se passifalsocome parametro, ti restituirà Normal HTML ma se passiVEROcome parametro, restituirà la stringa HTML5.
Il seguente codice di esempio crea un oggetto cartella di lavoro e aggiunge del testo nella cella A1 del primo foglio di lavoro. Quindi ottiene la stringa Normal HTML e HTML5 dalla cella A1 utilizzando il filegetHtmlString(booleano html5) e li stampa.
Codice d’esempio
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) |
Di seguito è riportato l’output generato dallo snippet di codice sopra fornito.
Produzione
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>