Blob Image to cell

I have a table which contains a Blob image. I’d like to export this table into a spreadsheet and have the image displayed in a cell.


How is this done? A regular ImportDataTable call just saves the images as its type (“System.Byte[]”)…see my simple code sample below.

This is SQL Server 2008 / .NET 4.0, btw.

var wb = new Aspose.Cells.Workbook();
wb.Worksheets.Add();

var data = ;
wb.Worksheets[0].Cells.ImportDataTable(data, true, 0, 0, true);

wb.Save(fileName);

Hi,


I don’t think so ImportDataTable provides any such facility of displaying blob data directly as image into a cell. However, you can convert byte data of blob into image and add it as a picture to your sheet manually as follow, with “data” as your byte data:

//Crearte Memory Stream Object
MemoryStream stream = new MemoryStream();

//Write data in memory
stream.Write(data, 0, data.Length);

//Create Image Object and load from stream
System.Drawing.Image infoImage = System.Drawing.Image.FromStream(stream);


//Insert a picture into a cell using a stream
sheet.Pictures.Add(1, 1, stream, 5, 5);


Thanks for the fast response.


This worked for me…
foreach (var dr in data.Rows)

{

	var bytes = (Byte[])data.Rows[i][4];

	var memStream = new MemoryStream();

	memStream.Write(bytes, 0, bytes.Length);
	wb.Worksheets[0].Pictures.Add(i, 0, i+1, 1, memStream);

        wb.Worksheets[0].Hyperlinks.Add(i, 1, 1, 1, "http://www.url.com");

	wb.CalculateFormula(true);


	i++;

}

Hi,

Thanks for sharing your solution.

It is good to know that your problem is now resolved.

If you face any other problem, please feel free to ask, we will help you asap.