Excel mit Rasterlinien in HTML exportieren via JavaScript
Contents
[
Hide
]
Wenn Sie Ihre Excel-Datei mit Rasterlinien in HTML exportieren möchten, verwenden Sie die Eigenschaft HtmlSaveOptions.exportGridLines() und setzen Sie sie auf true.
Excel in HTML mit Rasterlinien exportieren
Der folgende Beispielcode erstellt eine Arbeitsmappe, füllt das Arbeitsblatt mit einigen Werten und speichert sie anschließend im HTML-Format, nachdem die Eigenschaft HtmlSaveOptions.exportGridLines() auf true gesetzt wurde.
<!DOCTYPE html>
<html>
<head>
<title>Export To HTML With GridLines Example</title>
</head>
<body>
<h1>Export To HTML With GridLines Example</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, HtmlSaveOptions, SaveFormat } = 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 () => {
// Create your workbook
const wb = new Workbook();
// Access first worksheet
const ws = wb.worksheets.get(0);
// Fill worksheet with some integer values
for (let r = 0; r < 10; r++) {
for (let c = 0; c < 10; c++) {
const cell = ws.cells.get(r, c);
cell.value = r * 1;
}
}
// Save your workbook in HTML format and export gridlines
const opts = new HtmlSaveOptions();
opts.exportGridLines = true;
const outputData = wb.save(SaveFormat.Html, opts);
const blob = new Blob([outputData], { type: 'text/html' });
const downloadLink = document.getElementById('downloadLink');
downloadLink.href = URL.createObjectURL(blob);
downloadLink.download = 'ExportToHTMLWithGridLines_out.html';
downloadLink.style.display = 'block';
downloadLink.textContent = 'Download HTML File';
document.getElementById('result').innerHTML = '<p style="color: green;">HTML exported successfully! Click the download link to get the file.</p>';
});
</script>
</html>