C#-Read Image from Excel

In the last post, I show the method to write image in an Excel file. But, if I want to read image from one Excel file in a form via Spire.XLS, how should I do?

Firstly, we need to create a project as usual. I name it ReadImage.

Secondly, add references: Spire.XLS, System.Drawing, System.Windows.Forms (we need to show image in one form).

In this example, the image I will read is from another Excel file which I have in my computer, not the file I generate last time.

Then, use the following code.

using System.Drawing;
using System.Windows.Forms;
using Spire.Xls;

namespace ExcelSample
{
    class ReadImage
    {
        static void Main(string[] args)
        {
            Workbook workbook = new Workbook();
            workbook.LoadFromFile(@"..\..\..\..\..\..\Work\Image.xlsx");
            Worksheet sheet = workbook.Worksheets[0];

            ExcelPicture pic = sheet.Pictures[0];

            Form frm1 = new Form();
            PictureBox pic1 = new PictureBox();
            pic1.Image = pic.Picture;
            frm1.Width = pic.Picture.Width;
            frm1.Height = pic.Picture.Height;
            frm1.StartPosition = FormStartPosition.CenterParent;
            pic1.Dock = DockStyle.Fill;
            frm1.Controls.Add(pic1);
            frm1.ShowDialog();
        }
    }
}

After running, we can get the result as following:

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.

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