HTML mit JavaScript über C++
Excel-Arbeitsmappe in HTML konvertieren
Die API von Aspose.Cells bietet Unterstützung für den Export von Tabellenblättern in das HTML-Format. Für diesen Zweck verwendet Aspose.Cells die HtmlSaveOptions-Klasse, um die Flexibilität bei der Steuerung mehrerer Aspekte des HTML-Ausgangs zu gewährleisten.
Das folgende Codebeispiel zeigt, wie Sie ein Arbeitsbuch als HTML-Datei mit JavaScript über C++ speichern:
<!DOCTYPE html>
<html>
<head>
<title>Aspose.Cells Example</title>
</head>
<body>
<h1>Aspose.Cells - Convert Excel to HTML</h1>
<input type="file" id="fileInput" accept=".xls,.xlsx,.csv" />
<button id="runExample">Convert to HTML</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 } = 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 fileInput = document.getElementById('fileInput');
if (!fileInput.files.length) {
document.getElementById('result').innerHTML = '<p style="color: red;">Please select an Excel file.</p>';
return;
}
const file = fileInput.files[0];
const arrayBuffer = await file.arrayBuffer();
// Instantiating a Workbook object from the uploaded file
const workbook = new Workbook(new Uint8Array(arrayBuffer));
// Saving the workbook to HTML format
const outputData = workbook.save(SaveFormat.Html);
const blob = new Blob([outputData], { type: 'text/html' });
const downloadLink = document.getElementById('downloadLink');
downloadLink.href = URL.createObjectURL(blob);
downloadLink.download = 'out.html';
downloadLink.style.display = 'block';
downloadLink.textContent = 'Download HTML File';
document.getElementById('result').innerHTML = '<p style="color: green;">Conversion completed! Click the download link to get the HTML file.</p>';
});
</script>
</html>
Excel-Arbeitsmappe in MHTML-Dateien konvertieren
MHTML kombiniert normales HTML mit externen Ressourcen (also Inhalte, die gewöhnlich verlinkt sind, wie Bilder, Animationen, Audio usw.) in einer einzigen Datei. Sie werden für E-Mails mit der Erweiterung .mht verwendet. Aspose.Cells unterstützt das Lesen und Schreiben von MHTML-Dateien.
Das folgende Codebeispiel zeigt, wie Sie ein Arbeitsbuch als MHTML-Datei mit JavaScript über C++ speichern:
<!DOCTYPE html>
<html>
<head>
<title>Aspose.Cells Example - Save as MHT</title>
</head>
<body>
<h1>Save Excel as MHT 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, 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 () => {
const fileInput = document.getElementById('fileInput');
const resultDiv = document.getElementById('result');
if (!fileInput.files.length) {
resultDiv.innerHTML = '<p style="color: red;">Please select an Excel file.</p>';
return;
}
const file = fileInput.files[0];
const arrayBuffer = await file.arrayBuffer();
// Load your source workbook from the uploaded file
const workbook = new Workbook(new Uint8Array(arrayBuffer));
// Save file to MHT format
const outputData = workbook.save(SaveFormat.MHtml);
const blob = new Blob([outputData], { type: 'application/octet-stream' });
const downloadLink = document.getElementById('downloadLink');
downloadLink.href = URL.createObjectURL(blob);
downloadLink.download = 'out.mht';
downloadLink.style.display = 'block';
downloadLink.textContent = 'Download MHT File';
resultDiv.innerHTML = '<p style="color: green;">File converted to MHT successfully! Click the download link to get the result.</p>';
});
</script>
</html>
Erweiterte Themen
-
Spalten und Zeilen automatisch anpassen beim Laden von HTML in Arbeitsmappe
-
Vermeiden Sie die exponentielle Notation großer Zahlen beim Importieren aus HTML.
-
Löschen überflüssiger Leerzeichen nach einem Zeilenumbruch beim Importieren von HTML
-
Deaktivieren des Exports von Rahmen-Skripten und Dokumenteigenschaften.
-
Excel zu HTML - Verwenden Sie die Option für die Präsentationspräferenz für ein besseres Layout.
-
Ausnutzen nicht verwendeter Stile während der Konvertierung von Excel in HTML ausschließen
-
Text von rechts nach links erweitern, während Excel-Datei in HTML exportiert wird
-
Kommentare beim Speichern einer Excel-Datei in HTML exportieren
-
Export von Arbeitsmappe- und Arbeitsblatteigenschaften in Excel zur HTML-Konvertierung
-
Ähnlichen Randstil exportieren, wenn der Randstil von Webbrowsern nicht unterstützt wird
-
Überlagerter Inhalt mit CrossHideRight beim Speichern in HTML ausblenden
-
Vorabtabellenelementstilen mit der HtmlSaveOptions.TableCssId-Eigenschaft
-
Verhindern des Exportierens von versteckten Arbeitsblattinhalten beim Speichern als HTML
-
Verlaufsfüllung für WordArt beim Konvertieren von Tabellenkalkulationen in HTML rendern.
-
Spaltenbreite auf skalierbare Einheit wie em oder Prozent setzen.
-
Legen Sie die Standardschriftart beim Rendern der Tabellenkalkulation in HTML fest
-
Geben Sie an, wie die Zeichenfolge im Ausgabe-HTML mit HtmlCrossType gekreuzt wird.
-
Unterstützt das Layout von DIV-Tags beim Laden von HTML in die Excel-Arbeitsmappe
-
Aktivieren Sie CSS Standard-Eigenschaften beim Speichern in HTML