Insert Textbox to Excel Worksheet Using Java

<repositories>
<repository>
<id>com.e-iceblue</id>
<name>e-iceblue</name>
<url>http://repo.e iceblue.com/nexus/content/groups/public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>e-iceblue</groupId>
<artifactId>spire.xls.free</artifactId>
<version>3.9.1</version>
</dependency>
</dependencies>
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");
textBox.setHAlignment(CommentHAlignType.Center);
textBox.setVAlignment(CommentVAlignType.Center);

//Insert the textbox with picture
ITextBoxShape shape = sheet.getTextBoxes().addTextBox(5, 8, 128, 196);
shape.getFill().customPicture("C:\\Users\\Administrator\\Desktop\\java.png");
shape.getFill().setFillType(ShapeFillType.Picture);

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

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store