Articles in this section
Category / Section

How to convert Excel sheets to images in ASP.NET Core XIsIO?

4 mins read

Syncfusion Excel (XlsIO) library is a .NET Excel library used to create, read, and edit Excel documents. Also, converts Excel documents to PDF files.

In this article, we will explore how to convert Excel sheets to images and saving them as a GIF.

Steps for converting Excel sheets to images and saving them as a GIF programmatically:

Step 1: Create a new C# console application.

Console_application.png

Step 2: Install the Syncfusion.XlsIORenderer.Net.Core, Magick.NET-Q8-AnyCPU NuGet package as reference to your .NET Core application from NuGet.org.

Syncfusion.XlsIO.Net.Core.png

Magick.NET-Q8-AnyCPU.png

Step 3: Include the following namespaces in Program.cs file.

C#

using ImageMagick;
using Syncfusion.XlsIO;
using Syncfusion.XlsIORenderer; 

Step 4: Include the following code snippet to convert Excel sheets to images and save them as a GIF.
C#

using (ExcelEngine excelEngine = new ExcelEngine())
{
   IApplication application = excelEngine.Excel;
   application.DefaultVersion = ExcelVersion.Xlsx;
   
   //Load an input template
   using(FileStream file = new FileStream("../../../Data/InputTemplate.xlsx", FileMode.Open, FileAccess.Read))
   {
       IWorkbook workbook = application.Workbooks.Open(file);

       using (MagickImageCollection collection = new MagickImageCollection())
       {
           for (int i = 0; i < workbook.Worksheets.Count; i++)
           {
               IWorksheet worksheet = workbook.Worksheets[i];

               //Initialize XlsIORenderer
               application.XlsIORenderer = new XlsIORenderer();

               //Create a memory stream to save the image
               using (MemoryStream stream = new MemoryStream())
               {
                   //Convert worksheet to image and save it to stream
                   worksheet.ConvertToImage(1, 1, 27, 12, stream);

                   //Set stream postition
                   stream.Position = 0;

                   //Load the image into MagickImage
                   MagickImage image = new MagickImage(stream);

                   //Add the image to the collection
                   collection.Add(image);
               }
           }

           //Set the delay between frames (100 = 1 second)
           foreach (MagickImage image in collection)
           {
               image.AnimationDelay = 100;
           }

           //Create an animated GIF
           collection.Write(@"..\..\..\Output\animated.gif");
       }
   }
} 

Download a complete working sample demonstrating how to convert Excel sheets to images and save them as a GIF using C# from here.

By executing the program, you will get the output GIF file as shown below.

Output.gif

Take a moment to peruse the documentation, where you can find basic worksheet data manipulation options along with features like Conditional Formatting, worksheet calculations through Formulas, adding Charts in worksheets or workbooks, organizing and analyzing data through Tables and Pivot Tables, appending multiple records to a worksheet using Template Markers, and most importantly PDF and Image conversions with code examples.

Refer here to explore the rich set of Syncfusion Excel (XlsIO) library features.

Starting with v16.2.0.x, if you reference Syncfusion assemblies from the trial setup or the NuGet feed, include a license key in your projects. Refer to the link to learn about generating and registering the Syncfusion license key in your application to use the components without a trial message.

Conclusion

I hope you enjoyed learning about how to convert Excel sheets to images in ASP.NET Core XIsIO.

You can refer to our ASP.NET Core XIsIO feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our ASP.NET Core XIsIO example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied