How to insert image from database into a cell

I have an image (logo) stored in my database that I would like to insert into a cell in the worksheet that I am creating. How do I go about doing this?

My code results in "ExportImage" in cell H18 and "System.Byte[]" in cell H19.

The code:

SqlDataAdapter adapter = new SqlDataAdapter("Select ExportImage From Organization Where ID = @OrgID", con);

adapter.SelectCommand.Parameters.AddWithValue("@OrgID", Int32.Parse(Session["currentOrganizationID"].ToString()));

DataTable dt = new DataTable();

adapter.Fill(dt);

//Import the datatable to sheet cell

wsCover.Cells.ImportDataTable(dt, true, "H18");

Thanks

Jim

Hi,

Thanks for your posting and using Aspose.Cells for .NET.

Please download and use the latest version:
Aspose.Cells
for .NET v7.1.2.
6

Aspose.Cells for .NET will allow you to add images/pictures in your worksheet.

Please refer to this article for your more help.

Adding Pictures

Hi,

As I said in my original post, my images reside within a database - NOT in a file.
Is there a technique available to accomplish inserting such images into a worksheet?

Thanks

Jim

Hi,

Yes, you can use worksheet.Pictures.Add() overload that takes stream not file path.

Here are the steps you will follow.

1 - Get the image in the form of bytes from your database.
2 - Create a memory stream object from the image bytes.
3 - Pass the memory stream object as a parameter worksheet.Pictures.Add() method.

Let me know if you need more help.