HTML with JavaScript via C++
Contents
[
Hide
]
Converting Excel Workbook to HTML
The Aspose.Cells API provides support for exporting spreadsheets to HTML format. For this purpose, Aspose.Cells uses the HtmlSaveOptions class to provide the flexibility to control several aspects of the output HTML.
The code example below shows how to save a workbook as an HTML file using 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>
Converting Excel Workbook to MHTML Files
MHTML combines normal HTML with external resources (that is, content that is usually linked into, like images, animations, audio, and so on) into one file. They are used for emails with the .mht file extension. Aspose.Cells supports reading and writing MHTML files.
The code example below shows how to save a workbook as an MHTML file using 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>
Advanced topics
- AutoFit Columns and Rows while loading HTML in Workbook
- Avoid exponential notation of large numbers while importing from HTML
- Change the HTML Link Target Type
- Convert Excel to HTML with tooltip
- Create Transparent Image of Excel Worksheet
- Delete redundant spaces after line break while importing HTML
- Disable Downlevel Revealed Comments while saving to HTML
- Disable Exporting Frame Scripts and Document Properties
- Excel to HTML - Use PresentationPreference Option for Better Layout
- Exclude Unused Styles during Excel to HTML conversion
- Expanding text from right to left while exporting Excel file to HTML
- Export DataBar, ColorScale and IconSet Conditional Formatting while Excel to HTML Conversion
- Export Comments while Saving Excel file to HTML
- Export Document Workbook and Worksheet Properties in Excel to HTML conversion
- Export Excel to HTML with GridLines
- Export print area range to HTML
- Export similar Border Style when Border Style is not supported by Web Browsers
- Export Worksheet CSS Separately in Output HTML
- Hiding Overlaid Content with CrossHideRight while saving to HTML
- Prefix Table Elements Styles with HtmlSaveOptions.TableCssId property
- Prevent Exporting Hidden Worksheet Contents on Saving to HTML
- Provide exported worksheet HTML file path via IFilePathProvider interface
- Recognize Self Closing Tags
- Render Gradient Fill for the WordArt while Converting Spreadsheets to HTML
- Set column width to a scalable unit like em or percent
- Set Default Font while rendering spreadsheet to HTML
- Specify how to cross string in output HTML using HtmlCrossType
- Support the layout of DIV tags while loading HTML to Excel workbook
- Enable CSS Custom Properties while saving to HTML