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.Pictures.Add(0, 0, “C:\logo_swire_eng.gif”);
Picture pic = excel.Worksheets.Pictures[picIndex];
Worksheet sheet = excel.Worksheets;
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 v220.127.116.11 before, and I downlaoded the latest verion v18.104.22.168 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.Pictures.Add(0, 0, “d:\logo_swire_eng.gif”);
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?