As planilhas do Excel são úteis na organização, gerenciamento e computação de dados. Da mesma forma, HTML é útil para exibir conteúdo no navegador. Ambos os formatos são úteis em seus casos de uso específicos. Pode haver casos em que você precise mostrar dados do Excel em sites. Nesses casos, HTML seria o melhor formato a ser usado. Para conseguir isso, você terá que converter o arquivo Excel necessário para HTML. À luz disso, você aprenderá como converter arquivos do Excel para HTML usando C++.
- C++ Excel para API de conversão de HTML – Download grátis
- Conversão de Excel para HTML C++
- C++ Excel para conversão de HTML com opções adicionais
- Obtenha uma licença gratuita
C++ Excel para API de conversão de HTML – Download grátis
Aspose.Cells for C++ é uma API nativa de C++ para criar, converter e manipular planilhas do Excel. Você pode usar o conversor integrado da API para converter arquivos do Excel em HTML. Instale a API via NuGet ou baixe-a diretamente da seção Downloads.
PM> Install-Package Aspose.Cells.Cpp
Conversão de Excel para HTML C++
A seguir estão as etapas para converter arquivos do Excel para HTML:
- Carregue o arquivo Excel usando a classe IWorkbook.
- Salve o arquivo como HTML usando IWorkbook->Save(intrusiveptrAspose::Cells::Systems::String fileName, Aspose::Cells::SaveFormat saveFormat).
Veja a seguir o trecho de código C++ para converter arquivos do Excel em HTML:
// Caminho do diretório de origem.
StringPtr srcDir = new String("SourceDirectory\\");
// Caminho do diretório de saída.
StringPtr outDir = new String("OutputDirectory\\");
// Carregar arquivo Excel
intrusive_ptr<IWorkbook> workbook = Factory::CreateIWorkbook(srcDir->StringAppend(new String("sampleExcelFile.xlsx")));
// Salvar como arquivo HTML
workbook->Save(outDir->StringAppend(new String("sampleExcelFile_out.html")), SaveFormat_Html);
C++ Excel para conversão de HTML com opções adicionais
Aspose.Cells para C++ API fornece a classe IHtmlSaveOptions para personalizar o arquivo HTML convertido. A seguir estão as opções fornecidas pela classe IHtmlSaveOptions.
Opções fornecidas pela classe 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.
Convertendo Excel para HTML com IHtmlSaveOptions
A seguir estão as etapas para converter Excel em HTML com opções adicionais:
- Primeiramente, carregue o arquivo Excel com a classe IWorkbook.
- Crie uma instância da classe IHtmlSaveOptions.
- Defina opções adicionais com a classe IHtmlSaveOptions, como ExportHiddenWorksheet.
- Finalmente, salve o arquivo do Excel como HTML usando o IWorkbook->Save(intrusiveptrAspose::Cells::Systems::String fileName, intrusiveptrAspose::Cells::ISaveOptions saveOptions).
O exemplo de código a seguir mostra como converter arquivos do Excel em HTML com opções adicionais:
// Caminho do diretório de origem.
StringPtr srcDir = new String("SourceDirectory\\");
// Caminho do diretório de saída.
StringPtr outDir = new String("OutputDirectory\\");
// Carregar arquivo Excel
intrusive_ptr<IWorkbook> workbook = Factory::CreateIWorkbook(srcDir->StringAppend(new String("sampleExcelFile.xlsx")));
// Crie o objeto IHtmlSaveOptions.
intrusive_ptr<Aspose::Cells::IHtmlSaveOptions> options = Factory::CreateIHtmlSaveOptions();
// Desabilitar a exportação da planilha oculta
options->SetExportHiddenWorksheet(false);
// Salvar como arquivo HTML
workbook->Save(outDir->StringAppend(new String("sampleExcelFile_out.html")), options);
Obtenha uma licença gratuita
Você pode experimentar a API sem limitações de avaliação solicitando uma licença temporária gratuita.
Conclusão
Neste artigo, você aprendeu como converter um arquivo do Excel em HTML usando C++. Além disso, você viu diferentes opções para personalizar a conversão do Excel para HTML, como exportar planilhas ocultas. Você pode explorar mais sobre o Aspose.Cells para C++ usando documentação.