C#에서 Excel을 HTML로 변환하는 방법
C#에서 Excel을 HTML로 변환하는 방법
Excel 데이터를 HTML 형식으로 내보내는 것은 브라우저, 이메일 템플릿 또는 웹 응용 프로그램에서 스프레드시트 콘텐츠를 표시할 때 필수적입니다.이 가이드는 Excel 워크북을 HTML으로 변환하는 방법을 보여줍니다. Aspose.Cells for .NET.
Excel에서 HTML로 변환하는 방법
- 웹사이트에서 Excel 데이터의 사전 보기 생성
- 웹 기반 스프레드시트 보기 가능
- CMS 또는 블로그에 테이블 데이터를 삽입
단계별 가이드
단계 1: .NET을 위한 Aspose.Cells 설치
dotnet add package Aspose.Cells
2단계: 워크북을 업로드
Workbook workbook = new Workbook("path/to/excel.xlsx");
단계 3: HTML 저장 옵션 설정 (선택)
HtmlSaveOptions options = new HtmlSaveOptions(SaveFormat.Html);
단계 4 : Excel을 HTML 파일로 내보내기
workbook.Save("path/to/output.html", options);
5단계: 파일 대신 메모리 스트림으로 저장
using (MemoryStream outputStream = new MemoryStream())
{
workbook.Save(outputStream, SaveFormat.Html);
outputStream.Position = 0;
// Use the stream in a web response, save to disk, etc.
}
전체 코드 예제
using System;
using System.IO;
using Aspose.Cells;
class Program
{
static void Main()
{
Workbook workbook = new Workbook("input.xlsx");
// Option 1: Save to HTML file
HtmlSaveOptions options = new HtmlSaveOptions(SaveFormat.Html);
workbook.Save("output.html", options);
// Option 2: Save to stream for web applications
using (MemoryStream stream = new MemoryStream())
{
workbook.Save(stream, SaveFormat.Html);
stream.Position = 0;
// Use the stream as needed (e.g., send in API response)
}
Console.WriteLine("Excel exported to HTML.");
}
}
팁과 최고의 관행
팁 | 설명 |
---|---|
사용하기 HtmlSaveOptions | 완벽한 출력 HTML 구조, 캐릭터 암호화, 또는 이미지 통합 |
흐름을 저장하기 | APIs 또는 서버없는 기능에 유용 |
스타일링 보존 | Aspose.Cells는 대부분의 스타일링 및 레이아웃 요소가 유지되도록 보장합니다. |