Knowledgebase (2311)
Children categories
In Word 2013 and later version, you can reply to a comment, so it's easier to follow the whole conversation. Spire.Doc also allows programmers to insert a comment as a reply to a selected comment through ReplyToComment method.
Step 1: Create an object of Document and load a Word document containing comments.
Document doc = new Document();
doc.LoadFromFile("Comment.docx");
Step 2: Get the first comment.
Comment comment = doc.Comments[0];
Step 3: Create a new comment and specify the author and content.
Comment replyComment = new Comment(doc);
replyComment.Format.Author = "Adam";
replyComment.Body.AddParagraph().AppendText("Exactly.");
Step 4: Add the new comment as a reply to the selected comment.
comment.ReplyToComment(replyComment);
Step 5: Save to file.
doc.SaveToFile("ReplyToComment.docx", FileFormat.Docx2013);

Full Code:
using Spire.Doc;
using Spire.Doc.Fields;
namespace ReplyComment
{
class Program
{
static void Main(string[] args)
{
Document doc = new Document();
doc.LoadFromFile("Comment.docx");
Comment comment = doc.Comments[0];
Comment replyComment = new Comment(doc);
replyComment.Format.Author = "Adam";
replyComment.Body.AddParagraph().AppendText("Exactly.");
comment.ReplyToComment(replyComment);
doc.SaveToFile("ReplyToComment.docx", FileFormat.Docx2013);
}
}
}
Imports Spire.Doc
Imports Spire.Doc.Fields
Namespace ReplyComment
Class Program
Private Shared Sub Main(args As String())
Dim doc As New Document()
doc.LoadFromFile("Comment.docx")
Dim comment As Comment = doc.Comments(0)
Dim replyComment As New Comment(doc)
replyComment.Format.Author = "Adam"
replyComment.Body.AddParagraph().AppendText("Exactly.")
comment.ReplyToComment(replyComment)
doc.SaveToFile("ReplyToComment.docx", FileFormat.Docx2013)
End Sub
End Class
End Namespace
When coping content from the Internet into a Word document, you may find that there are a lot of blank lines between paragraphs, which will not only make the document look lengthier but also affect the readability. In this article, you will learn how to programmatically remove empty lines/blank paragraphs in an existing Word document using Spire.Doc for .NET.
Install Spire.Doc for .NET
To begin with, you need to add the DLL files included in the Spire.Doc for .NET package as references in your .NET project. The DLL files can be either downloaded from this link or installed via NuGet.
PM> Install-Package Spire.Doc
Remove Empty Lines in an Existing Word Document
The detailed steps are as follows:
- Create a Document instance.
- Load a sample Word document using Document.LoadFromFile() method.
- Loop through all paragraphs in the document and determine whether the paragraph is a blank paragraph.
- Remove blank paragraphs from the document using DocumentObjectCollection.Remove() method.
- Save the document to another file using Document.SaveToFile() method.
- C#
- VB.NET
using Spire.Doc;
using Spire.Doc.Documents;
using System;
namespace RemoveEmptyLines
{
class Program
{
static void Main(string[] args)
{
//Create a Document instance
Document doc = new Document();
//Load a sample Word document
doc.LoadFromFile(@"D:\Files\input.docx");
//Loop through all paragraphs in the document
foreach (Section section in doc.Sections)
{
for (int i = 0; i < section.Body.ChildObjects.Count; i++)
{
if (section.Body.ChildObjects[i].DocumentObjectType == DocumentObjectType.Paragraph)
{
//Determine if the paragraph is a blank paragraph
if (String.IsNullOrEmpty((section.Body.ChildObjects[i] as Paragraph).Text.Trim()))
{
//Remove blank paragraphs
section.Body.ChildObjects.Remove(section.Body.ChildObjects[i]);
i--;
}
}
}
}
//Save the document
doc.SaveToFile("RemoveEmptyLines.docx", FileFormat.Docx2013);
}
}
}

Apply for a Temporary License
If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.
Spire.Doc supports to insert a picture to text box as a background image or as a part of body content. This article demonstrates how to achieve these purposes through following code snippets.
Part 1. Insert Background Image to Text Box
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
using System.Drawing;
namespace InsertTextBox
{
class Program
{
static void Main(string[] args)
{
//Create a Word document
Document doc = new Document();
Section section = doc.AddSection();
Paragraph paragraph = section.AddParagraph();
//Append a Textbox to paragraph
TextBox tb = paragraph.AppendTextBox(120, 200);
//Set the position of Textbox
tb.Format.HorizontalOrigin = HorizontalOrigin.Page;
tb.Format.HorizontalPosition = 50;
tb.Format.VerticalOrigin = VerticalOrigin.Page;
tb.Format.VerticalPosition = 50;
//Set the fill effect of Textbox as picture
tb.Format.FillEfects.Type = BackgroundType.Picture;
//Fill the Textbox with a picture
tb.Format.FillEfects.Picture = Image.FromFile("Background.jpg");
//Save to file
doc.SaveToFile("InsertBackgroundImage.docx", FileFormat.Docx2013);
}
}
}
Output:

Part 2. Insert Image to Body of Text Box
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
using System.Drawing;
namespace InsertTextBox
{
class Program
{
static void Main(string[] args)
{
//Create a Word document
Document doc = new Document();
Section section = doc.AddSection();
Paragraph paragraph = section.AddParagraph();
//Append a Textbox to paragraph
TextBox tb = paragraph.AppendTextBox(140, 250);
//Set the position of Textbox
tb.Format.HorizontalOrigin = HorizontalOrigin.Page;
tb.Format.HorizontalPosition = 50;
tb.Format.VerticalOrigin = VerticalOrigin.Page;
tb.Format.VerticalPosition = 50;
//Insert an image to body of Textbox
Paragraph para1 = tb.Body.AddParagraph();
Image image = Image.FromFile("Shakespeare.jpg");
DocPicture picture = para1.AppendPicture(image);
para1.Format.AfterSpacing = 8;
para1.Format.HorizontalAlignment = HorizontalAlignment.Center;
//Insert text to body of Textbox
Paragraph para2 = tb.Body.AddParagraph();
TextRange textRange = para2.AppendText("(26 Apr.1564–§C23 Apr.1616) English poet, playwright, and actor, widely regarded as the greatest writer in the English language and the world's pre-eminent dramatist.");
textRange.CharacterFormat.FontName = "Cambria";
textRange.CharacterFormat.FontSize = 9;
para2.Format.LineSpacing = 15;
para2.Format.HorizontalAlignment = HorizontalAlignment.Left;
para2.Format.SuppressAutoHyphens = true;
//Save to file
doc.SaveToFile("InsertToBody.docx", FileFormat.Docx2013);
}
}
}
Output:
