//Creates a Word document.
WordDocument document = new WordDocument();
//Adds a section and paragraph in the document.
document.EnsureMinimal();
//Appends picture in the paragraph.
IWPicture picture = document.LastParagraph.AppendPicture(Image.FromFile("image.jpg"));
//Sets vertical origin as paragraph to enable move with text property.
picture.VerticalOrigin = VerticalOrigin.Paragraph;
//Sets wrapping style for picture.
picture.TextWrappingStyle = TextWrappingStyle.Square;
//Appends shape in the paragraph.
Shape shape = document.LastParagraph.AppendShape(AutoShapeType.Rectangle, 70, 50);
//Sets vertical origin as paragraph to enable move with text property.
shape.VerticalOrigin = VerticalOrigin.Paragraph;
//Sets wrapping style for shape.
shape.WrapFormat.TextWrappingStyle = TextWrappingStyle.Square;
//Appends textbox in the paragraph.
IWTextBox textBox = document.LastParagraph.AppendTextBox(70, 50);
//Sets vertical origin as paragraph to enable move with text property.
textBox.TextBoxFormat.VerticalOrigin = VerticalOrigin.Paragraph;
//Sets wrapping style for textbox.
textBox.TextBoxFormat.TextWrappingStyle = TextWrappingStyle.Square;
//Saves the Word document.
document.Save("Sample.docx");
//Closes the Word document.
document.Close(); |
WordDocument document = new WordDocument(@"../../Data/Input.docx");
WParagraph paragraph = new WParagraph(document);
IWPicture pic = paragraph.AppendPicture(Image.FromFile(@"../../Data/input.jpg"));
pic.VerticalOrigin = VerticalOrigin.Paragraph;
pic.TextWrappingStyle = TextWrappingStyle.Square;
TextBodyPart bodyPart = new TextBodyPart(document);
bodyPart.BodyItems.Add(paragraph);
//Replaces a particular text with the text body part
document.Replace("Replace", bodyPart, false, true, true);
document.Save(@"Output.docx", FormatType.Docx); |