Text Box has been widely used in word documents to present additional information to readers. As a powerful and easy to use .NET word component, Spire.Doc has powerful function to work with text box. We have already showed you how to insert text box to word document and extract Text from Text Boxes in Word document. In this article let's see how to remove text box from word document in C#.
Spire.Doc supports to remove the particular text box or clear all the text boxes from the word documents. We will show you the details as below. Firstly, check the original word document contains three text boxes on it.
Here comes to the steps of how to remove the text box from word document by using the class of TextBoxes.
Step 1: Create a new document and load from file.
Document Doc = new Document(); Doc.LoadFromFile("Sample.docx");
Step 2: Remove the first text box by using the class of TextBoxes.
Doc.TextBoxes.RemoveAt(0);
Step 3: Save and launch the file.
Doc.SaveToFile("result.docx", FileFormat.Docx); System.Diagnostics.Process.Start("result.docx");
Effective screenshot:
If you want to clear all the text boxes at one time, the following code snippet will fulfill it.
Screenshot after clear all the text boxes:
Doc.TextBoxes.Clear();
Full codes:
namespace Removetextbox { class Program { static void Main(string[] args) { Document Doc = new Document(); Doc.LoadFromFile("Sample.docx"); Doc.TextBoxes.RemoveAt(0); //Doc.TextBoxes.Clear(); Doc.SaveToFile("result.docx", FileFormat.Docx); System.Diagnostics.Process.Start("result.docx"); } } }