Insert image into cell using C# and Excel interop??

M

Michael Howes

I'm trying to insert a bitmap from the harddrive into a cell of a
worksheet and can't seem to find anything in MSDN or on the net.

I'm creating Excel (version 2003/11) from within a C# application
ExcelApp = new Microsoft.Office.Interop.Excel.Application();

I recorded a macro and inserted a jpg into a cell and the code
that Excel generated was the following

Range("F20").Select
ActiveSheet.Pictures.Insert("C:\Logo transparent.gif").Select

In my C#/Winforms application I have code that looks like this

currentSheet = (Excel.Worksheet)ExcelApp.Workbooks[0].Sheets[0];
Excel.Range range = currentSheet.get_Range("A1", "A1");
range.Select();

currentSheet.Pictures does not have any methods?
I've looked at the range object and the WorkSheet object and haven't
figured out how to insert a bitmap from a file

I've seen code that uses the clipboard like this
Image oImage = Image.FromFile(_stLOGO);
System.Windows.Forms.Clipboard.SetDataObject(oImage,true);
ThisSheet.Paste(oRange,_stLOGO);

do I have to use the clipboard

I did the same in Word with one line of code
WordApp.Selection.InlineShapes.AddPicture(
Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath) +
Path.DirectorySeparatorChar + "Logo.gif",
ref oFalse, ref oTrue, ref oMissing);

thanks
mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top