Excel 스프레드시트는 데이터를 구성, 관리 및 계산하는 데 유용합니다. 마찬가지로 HTML은 브라우저에 콘텐츠를 표시하는 데 유용합니다. 두 형식 모두 특정 사용 사례에서 편리합니다. 웹 사이트에 Excel 데이터를 표시해야 하는 경우가 있습니다. 이러한 경우 HTML이 사용하기에 더 나은 형식이 될 것입니다. 이렇게 하려면 필요한 Excel 파일을 HTML로 변환해야 합니다. 이에 비추어 C++를 사용하여 Excel 파일을 HTML로 변환하는 방법을 배웁니다.
C++ Excel에서 HTML 변환기 API로 – 무료 다운로드
Aspose.Cells for C++는 Excel 스프레드시트를 생성, 변환 및 조작하기 위한 C++ 네이티브 API입니다. API의 내장 변환기를 사용하여 Excel 파일을 HTML로 변환할 수 있습니다. NuGet을 통해 API를 설치하거나 다운로드 섹션에서 직접 다운로드하세요.
PM> Install-Package Aspose.Cells.Cpp
Excel에서 HTML C++로 변환
다음은 Excel 파일을 HTML로 변환하는 단계입니다.
- IWorkbook 클래스를 이용하여 엑셀 파일을 불러옵니다.
- IWorkbook->Save(intrusiveptrAspose::Cells::Systems::String fileName, Aspose::Cells::SaveFormat saveFormat) 메서드.
다음은 Excel 파일을 HTML로 변환하기 위한 C++ 코드 스니펫입니다.
// 소스 디렉토리 경로.
StringPtr srcDir = new String("SourceDirectory\\");
// 출력 디렉토리 경로.
StringPtr outDir = new String("OutputDirectory\\");
// 엑셀 파일 불러오기
intrusive_ptr<IWorkbook> workbook = Factory::CreateIWorkbook(srcDir->StringAppend(new String("sampleExcelFile.xlsx")));
// HTML 파일로 저장
workbook->Save(outDir->StringAppend(new String("sampleExcelFile_out.html")), SaveFormat_Html);
추가 옵션이 있는 C++ Excel에서 HTML로 변환
Aspose.Cells for C++ API는 변환된 HTML 파일을 사용자 정의하기 위한 IHtmlSaveOptions 클래스를 제공합니다. 다음은 IHtmlSaveOptions 클래스에서 제공하는 옵션입니다.
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.
IHtmlSaveOptions를 사용하여 Excel을 HTML로 변환
다음은 추가 옵션을 사용하여 Excel을 HTML로 변환하는 단계입니다.
- 먼저 IWorkbook 클래스가 포함된 Excel 파일을 로드합니다.
- IHtmlSaveOptions 클래스의 인스턴스를 만듭니다.
- ExportHiddenWorksheet와 같은 IHtmlSaveOptions 클래스로 추가 옵션을 설정합니다.
- 마지막으로 IWorkbook->Save(intrusiveptr)를 사용하여 Excel 파일을 HTML로 저장합니다.Aspose::Cells::Systems::String 파일 이름, intrusiveptrAspose::Cells::ISaveOptions saveOptions) 메서드.
다음 코드 샘플은 추가 옵션을 사용하여 Excel 파일을 HTML로 변환하는 방법을 보여줍니다.
// 소스 디렉토리 경로.
StringPtr srcDir = new String("SourceDirectory\\");
// 출력 디렉토리 경로.
StringPtr outDir = new String("OutputDirectory\\");
// 엑셀 파일 불러오기
intrusive_ptr<IWorkbook> workbook = Factory::CreateIWorkbook(srcDir->StringAppend(new String("sampleExcelFile.xlsx")));
// IHtmlSaveOptions 개체를 만듭니다.
intrusive_ptr<Aspose::Cells::IHtmlSaveOptions> options = Factory::CreateIHtmlSaveOptions();
// 숨겨진 시트 내보내기 비활성화
options->SetExportHiddenWorksheet(false);
// HTML 파일로 저장
workbook->Save(outDir->StringAppend(new String("sampleExcelFile_out.html")), options);
무료 라이선스 받기
임시 무료 라이선스를 요청하면 평가 제한 없이 API를 사용해 볼 수 있습니다.
결론
이 기사에서는 C++를 사용하여 Excel 파일을 HTML로 변환하는 방법을 배웠습니다. 또한 숨겨진 워크시트를 내보낼지 여부와 같이 Excel에서 HTML로의 변환을 사용자 지정하는 다양한 옵션을 보았습니다. 문서를 사용하여 C++용 Aspose.Cells에 대해 자세히 알아볼 수 있습니다.