Skip to content

Ungroup shape in word file in c#

Pankaj Saha

Asked Nov 23, 2009, 4:04 AM EST1 answer
Share
LinkedInX
Hi, I have a word file which contains numbers of shapes. Each shape contain some textboxes. I am copying that file to another location and assigning some values to those textboxes of those shapes. Now I have to assign the values to those textboxes then I have to ungroup those shape first then only I can assign values those text boxes. Now the problem is that when I ungroup those shapes, they change their locations in the document. I do not understand what is the problem. Here is the code //copy the sourc file to another location System.IO.File.Copy(Convert.ToString(source), Convert.ToString(destination)); Microsoft.Office.Interop.Word.Document obDoc = new Microsoft.Office.Interop.Word.Document(); object unknown = Type.Missing; object format = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatDocumentDefault; obDoc = varWord.Documents.Add(ref source, ref unknown, ref unknown, ref visible); obDoc.Activate(); //hiding a shape--working fine obj = "shape1"; varWord.ActiveDocument.Shapes.get_Item(ref obj).Select(ref unknown); varWord.ActiveDocument.Shapes.get_Item(ref obj).Visible = MsoTriState.msoFalse; //ungroup the shape obj = "Shape2"; varWord.ActiveDocument.Shapes.get_Item(ref obj).Select(ref unknown); varWord.ActiveDocument.Shapes.get_Item(ref obj).Ungroup(); obj = "txtbox1"; varWord.ActiveDocument.Shapes.get_Item(ref obj).Select(ref unknown); varWord.Selection.TypeText(txtbox1value); //show the word file varWord.Visible = true; varWord = null; :(

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    Got the solution I have used following code before ungrouping the shape System.Threading.Thread.Sleep(1000); Actually when out c# code run its ungroup the shape first, then render the file, that's why shape is showing in the header of the page, not in the proper position. Now using the sleep method it render the shape in proper place.
    0