Hi Derek,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
You can create or edit an existing textbox in document by using the code similar to below.
Document doc = new Document(dataDir + "Test Document.doc");
bool hasTextBox = false;
Shape textBox = null;
// Try to find existing textbox
NodeCollection nodes = doc.GetChildNodes(NodeType.Shape, true);
foreach (Shape node in nodes)
{
if (node.ShapeType == ShapeType.TextBox)
{
hasTextBox = true;
textBox = node;
}
}
// Create a new textbox if no textbox already exists
if (!hasTextBox)
{
textBox = new Shape(doc, ShapeType.TextBox);
// Set Textbox size
textBox.Width = 100;
textBox.Height = 100;
// Insert one empty paragraph into the textbox.
Paragraph par = new Paragraph(doc);
par.AppendChild(new Run(doc));
textBox.AppendChild(par);
// Insert textbox into the document.
doc.FirstSection.Body.FirstParagraph.AppendChild(textBox);
}
// Change text in textbox
textBox.FirstParagraph.Runs[0].Text = "Text Inserted";
doc.Save(dataDir + "Test Document Out.doc");
If you need any futher help please ask.
Thanks,