ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Insert image into cell using C# and Excel interop?? (https://www.excelbanter.com/excel-programming/378979-insert-image-into-cell-using-c-excel-interop.html)

Michael Howes

Insert image into cell using C# and Excel interop??
 
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(oImag e,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.Applica tion.ExecutablePath) +
Path.DirectorySeparatorChar + "Logo.gif",
ref oFalse, ref oTrue, ref oMissing);

thanks
mike


All times are GMT +1. The time now is 03:36 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com