Click here to Skip to main content
15,900,907 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
How can I past an image in Cell[5,3] of an excel worksheet by C#?

Please Do NOT express your opinion if you have not enough knowledge about it or you are not sure about that.
Please Do NOT send any other link searched by google, because there are a lot of non working example on the Internet.
Thx.
Posted
Updated 23-Jun-10 6:11am
v3
Comments
saurabhdsadasdasd 5-Jul-12 2:05am    
Microsoft.Office.Interop.Excel.Range picPosition = excelSheet.Cells[i, j]; // retrieve the range for picture insert
Microsoft.Office.Interop.Excel.Pictures p = excelSheet.Pictures(System.Reflection.Missing.Value) as Microsoft.Office.Interop.Excel.Pictures;

Microsoft.Office.Interop.Excel.Picture pic= p.Insert(FilePath, missing);
pic.Left = Convert.ToDouble(picPosition.Left);
pic.Top = picPosition.Top;
pic.Placement = Microsoft.Office.Interop.Excel.XlPlacement.xlMoveAndSize;

1 solution

:thumbsup:
I could solve it:
Excel.Range oRange = (Excel.Range)xlWorkSheet1.Cells[Row, 1];
float Left =(float) ((double)oRange.Left);
float Top =(float) ((double)oRange.Top);
const float ImageSize=32;
xlWorkSheet1.Shapes.AddPicture(imagString, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoCTrue, Left, Top, ImageSize, ImageSize);
oRange.RowHeight = ImageSize + 2;
 
Share this answer
 
Comments
dhanildas 24-Oct-11 3:28am    
Got error, plz help me Error 4 The type 'Microsoft.Office.Core.MsoTriState' is defined in an assembly that is not referenced. You must add a reference to assembly 'Office, Version=7.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. Am using VS 2010, have refrenced Excel.dll file
Beauty Keshri Shah 27-Jul-12 3:34am    
thanks aasser... for the code.. it helps me a lot...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900