How to add/insert TextBox to Worksheet

Add Text Box to Worksheet in Excel

In the Excel program (version 07 and above), there are two places where you can insert text boxes.One in “insert-shapes”,the other is on the right side of the top menu of the “Insert” option.

method one:

1

method two:

2

How to create

You can create text boxes with horizontal or vertical text.

  • Select the corresponding option(horizontal or vertical)
  • Left click on the page
  • Hold down the left button and drag a distance on the page
  • Release the left button

Now you get a text box.

Add Text Box to Worksheet in Aspose.Cells

When you need to bulk insert TextBox into the worksheet, the manual insertion method is obviously a disaster.If this bothers you, I think this document will help you. Aspose.Cells provides you with an API to easily do bulk inserts in your code.

The following sample code creates a text box.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// The path to the documents directory.
String dataDir = "";
// Create directory if it is not already present.
File file = new File(dataDir);
if(!file.exists())
file.mkdir();
// 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.getWorksheets().get(0);
// Add the TextBox to the worksheet
sheet.getTextBoxes().add(6, 10, 100, 200);
//Save.You can check your text box in this way.
workbook.save("result.xlsx", SaveFormat.XLSX);

You will get a file similar to result file.In the file, you will see the following: