PNG या JPEG जैसे छवि प्रारूप में एक एकल Excel कार्यपत्रक को निर्यात करना पूर्वावलोकन उत्पन्न करने के लिए उपयोगी है, स्वरूपित रिपोर्टों को आउटपुट करने और वेब पेजों या पीडीएफ में शीट्स को अंतर्निहित करने में मदद करता है. यह गाइड दिखाता है कि कैसे एक Excel वर्कबुक से छवियों में परिवर्तित किया जा सकता है Aspose.Cells for .NET का उपयोग करके.

Introduction

एक इक्सेल कार्यपत्रक को एक छवि प्रारूप (उदाहरण के लिए, PNG, JPEG) में निर्यात करना, पूर्वावलोकन बनाने, चार्टों को आयात करने या स्प्रैडबोर्ड सामग्री के केवल दृश्य अभिव्यक्तियों को साझा करने में उपयोगी है. इस गाइड में आपको दिखाया गया है कि कैसे किसी Excel कार्यपुस्तिका से एक चित्र को Aspose.Cells for .NET का उपयोग करके परिवर्तित करें.

मामलों का उपयोग

  • एक विशिष्ट कार्यपत्रक का पूर्वावलोकन बनाएं
  • ईमेल या दस्तावेज के लिए निर्यात प्रारूपित रिपोर्ट
  • एक वेब पेज या पीडीएफ में एक एकल शीट शामिल करें

कदम-दर-चरण गाइड

चरण 1: .NET के लिए Aspose.Cells स्थापित करें

$ dotnet add package Aspose.Cells

चरण 2: Excel फ़ाइल लोड करें

Workbook workbook = new Workbook("SalesData.xlsx");
Worksheet sheet = workbook.Worksheets["Q1 Report"]; // Access specific worksheet

चरण 3: छवि रेंडरिंग विकल्पों को परिभाषित करें

ImageOrPrintOptions options = new ImageOrPrintOptions
{
    ImageType = ImageType.Png,
    OnePagePerSheet = true,
    HorizontalResolution = 200,
    VerticalResolution = 200,
    PrintingPageType = PrintingPageType.Default
};

चरण 4: SheetRender ऑब्जेक्ट बनाएं

SheetRender renderer = new SheetRender(sheet, options);

चरण 5: प्रत्येक पृष्ठ को एक छवि में रेंडर करें

for (int pageIndex = 0; pageIndex < renderer.PageCount; pageIndex++)
{
    string imageName = $"worksheet_q1_page_{pageIndex + 1}.png";
    renderer.ToImage(pageIndex, imageName);
}

चरण 6: छवियों को बचाएं

यह कोड स्वचालित रूप से कार्यपत्रक में प्रत्येक प्रिंट योग्य पृष्ठ पर एक छवि को सहेजता है।

चरण 7: वैकल्पिक सुधार

आप अतिरिक्त लेआउट सेटिंग्स लागू कर सकते हैं:

// Show gridlines in the output image
options.ShowGridLines = true;

// Fit all content on a single page
options.AllColumnsInOnePagePerSheet = true;

पूर्ण उदाहरण कोड

using System;
using Aspose.Cells;
class Program
{
    static void Main()
    {
        // Load the Excel workbook
        Workbook workbook = new Workbook("SalesData.xlsx");

        // Access a specific worksheet
        Worksheet sheet = workbook.Worksheets["Q1 Report"];

        // Define image rendering options
        ImageOrPrintOptions options = new ImageOrPrintOptions
        {
            ImageType = ImageType.Png,
            OnePagePerSheet = true,
            HorizontalResolution = 200,
            VerticalResolution = 200,
            PrintingPageType = PrintingPageType.Default
        };

        // Enable gridlines if desired
        options.ShowGridLines = true;

        // Render the sheet to image(s)
        SheetRender renderer = new SheetRender(sheet, options);

        for (int pageIndex = 0; pageIndex < renderer.PageCount; pageIndex++)
        {
            string imageName = $"worksheet_q1_page_{pageIndex + 1}.png";
            renderer.ToImage(pageIndex, imageName);
            Console.WriteLine($"Saved: {imageName}");
        }

        Console.WriteLine("Worksheet successfully rendered to image(s).");
    }
}

सामान्य परिदृश्य और समस्या समाधान

IssueSolution
कट-ऑफ सामग्रीUse AllColumnsInOnePagePerSheet = true
उत्पादन कम गुणवत्ता हैछवि संकल्प बढ़ाएं
ग्रीनहाउस गायबSet ShowGridLines = true

More in this category