Supporta il layout dei tag DIV durante il caricamento di HTML nel foglio di lavoro Excel con Node.js tramite C++
Contents
[
Hide
]
Normalmente, il layout dei tag div viene ignorato durante il caricamento di HTML in un oggetto foglio Excel. Tuttavia, se desideri che il layout dei tag div non venga ignorato, imposta la proprietà HtmlLoadOptions.getSupportDivTag() su true. Il valore predefinito di questa proprietà è false.
Il seguente esempio di codice illustra l’uso della proprietà HtmlLoadOptions.getSupportDivTag(). Si prega di scaricare il logo Aspose usato all’interno dell’HTML di input e il file Excel di output generato dal codice.
const path = require("path");
const fs = require("fs");
const AsposeCells = require("aspose.cells.node");
// The path to the documents directory.
const dataDir = path.join(__dirname, "data");
const exportHtml = `
<html>
<body>
<table>
<tr>
<td>
<div>This is some Text.</div>
<div>
<div>
<span>This is some more Text</span>
</div>
<div>
<span>abc@abc.com</span>
</div>
<div>
<span>1234567890</span>
</div>
<div>
<span>ABC DEF</span>
</div>
</div>
<div>Generated On May 30, 2016 02:33 PM <br />Time Call Received from Jan 01, 2016 to May 30, 2016</div>
</td>
<td>
<img src="${dataDir}/ASpose_logo_100x100.png" />
</td>
</tr>
</table>
</body>
</html>`;
const ms = Buffer.from(exportHtml, "utf-8");
// Specify HTML load options, support div tag layouts
const loadOptions = new AsposeCells.HtmlLoadOptions(AsposeCells.LoadFormat.Html);
loadOptions.setSupportDivTag(true);
// Create workbook object from the html using load options
const wb = new AsposeCells.Workbook(ms, loadOptions);
// Auto fit rows and columns of first worksheet
const ws = wb.getWorksheets().get(0);
ws.autoFitRows();
ws.autoFitColumns();
// Save the workbook in xlsx format
wb.save(path.join(dataDir, "DivTagsLayout_out.xlsx"), AsposeCells.SaveFormat.Xlsx);