Supporta il layout dei tag DIV durante il caricamento di HTML in un workbook Excel con JavaScript tramite C++
Contents
[
Hide
]
Normalmente, il layout dei tag div viene ignorato durante il caricamento di HTML in un oggetto cartella di lavoro Excel. Tuttavia, se desideri che il layout dei tag div non venga ignorato, imposta la proprietà HtmlLoadOptions.supportDivTag su true. Il valore predefinito di questa proprietà è false.
Il seguente esempio di codice illustra l’uso della proprietà HtmlLoadOptions.supportDivTag. Scarica il Logo Aspose usato all’interno dell’HTML di input e il file excel di output generato dal codice.
<!DOCTYPE html>
<html>
<head>
<title>Aspose.Cells Example</title>
</head>
<body>
<h1>Example Title</h1>
<input type="file" id="fileInput" accept=".xls,.xlsx,.csv" />
<button id="runExample">Run Example</button>
<a id="downloadLink" style="display: none;">Download Result</a>
<div id="result"></div>
</body>
<script src="aspose.cells.js.min.js"></script>
<script type="text/javascript">
const { Workbook, SaveFormat, HtmlLoadOptions, LoadFormat, Utils } = AsposeCells;
AsposeCells.onReady({
license: "/lic/aspose.cells.enc",
fontPath: "/fonts/",
fontList: [
"arial.ttf",
"NotoSansSC-Regular.ttf"
]
}).then(() => {
console.log("Aspose.Cells initialized");
});
document.getElementById('runExample').addEventListener('click', async () => {
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="ASpose_logo_100x100.png" />
</td>
</tr>
</table>
</body>
</html>`;
// Encode HTML string to Uint8Array
const encoder = new TextEncoder();
const ms = encoder.encode(exportHtml);
// Specify HTML load options, support div tag layouts
const loadOptions = new HtmlLoadOptions(LoadFormat.Html);
loadOptions.supportDivTag = true;
// Create workbook object from the html using load options
const wb = new Workbook(ms, loadOptions);
// Auto fit rows and columns of first worksheet
const ws = wb.worksheets.get(0);
ws.autoFitRows();
ws.autoFitColumns();
// Save the workbook in xlsx format and provide download link
const outputData = wb.save(SaveFormat.Xlsx);
const blob = new Blob([outputData]);
const downloadLink = document.getElementById('downloadLink');
downloadLink.href = URL.createObjectURL(blob);
downloadLink.download = 'DivTagsLayout_out.xlsx';
downloadLink.style.display = 'block';
downloadLink.textContent = 'Download Excel File';
document.getElementById('result').innerHTML = '<p style="color: green;">Workbook created successfully. Click the download link to get the file.</p>';
});
</script>
</html>