C# – Convert Excel to Image

In order to share data with others, we can save data in Excel and send it to other via E-mail. Sometimes, people may not send the Excel file, but convert it to other format, for example, image.

If we convert Excel to image, the data cannot be formatted and modified directly. Also, we can insert image in blog posts or articles for showing data more intuitively. In this post, I will show the method to convert Excel to image with C# via Spire.XLS.

Firstly, download and install Spire.XLS on your computer.

Secondly, add Spire.XLS DLL file as reference after creating a new project.

Thirdly, load Excel file which we would like to convert to image. In this example, I choose the file about student information.

Fourthly, initialize worksheet. Then, save Excel to image by using sheet.SaveToImage(); I save the format as jpg. Also, we can set the image as other format, such as bmp or gif.

Finally, launch this converted image.

Using the Code:

using System;

using Spire.Xls;

 

namespace ExceltoImage

{

    class toimage

    {

        static void Main(string[] args)

        {

            Workbook workbook = new Workbook();

             //Load File

             workbook.LoadFromFile(@"D:\work\My Documents\Student Info.xlsx",ExcelVersion.Version2010);

             //Initialize Worksheet

            Worksheet sheet = workbook.Worksheets[0];

            //Save and Launch Image

            sheet.SaveToImage("Stinfo.jpg");

            System.Diagnostics.Process.Start("Stinfor.jpg");

        }

    }

}

After running, we can the image as following:

——–

Click Here to Learn More about Spire.XLS
Click Here to Download Spire.XLS

Advertisements

Author: janewdaisy

.NET Program Beginner. Share methods about how to use C#/VB.NET to export data, operate Word, Excel, PDF and other useful skills.

6 thoughts on “C# – Convert Excel to Image”

    1. I’m sorry, I don’t know how to do to meet your requirement. And my method just can convert data in one specified worksheet to image. If I find a method to meet your requirement. I will share it in my blog. Thanks very much.

  1. You’re so cool! I don’t think I’ve read anything like that before. So great to discover someone with a few original thoughts on this subject. Seriously.. many thanks for starting this up. This website is something that is required on the internet, someone with some originality!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s