Insert Textbox to Excel Worksheet Using Java

Text box allows people to enter text in it and move it arbitrarily. It can be used in some areas that need to be emphasized or highlighted. This article will demonstrate how to add textbox into Excel worksheet with Free Spire.XLS for Java. We could fill in the textbox with text and image.

Installation (2 Method)
1# Download the free library and unzip it, then add the Spire.Xls.jar file to your project as dependency.

2# You can also add the jar dependency to maven project by adding the following configurations to the pom.xml.


Sample Code

import com.spire.xls.*;
import com.spire.xls.core.ITextBox;
import com.spire.xls.core.ITextBoxShape;

public class ExcelTextbox {
public static void main(String[] args) throws Exception {

//Create a workbook
Workbook workbook = new Workbook();

//Get the first sheet
Worksheet sheet = workbook.getWorksheets().get(0);

//Insert the textbox with text
ITextBox textBox = sheet.getTextBoxes().addTextBox(5, 3, 70, 196);
textBox.setText("Insert TextBox in Excel");

//Insert the textbox with picture
ITextBoxShape shape = sheet.getTextBoxes().addTextBox(5, 8, 128, 196);

//Save the Excel file
workbook.saveToFile("output/TextBox.xlsx", ExcelVersion.Version2010);