Insert a picture into a Excel file

code to add a picture to Excel Comment 

1   Range range = oWorkSheet.get_Range("A1",missing);
2   Excel.Comment comment = range.AddComment("");
3   comment.Shape.Fill.UserPicture("c:\\web.jpg"); 

insert a picture to a Excel file and Save it

1            System.Drawing.Image oImage = System.Drawing.Image.FromFile("c:\\web.jpg");
2            Clipboard.SetDataObject(oImage);
3            Range ImageRange = oWorkSheet.get_Range("A10",missing);
4            oWorkSheet.Paste(ImageRange,"c:\\web,jpg");

Comment: It only be used in the windows form application. If in the web application ,it occours a error like this:

The current thread must set to Single Thread Apartment (STA) mode before
OLE calls can be made. Ensure that your Main function has STAThreadAttribute
marked on it

who can tell me why and how to slove that problem?

posted on 2006-08-31 17:52  广思  阅读(434)  评论(0编辑  收藏  举报

导航