프레젠테이션, 웹 사이트 또는 디자인 컴포지션에서 사용하기 위해 Excel 스파이더에서 시각을 생성할 때, 단단한 배경을 제거하고 콘텐츠만 보존하는 것이 종종 유용합니다.이 기사는 Aspose.Cells for .NET를 사용하여 투명한 뒷면을 가진 이미지로 Excel 워크시트를 변환하는 방법을 설명 합니다.

소개

프레젠테이션이나 웹 페이지에서 사용할 수있는 이미지로 데이터를 수출해야 할 때가 있습니다.그러나 기본 화이트 배경과 경계는 혼란 스럽습니다.이 가이드는 Aspose.Cells for .NET을 사용하여 투명한 배후를 가진 PNG 이미지를 Excel 워크시트로 변환하는 방법을 보여줍니다.

왜 투명한 배경을 사용합니까?

  • 다른 UI 요소 또는 배경에 대한 레이어 스프레드시트 콘텐츠
  • Dashboards 및 그래픽 수출에서 시각적 클러터를 줄이기
  • 그래픽 도구 및 프레젠테이션과의 통합을 향상시키기

단계별 가이드

단계 1: .NET을 위한 Aspose.Cells 설치

NuGet Package Manager를 통해 패키지를 설치하십시오.

dotnet add package Aspose.Cells

2단계: 워크북 및 대상표를 업로드합니다.

Excel 파일을 업로드하고 변환하려는 워크시트를 선택합니다.

// Load the Excel file
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 클래스는 워크시트를 투명한 배경을 가진 이미지로 변환합니다.

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와 같은 다른 형식은 투명성을 지원하지 않습니다.
명시적으로 불가능한 네트워크이미지 수출에서 유령 라인을 방지
경기 세포 조정세포 스타일 조정과 함께 아름다운 모양

More in this category