HTMLをJavaScript経由でC++
ExcelワークブックをHTMLに変換する
Aspose.Cells APIは、スプレッドシートをHTML形式にエクスポートする機能をサポートしています。これには、出力HTMLの複数の側面を制御する柔軟性を提供する HtmlSaveOptions クラスを使用します。
以下のコード例は、JavaScript経由でC++を使用してワークブックをHTMLファイルとして保存する方法を示しています:
<!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ワークブックをMHTMLファイルに変換する
MHTMLは、通常のHTMLに外部リソース(画像やアニメーション、音声など)を結合し、一つのファイルにまとめたものです。.mht拡張子のメールに使用されます。Aspose.Cellsは、MHTMLファイルの読み書きをサポートしています。
以下のコード例は、JavaScriptを経由してC++を使用してワークブックをMHTMLファイルとして保存する方法を示しています:
<!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>
高度なトピック
-
ExcelをHTMLに変換する際にPresentationPreferenceオプションを使用してレイアウトを向上させる
-
Excel を HTML に変換する際の DataBar、ColorScale、および IconSet 条件付き書式をエクスポート
-
HTMLに保存する際のボーダースタイルがWebブラウザでサポートされていない場合に似たボーダースタイルをエクスポートする
-
[HtmlSaveOptions.TableCssIdプロパティの使用方法についてのサンプルコードを以下に説明します。参照のために、コードによって生成されたoutput HTMLを確認してください。](/cells/ja/javascript-cpp/prefix-table-elements-styles-with-htmlsaveoptions-tablecssid-property/)
-
[次のサンプルコードは、{0} 属性の使用例を示しています。このプロパティがTrueに設定されていない場合の効果もスクリーンショットで示しています。サンプルExcelファイルと生成された出力HTMLをダウンロードして参照してください。](/cells/ja/javascript-cpp/enable-css-custom-properties-while-saving-to-html/)