Click here to Skip to main content
11,479,170 members (54,479 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C# XML Excel .NET4 , +
Hi All,

I have a requirement in my project to add multiple images on the fly. The images are dynamically obtained from another source (the image path is obtained) and i need to paste them at a particular location on the excel sheet.

I am able to add single image successfully to spreadsheet (with OR without comments) but when i try to add one more image the excel was not opening. I am using "two anchor cell" method for adding the image.

Can anyone post a sample code ?

Thanks and Regards,

YKK Reddy
Posted 13-Feb-12 0:58am
YKK Reddy1.6K

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

I have solved it myself. I am posting it here just in case anyone else needs.
I modified the code for the "Drawing" class. The below code is mentioned:
if (imageNumber == 1)            
Drawing drawing = new Drawing() { Id = "rId" + drawingPartId.ToString() };                
//Check whether the WorksheetPart contains VmlDrawingParts (LegacyDrawing element)                
if (sheet1.VmlDrawingParts == null)                
//if there is no VMLDrawing part (LegacyDrawing element) exists, just append the drawing part to the sheet                    sheet1.Worksheet.Append(drawing);                
//if VmlDrawingPart (LegacyDrawing element) exists, then find the index of legacy drawing in the sheet and inserts the new drawing element before VMLDrawing part                    
int legacyDrawingIndex = GetIndexofLegacyDrawing(sheet1);                    
if (legacyDrawingIndex != -1)                        sheet1.Worksheet.InsertAt<OpenXmlElement>(drawing, legacyDrawingIndex);                    

The complete set of code is available at ""
In the code available in above link we need to just modify the "Drawing" part

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 215
1 OriginalGriff 205
2 F-ES Sitecore 185
3 Frankie-C 120
4 DamithSL 85
0 Sergey Alexandrovich Kryukov 7,890
1 OriginalGriff 7,441
2 Sascha Lefèvre 3,064
3 Maciej Los 2,491
4 Richard Deeming 2,335

Advertise | Privacy | Mobile
Web01 | 2.8.150520.1 | Last Updated 13 Feb 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100