Insert TextBox into Excel via .NET
Insert TextBox using Aspose.Cells’ API without any software like Microsoft or Open Office, Adobe PDF, etc.
How to Insert TextBox into Excel File Using C#
In order to insert TextBox into excel file, we’ll use
API which is a feature-rich, powerful and easy to use document manipulation and splitter API for C# platform. Open
package manager, search for Aspose.Cells and install. You may also use the following command from the Package Manager Console.
Command
PM> Install-Package Aspose.Cells
Steps to insert TextBox to Excel file via C#
You need the aspose.cells.dll to try the following workflow in your own environment.
- Instantiating a Workbook object.(or->Load the XLSX file with full path.)
- Select Worksheet via its index.
- Use the add method to insert a TextBox in the selected worksheet
- Save workbook in XLSX format.
System Requirements
Aspose.Cells for .NET is supported on all major operating systems. Just make sure that you have the following prerequisites.
- Microsoft Windows or a compatible OS with .NET Framework, .NET Core, Mono or Xamarin Platforms
- Development environment like Microsoft Visual Studio
- Add reference to the Aspose.Cells for .NET DLL in your project - Install from NuGet using the Download button above
Insert TextBox - C#
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = ""; | |
if (!System.IO.Directory.Exists(dataDir)) | |
{ | |
System.IO.Directory.CreateDirectory(dataDir); | |
} | |
// Open an Excel file. | |
//Workbook workbook = new Workbook(dataDir+ "Book_SourceData.xlsx");//If you want to insert a text box in an existing file, use this code. | |
// Create an object of the Workbook class | |
Workbook workbook = new Workbook(); | |
// Access first worksheet from the collection | |
Worksheet sheet = workbook.Worksheets[0]; | |
// Add the TextBox to the worksheet | |
sheet.TextBoxes.Add(6, 10, 100, 200); | |
//Save.You can check your text box in this way. | |
workbook.Save("result.xlsx", SaveFormat.Xlsx); |