Ungroup shape in word file in c#
-
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; :(
Pankaj
-
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; :(
Pankaj
Got the solution I have used following code before ungrouping the shape System.Threading.Thread.Sleep(1000); Actually when 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 renders the shape in proper place.
Pankaj
-
Got the solution I have used following code before ungrouping the shape System.Threading.Thread.Sleep(1000); Actually when 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 renders the shape in proper place.
Pankaj
ha ha ... I think the process takes some time to ungroup. So sleeping the Thread cures the problem. :laugh:
Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.
My Latest Articles-->** Simplify Code Using NDepend
Basics of Bing Search API using .NET
Microsoft Bing MAP using Javascript -
ha ha ... I think the process takes some time to ungroup. So sleeping the Thread cures the problem. :laugh:
Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.
My Latest Articles-->** Simplify Code Using NDepend
Basics of Bing Search API using .NET
Microsoft Bing MAP using JavascriptMay be you are right. I have also posted the code for ungrouping. But there are no problem in ungrouping. Do you have any solution without using threading ? ;)
Pankaj