//Loads an existing Word document WordDocument document = new WordDocument(@"D:\Temp\Input.docx"); //Get the paragraph where you need to find the text WParagraph paragraph = document.LastSection.Paragraphs[0]; //Find the text in document TextSelection[] textSelections = document.FindAll("DocIO", false, false); for (int i = 0; i < textSelections.Length; i++) { WTextRange foundTextRange = textSelections[i].GetAsOneRange(); //Check found text is from the expected paragraph if(foundTextRange.OwnerParagraph == paragraph) { //Here, do the necessary formatting for found text //Sets the highlight color for the searched text as Yellow. foundTextRange.CharacterFormat.HighlightColor = System.Drawing.Color.Yellow; } } //Saves and closes the Word document document.Save("Sample.docx"); document.Close(); |
WordDocument document = new WordDocument();
document.EnsureMinimal(); IWPicture picture= document.LastParagraph.AppendPicture(Image.FromFile(@"download.png")); picture.CharacterFormat.Border.LineWidth = 2; document.Save("Image.docx"); Process.Start("Image.docx"); |