Insert Textbox with Contents in Excel in C#, VB.NET

Textbox in Excel is an independent part, which allows users to add and format text in it. It can be quote or abstract about contents in file so that it is often created as sidebar to call readers’ attention.

Spire.XLS for .NET, a professional component to manipulate Excel file in .NET applications, enables users to insert textbox in Excel and add contents in it by using C#, VB.NET.

With Spire.XLS for .NET, users can invoke sheet.TextBoxes.AddTextBox(int row, int column, int height, int width) method directly to add textbox. Then, add contents through setting Text property of ITextBox class. Also, users can set alignment with setting HAlignment and VAlignment property. After coding, you can get the result like this:

Download and install Spire.XLS for .NET and use the following code to insert textbox in Excel.

   ITextBox textBox = sheet.TextBoxes.AddTextBox(5, 3, 128, 196);
            textBox.Text = "Insert TextBox in Excel";
            textBox.HAlignment = CommentHAlignType.Center;
            textBox.VAlignment = CommentVAlignType.Center;
         Dim textBox As ITextBox = sheet.TextBoxes.AddTextBox(5, 3, 128, 196)
            textBox.Text = "Insert TextBox in Excel"
            textBox.HAlignment = CommentHAlignType.Center
            textBox.VAlignment = CommentVAlignType.Center