Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Ungroup shape in word file in c#

Ungroup shape in word file in c#

Scheduled Pinned Locked Moved C#
csharpcomhelpquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Pankaj Saha
    wrote on last edited by
    #1

    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

    P 1 Reply Last reply
    0
    • P Pankaj Saha

      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

      P Offline
      P Offline
      Pankaj Saha
      wrote on last edited by
      #2

      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

      A 1 Reply Last reply
      0
      • P Pankaj Saha

        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

        A Offline
        A Offline
        Abhishek Sur
        wrote on last edited by
        #3

        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

        P 1 Reply Last reply
        0
        • A Abhishek Sur

          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

          P Offline
          P Offline
          Pankaj Saha
          wrote on last edited by
          #4

          May 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

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups