Hämta HTML5 sträng från cell

Möjliga användningsscenario

Aspose.Cells returnerar HTML-strängen för cellen med hjälp av Cell.getHtmlString(boolean)-metoden som tar emot en boolean-parameter. Om du skickar false som parameter, returnerar den vanlig HTML, men om du skickar true, returnerar den HTML5-sträng.

Hämta HTML5-sträng från cell

Följande exempel skapar ett arbetsboksobjekt och lägger till lite text i cell A1 i det första kalkbladet. Sedan hämtar den den normala HTML och HTML5-sträng från cell A1 med Cell.getHtmlString(boolean)-metoden och skriver ut dem i konsolen.

Exempelkod

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);

Konsoloutput

 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>