Obtener cadena HTML5 de la Celda
Escenarios de uso posibles
Aspose.Cells devuelve la cadena HTML de la celda usando el método Cell.getHtmlString(boolean) que acepta un parámetro booleano. Si pasas false como parámetro, devolverá HTML normal; si pasas true, devolverá cadena HTML5.
Obtener cadena HTML5 de la Celda
El siguiente código de ejemplo crea un objeto libro de trabajo y agrega algo de texto en la celda A1 de la primera hoja. Luego obtiene las cadenas HTML normal y HTML5 de la celda A1 usando el método Cell.getHtmlString(boolean) y las imprime en la consola.
Código de muestra
const AsposeCells = require("aspose.cells.node"); | |
const path = require("path"); | |
// The path to the documents directory. | |
const dataDir = path.join(__dirname, "data"); | |
// Create workbook. | |
const wb = new AsposeCells.Workbook(); | |
// Access first worksheet. | |
const ws = wb.getWorksheets().get(0); | |
// Access cell A1 and put some text inside it. | |
const cell = ws.getCells().get("A1"); | |
cell.putValue("This is some text."); | |
// Get the Normal and Html5 strings. | |
const strNormal = cell.getHtmlString(false); | |
const strHtml5 = cell.getHtmlString(true); | |
// Print the Normal and Html5 strings on console. | |
console.log("Normal:\r\n" + strNormal); | |
console.log(); | |
console.log("Html5:\r\n" + strHtml5); |
Salida de la consola
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>