HTML con JavaScript a través de C++
Convirtiendo Libro de Excel a HTML
La API de Aspose.Cells ofrece soporte para exportar hojas de cálculo a formato HTML. Para esto, Aspose.Cells usa la clase HtmlSaveOptions para ofrecer flexibilidad en el control de varios aspectos del HTML de salida.
El ejemplo de código a continuación muestra cómo guardar un libro de trabajo como un archivo HTML usando JavaScript a través de 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>
Convirtiendo Libro de Excel a Archivos MHTML
MHTML combina HTML normal con recursos externos (es decir, contenido que normalmente está enlazado, como imágenes, animaciones, audio, etc.) en un solo archivo. Se usan para correos electrónicos con extensión de archivo .mht. Aspose.Cells soporta la lectura y escritura de archivos MHTML.
El ejemplo de código a continuación muestra cómo guardar un libro de trabajo como un archivo MHTML usando JavaScript a través de 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>
Temas avanzados
-
Ajustar automáticamente columnas y filas al cargar HTML en el libro de trabajo
-
Evita la notación exponencial de números grandes al importar desde HTML
-
Eliminar espacios redundantes después de salto de línea al importar HTML
-
Desactivar Comentarios Revelados de Niveles Inferiores al guardar en HTML
-
Deshabilitar la exportación de scripts de marco y propiedades del documento
-
Excel a HTML - Utilice la opción PresentationPreference para un mejor diseño
-
Excluir estilos no utilizados durante la conversión de Excel a HTML
-
Expandir texto de derecha a izquierda al exportar archivo Excel a HTML
-
Exportar Formato Condicional DataBar, ColorScale e IconSet al convertir Excel a HTML
-
Exportar propiedades del libro y la hoja de cálculo del documento en la conversión de Excel a HTML
-
Exportar la hoja de estilos CSS por separado en el HTML de salida
-
Ocultar Contenido Superpuesto con CrossHideRight al guardar en HTML
-
Prefijo de estilos de elementos de tabla con la propiedad HtmlSaveOptions.TableCssId
-
Evitar la exportación del contenido oculto de la hoja de cálculo al guardar en HTML
-
Renderizar relleno de degradado para WordArt al convertir hojas de cálculo a HTML
-
Establecer el ancho de la columna a una unidad escalable como em o porcentaje
-
Establecer fuente predeterminada al renderizar la hoja de cálculo a HTML
-
Especifica cómo cruzar la cadena en HTML de salida utilizando HtmlCrossType
-
Soportar el diseño de etiquetas DIV al cargar HTML en un libro de Excel
-
Habilitar Propiedades Personalizadas de CSS al guardar en HTML