C#에서 투명 배경으로 Excel을 이미지로 변환하는 방법
C#에서 투명 배경으로 Excel을 이미지로 변환하는 방법
프레젠테이션, 웹 사이트 또는 디자인 컴포지션에서 사용하기 위해 Excel 스파이더에서 시각을 만들 때, 단단한 배경을 제거하고 콘텐츠만 보존하는 것이 종종 유용합니다.이 기사에서는 Excel 워크시트를 투명한 배경을 가진 이미지로 변환하는 방법을 설명합니다. Aspose.Cells for .NET.
왜 투명한 배경을 사용합니까?
- 다른 UI 요소 또는 배경에 대한 레이어 스프레드시트 콘텐츠
- Dashboards 및 그래픽 수출에서 시각적 클러터를 줄이기
- 그래픽 도구 및 프레젠테이션과의 통합을 향상시키기
단계별 가이드
단계 1: .NET을 위한 Aspose.Cells 설치
dotnet add package Aspose.Cells
2단계: 워크북 및 대상표를 업로드합니다.
Workbook workbook = new Workbook("DataGrid.xlsx");
Worksheet sheet = workbook.Worksheets[0];
3단계 : 투명한 배경을 사용하여 렌더링을 설정합니다.
ImageOrPrintOptions options = new ImageOrPrintOptions
{
ImageType = ImageType.Png,
OnePagePerSheet = true,
Transparent = true
};
단계 4 : 배경 및 그리드 라인을 제거합니다.
sheet.PageSetup.PrintGridlines = false;
sheet.PageSetup.PrintHeadings = false;
sheet.DisplayGridlines = false;
단계 5 : SheetRender를 사용하여 렌더 이미지
SheetRender renderer = new SheetRender(sheet, options);
renderer.ToImage(0, "transparent_output.png");
단계 6: 투명한 PNG를 사용하십시오.
결과는 순수한 PNG 이미지가 될 것이며 셀 콘텐츠만 제공됩니다 - 흰색 배경이나 경계가 없습니다.
완전한 샘플 코드
using System;
using Aspose.Cells;
class Program
{
static void Main()
{
// Load the Excel file
Workbook workbook = new Workbook("DataGrid.xlsx");
Worksheet sheet = workbook.Worksheets[0];
// Hide gridlines and headings
sheet.PageSetup.PrintGridlines = false;
sheet.PageSetup.PrintHeadings = false;
sheet.DisplayGridlines = false;
// Set image rendering options with transparency
ImageOrPrintOptions options = new ImageOrPrintOptions
{
ImageType = ImageType.Png,
Transparent = true,
OnePagePerSheet = true
};
// Render the sheet as an image
SheetRender renderer = new SheetRender(sheet, options);
renderer.ToImage(0, "transparent_output.png");
Console.WriteLine("Worksheet rendered with transparent background.");
}
}
최고의 결과를 위한 팁
팁 | 설명 |
---|---|
투명성을 위한 PNG 사용 | JPEG와 같은 다른 형식은 투명성을 지원하지 않습니다. |
명시적으로 불가능한 네트워크 | 이미지 수출에서 유령 라인을 방지 |
경기 세포 조정 | 세포 스타일 조정과 함께 아름다운 모양 |