Hi,
I got the following code that adds border to shape (textbox) only if I directly add textbox to word document, but I am adding shape to table cell, then it is not displaying shape textbox in that table cell. What am I doing wrong?
Shape textBox = new Shape(doc, ShapeType.TextBox);
textBox.Width = 200;
textBox.Height = 150;
textBox.Stroke.LineStyle = ShapeLineStyle.Single;
textBox.Stroke.Weight = 6;
textBox.Stroke.Color = Color.Black;
// Create Paragraph and run
Paragraph cell2Paragraph = new Paragraph(doc);
cell2Paragraph.AppendChild(new Run(doc, "Data"));
// Insert Paragraph into the TextBox
textBox.AppendChild(cell2Paragraph);
Cell dataCell = new Cell(doc);
dataCell.AppendChild(cell2Paragraph);
row.AppendChild(dataCell);
Row is of type TableRow. When I generate word document with the above code, it’s not generating textbox with borderv
Thanks for your inquiry. You should specify the TextBox.FitShapeToText property to true so that Microsoft Word will grow the shape to fit text as follows:
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Shape textBox = new Shape(doc, ShapeType.TextBox);
// You must have to specify the width
textBox.Width = 200;
textBox.TextBox.FitShapeToText = true;
Paragraph para = new Paragraph(doc);
para.Runs.Add(new Run(doc, "Long text goes here Long text goes here Long text goes here Long text goes here Long text goes here Long text goes here ..."));
textBox.AppendChild(para);
doc.FirstSection.Body.FirstParagraph.AppendChild(textBox);
doc.Save(@"C:\Temp\out.docx");
I hope, this helps.
Best Regards,
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
Enables storage, such as cookies, related to analytics.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.