How to write text at specific position in Shape node using C#

Hi All,

I am using aspose dll license version

I am trying to write data in word document Box area

I have attached sample document
Sample1.zip (13.4 KB)

@pravinghadge

The box in your document is shape node. Please move the cursor to the desired location and insert the content. We suggest you please read the following articles.
Aspose.Words Document Object Model
Document Builder Overview
Navigation with Cursor

Following code example shows how to get the Shape node and move the cursor to the first paragraph of Shape node.

Document doc = new Document(MyDir + "Sample1.docx");
DocumentBuilder builder = new DocumentBuilder(doc); 
                
Shape shape = (Shape)doc.GetChild(NodeType.Shape, 0, true);

builder.MoveTo(shape.FirstParagraph);
builder.Write("New text");

doc.Save(MyDir + "20.5.docx");

I went through the content and link provided by you. I understood that this is realetd to shape and tried to follow the same. However, couldnt succeed. As I mentioned, the document already contains Shape box and within that it contains few Texts for name and Cnntact number.
Here, all I want to replace that name text with actual name and Contact number text with actual contact number.

Please do the needful.

Thanks,

@pravinghadge

Please manually create your expected Word document using Microsoft Word and attach it here for our reference. We will investigate how you want your final Word output be generated like. We will then provide you more information on this along with code.

Thanks for your reply.

Please find attached file. In this , i have shown you , what will be template & what is my expected output

Sample2.zip (15.2 KB)

Kindly suggest

@pravinghadge

You need to move the cursor to the paragraph nodes of Shape node and insert your desired content.

Please read these articles.

Following code example shows how to insert the text after Paragraph Node that is child node of Shape node.

Document doc = new Document(MyDir + "Sample1.docx");
DocumentBuilder builder = new DocumentBuilder(doc);

Shape shape = (Shape)doc.GetChild(NodeType.Shape, 0, true);
NodeCollection nodes =  shape.GetChildNodes(NodeType.Paragraph, true);
for (int i = 0; i < nodes.Count; i++)
{
    builder.MoveTo(nodes[i]);
    builder.Write(" This is new text after paragraph ");
}

doc.Save(MyDir + "20.5.docx");