HTML med JavaScript via C++
Konvertera Excelfil till HTML
Aspose.Cells API stöder export av kalkylblad till HTML-format. För detta använder Aspose.Cells klassen HtmlSaveOptions för att ge flexibilitet att kontrollera flera aspekter av utdata-HTML:en.
Nedan visas ett kodexempel för att spara en arbetsbok som en HTML-fil med JavaScript via C++:
<!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>
Konvertera Excel arbetsbok till MHTML-filer
MHTML kombinerar normalt HTML med externa resurser (det vill säga innehåll som vanligtvis länkas in, såsom bilder, animationer, ljud och liknande) i en fil. De används för e-postmeddelanden med filändelsen .mht. Aspose.Cells stöder läsning och skrivning av MHTML-filer.
Nedan visas ett kodexempel för att spara en arbetsbok som en MHTML-fil med JavaScript via C++:
<!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>
Fortsatta ämnen
-
Justera kolumner och rader automatiskt vid inläsning av HTML i arbetsboken
-
Undvik exponentiell notation av stora tal vid import från HTML
-
Ta bort överflödiga mellanslag efter radbrytning vid import av HTML
-
Inaktivera nivånedstiällda avslöjade kommentarer vid sparning till HTML
-
Excel till HTML - Använd PresentationPreference-alternativet för bättre layout
-
Expandera text från höger till vänster vid export av Excel-fil till HTML
-
Exportera DataBar, ColorScale och IconSet villkorlig formatering vid Excel till HTML-omvandling
-
Exportera dokumentarbetsboks- och arbetsbladsegenskaper vid konvertering från Excel till HTML
-
Exportera liknande kantstilmall när kantstil inte stöds av webbläsare
-
Dölja överlagt innehåll med CrossHideRight vid sparande till HTML
-
Förprefixa tabellens elementstilar med HtmlSaveOptions.TableCssId-egenskapen
-
Förhindra export av dolda arbetsbladsinnehåll när du sparar till HTML
-
Ange sökväg till exporterad arbetsbokhtml-fil via IFilePathProvider-gränssnittet
-
Rendera gradientfyllning för WordArt vid konvertering av kalkylblad till HTML
-
Ange hur man korsar sträng i utmatnings-HTML med HtmlCrossType
-
Stödjer layouten för DIV-taggar vid laddning av HTML till excel arbetsbok