Add Picture


Hi Laurence,

I tried to add a picture into the excel file, although the application did not give any error, the file was blank and without any picture. I have tried both of the following code to implement:

int picIndex = excel.Worksheets[0].Pictures.Add(0, 0, “C:\logo_swire_eng.gif”);
Picture pic = excel.Worksheets[0].Pictures[picIndex];

Worksheet sheet = excel.Worksheets[0];
FileStream fs = new FileStream(“c:\logo_swire_eng.gif”, FileMode.Open, FileAccess.Read);
int pos = sheet.Pictures.Add(0, 0, fs);
Picture pic = sheet.Pictures[pos];

I cannot figure out why they did not work, could you give me any suggestion about this?

Thanks and Regards,



Which version are you using? Could you please post your image file here?


I was using v3.3.3.0 before, and I downlaoded the latest verion v3.4.0.0 to see whether it work or not, both of the versions did not work.

Attached is the gif file that I tried before.


I don’t find the problem. Do you use Excel97 to open your generated file? If yes, please try the following sample code:

Excel excel = new Excel();
excel.Worksheets[0].Pictures.Add(0, 0, “d:\logo_swire_eng.gif”);
excel.Save(“d:\book1.xls”, FileFormatType.Excel97);


I tried the code you provided and using office 2003, the size of the excel file is 75kb, it seems that the picture was inserted into the file, but I cannot see any picture when I open the excel file. Do you have any idea about this?



I also cannot see the pictures in your file. But it works fine in my machine.
The attached file is created with my sample code. It’s only 6KB.

Does your code and image file is exactly same as mine?