I have a requirement that i need to copy data from one excel sheet to another sheet. For example "Sheet1" contains some data (images, comments etc). I have image and few cells in "Sheet2".
Now, i want to copy contents of "Sheet2" at the end of contents of "Sheet1". I was able to copy entire sheet including images but i am not able to position the image in the destination sheet.
To be more clear, on "Sheet2", the image is located at Row Number : 7. On "Sheet1", i want the image to be placed at Row Number: 30.
I have tried modifing "RowId.Text" value but the output is getting opened with Errors on Drawing part.
Can anyone help me on this ?
Thanks and Regards,
Thanks for posting in the MSDN Forum.
This image have been stored in DrawingsPart in each WorksheetPart and the postition has been defined in WorksheetDrawing element of the DrawingsPart.
I hope it can help you.
Have a good day,
Tom Xu [MSFT]
MSDN Community Support | Feedback to us
Thanks for your reply.
I cloned the child elements of Source Worksheet Drawings and tried to append to destination worksheet drawing. In the end, i found that the image which is already present in the destination sheet keeps on pasting again and again.
Can you help me overcome this problem?
I am posting a sample code for your reference.
private void CopyImageFromRange(WorksheetPart srcWorkSheetPart, WorksheetPart destWorkSheetPart, int nImageOffset)
if (null != destWorkSheetPart.DrawingsPart.WorksheetDrawing)
if (null != srcWorkSheetPart.DrawingsPart.WorksheetDrawing)
foreach (OneCellAnchor Item in srcWorkSheetPart.DrawingsPart.WorksheetDrawing.Descendants<OneCellAnchor>().ToList())
OneCellAnchor anchor = (OneCellAnchor)Item.Clone();
anchor.FromMarker.RowId.Text = (Convert.ToInt16(anchor.FromMarker.RowId.Text) + nImageOffset).ToString();
Thanks and Regards,
I solved it myself and thought of posting it to forum so that anyone facing the same problem can be benefited.
I followed the following steps:
1. Iterate through all the Image parts (present under Drawing Part) of source worksheet and add them to destination worksheet Drawing part.
2. Now get the "WorksheetDrawing" of Source Worksheet DrawingPart and add get the Child elements. Add them to Destination Worksheets drawing part.
3. While adding to "WorksheetDrawing" of Destination worksheet drawing, assign a parameter (Picture.BlipFill.Blip.Embed) to the newly added Image part's rID.
I can share the code also in case anyone needs...
Thanks and Regards
- 已标记为答案 Kishor Reddy 2012年5月3日 17:26
hello Kishor Reddy excuse me wonder if you still have the code to copy image from one sheet to another...