
Las hojas de cálculo de Excel son útiles para organizar, administrar y calcular datos. De manera similar, HTML es útil para mostrar contenido en el navegador. Ambos formatos son útiles en sus casos de uso específicos. Puede haber casos en los que tenga que mostrar datos de Excel en sitios web. En esos casos, HTML sería el mejor formato para usar. Para lograr esto, deberá convertir el archivo de Excel requerido a HTML. A la luz de esto, aprenderá cómo convertir archivos de Excel a HTML usando C++.
- C++ Excel to HTML Converter API – Descarga gratuita
- Conversión de Excel a HTML C++
- Conversión de C++ Excel a HTML con opciones adicionales
- Obtenga una licencia gratis
C++ Excel to HTML Converter API – Descarga gratuita
Aspose.Cells for C++ es una API nativa de C++ para crear, convertir y manipular hojas de cálculo de Excel. Puede utilizar el convertidor integrado de la API para convertir archivos de Excel a HTML. Instale la API mediante NuGet o descárguela directamente desde la sección Descargas.
PM> Install-Package Aspose.Cells.Cpp
Conversión de Excel a HTML C++
Los siguientes son los pasos para convertir archivos de Excel a HTML:
- Cargue el archivo de Excel usando la clase IWorkbook.
- Guarde el archivo como HTML usando IWorkbook->Save(intrusiveptrAspose::Cells::Systems::String fileName, Aspose::Cells::SaveFormat saveFormat) método.
El siguiente es el fragmento de código de C++ para convertir archivos de Excel a HTML:
// Ruta del directorio de origen.
StringPtr srcDir = new String("SourceDirectory\\");
// Ruta del directorio de salida.
StringPtr outDir = new String("OutputDirectory\\");
// Cargar archivo de Excel
intrusive_ptr<IWorkbook> workbook = Factory::CreateIWorkbook(srcDir->StringAppend(new String("sampleExcelFile.xlsx")));
// Guardar como archivo HTML
workbook->Save(outDir->StringAppend(new String("sampleExcelFile_out.html")), SaveFormat_Html);
Conversión de C++ Excel a HTML con opciones adicionales
Aspose.Cells for C++ API proporciona la clase IHtmlSaveOptions para personalizar el archivo HTML convertido. Las siguientes son las opciones proporcionadas por la clase IHtmlSaveOptions.
Opciones proporcionadas por la clase IHtmlSaveOptions
- AttachedFilesDirectory: The directory for saving the attached files.
- AttachedFilesUrlPrefix: Specify the URL prefix for the attached files.
- CellCssPrefix: Set the prefix for the CSS name.
- DefaultFontName: Specify the default font used when the original font does not exist.
- Encoding: Specify the encoding.
- ExpImageToTempDir: Indicate whether to export the images to a temp directory.
- ExportActiveWorksheetOnly: Indicate whether to export only the active worksheet or the whole workbook to HTML.
- ExportBogusRowData: Specify whether to export bogus bottom row data.
- ExportDataOptions: Specify whether to export only the table or all the data of the HTML file.
- ExportFrameScriptsAndProperties: Indicate whether to export frame scripts and properties.
- ExportGridLines: Indicates whether to export grid lines.
- ExportHiddenWorksheet: Specify whether to export the hidden worksheet to HTML.
- ExportImagesAsBase64: Specify whether to save the images in Base64 format.
- FullPathLink: Specify whether to use the full path link in sheet00x.htm,filelist.xml and tabstrip.htm.
- HiddenColDisplayType: Specify whether to export the hidden column (column with the width of 0) to HTML.
- HiddenRowDisplayType: Specify whether to export the hidden row (the row with the height of 0) to HTML.
- HtmlCrossStringType: Specify the behavior of the cells when the text is larger than the cell size.
- LinkTargetType: Specify the link target type in the HTML anchor tag.
- ParseHtmlTagInCell: Indicate to parse HTML tags in a cell.
- PresentationPreference: Set this to true to get a more beautiful HTML presentation.
Conversión de Excel a HTML con IHtmlSaveOptions
Los siguientes son los pasos para convertir Excel a HTML con opciones adicionales:
- En primer lugar, cargue el archivo de Excel con la clase IWorkbook.
- Cree una instancia de la clase IHtmlSaveOptions.
- Configure opciones adicionales con la clase IHtmlSaveOptions como ExportHiddenWorksheet.
- Finalmente, guarde el archivo de Excel como HTML usando IWorkbook->Save(intrusiveptrAspose::Cells::Systems::String fileName, intrusiveptrAspose::Cells::ISaveOptions saveOptions) método.
El siguiente ejemplo de código muestra cómo convertir archivos de Excel a HTML con opciones adicionales:
// Ruta del directorio de origen.
StringPtr srcDir = new String("SourceDirectory\\");
// Ruta del directorio de salida.
StringPtr outDir = new String("OutputDirectory\\");
// Cargar archivo de Excel
intrusive_ptr<IWorkbook> workbook = Factory::CreateIWorkbook(srcDir->StringAppend(new String("sampleExcelFile.xlsx")));
// Cree el objeto IHtmlSaveOptions.
intrusive_ptr<Aspose::Cells::IHtmlSaveOptions> options = Factory::CreateIHtmlSaveOptions();
// Deshabilitar la exportación de la hoja oculta
options->SetExportHiddenWorksheet(false);
// Guardar como archivo HTML
workbook->Save(outDir->StringAppend(new String("sampleExcelFile_out.html")), options);
Obtenga una licencia gratis
Puede probar la API sin limitaciones de evaluación solicitando una licencia temporal gratuita.
Conclusión
En este artículo, ha aprendido cómo convertir un archivo de Excel a HTML usando C++. Además, ha visto diferentes opciones para personalizar la conversión de Excel a HTML, como exportar hojas de trabajo ocultas. Puede explorar más sobre Aspose.Cells for C++ usando documentación.