Ungroup shape in word file in c#

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pankajprakash
    New Member
    • Feb 2007
    • 70

    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
    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;
    :(
    Last edited by Frinavale; Nov 23 '09, 04:39 PM. Reason: Please post code in [code] ... [/code] tags. Added code tags.
  • pankajprakash
    New Member
    • Feb 2007
    • 70

    #2
    Got the solution

    I have used following code before ungrouping the shape

    System.Threadin g.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.

    Comment

    Working...