Excel to Image in C#

Converting Excel XLSX or XLS files to image formats such as JPG and PNG can be highly beneficial in various scenarios. Whether you want to display Excel data on a website, embed it into a report, or share a snapshot of your spreadsheet without exposing the original file, converting Excel sheets to images is an efficient solution. In this blog post, we will demonstrate how to convert Excel files into JPG and PNG images programmatically using C#.

Why Convert Excel to Image?

There are several reasons why converting Excel sheets to images can be advantageous:

  1. Ease of Sharing: Images are easier to share and view across devices and platforms compared to Excel files.

  2. No Dependency on Excel Software: Recipients do not need to have Excel installed to view the data.

  3. Data Protection: Converting Excel to images ensures the data is not editable, offering better protection for sensitive information.

  4. Enhanced Presentation: Images can be integrated into websites, presentations, and documents for a more polished look.

  5. Quick Access: Images load faster and are easier to preview, especially for non-technical users.

By converting Excel files to JPG or PNG, you can simplify data sharing and presentation while ensuring better accessibility.

XLSX to Image Conversion - C# API Installation

You can render Excel XLSX or XLS files by installing Conholdate.Total for .NET in your system. You can either download the DLL file or run the NuGet installation command below:

PM> NuGet\Install-Package Conholdate.Total

Convert Excel to JPG Image in C#

The steps below explain the process to export Excel spreadsheet to a JPG image in C#:

  • Load the Workbook: The Workbook class loads the Excel file.

  • Select Worksheet: The Worksheets[0] property retrieves the first worksheet.

  • Configure Image Options: The ImageOrPrintOptions object allows you to set resolution and specify the image type as JPG.

  • Render Images: The SheetRender class generates images for each page of the worksheet.

  • Save Images: The ToImage method saves each page as a separate JPG file.

The following sample code shows how to convert Excel to JPG in C#:

Convert XLSX to PNG Image in C#

The following steps demonstrate how to render XLSX or XLS file to PNG image in C#:

  • Load the Workbook: Similar to the JPG conversion, the Workbook class loads the Excel file.

  • Select Worksheet: The first worksheet is selected using Worksheets[0].

  • Configure Image Options: The ImageOrPrintOptions object is used to specify PNG as the desired image format.

  • Render Images: The SheetRender class processes the worksheet into individual pages.

  • Save Images: Each page is saved as a separate PNG file using the ToImage method.

The code sample below explains how to convert XLSX to PNG in C#:

Get a Free License

You may request a free temporary license to test different image rendering features without any evaluation limitations.

Summing up

Converting Excel worksheets to image formats such as JPG and PNG offers numerous advantages in terms of accessibility, data security, and presentation. Using Conholdate.Total for .NET, the conversion process is simple, efficient, and produces high-quality images. By following the code snippets provided in this guide, you can seamlessly integrate this functionality into your .NET applications and unlock the full potential of your Excel data. Furthermore, if you want to discuss any of your queries, please feel free to reach out to us at the forum.

See Also