Extract Text from Textbox in Excel Using Java

Installation (2 Method)

1# Download the free API and unzip it, then add the Spire.Xls.jar file to your project as dependency.

<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>5.1.0</version>
</dependency>
</dependencies>

Steps and Sample Code

  1. Create a Workbook instance.
  2. Load a sample Excel file using Workbook.loadFromFile() method.
  3. Get a specified worksheet using Workbook.getWorksheets().get() method.
  4. Get a specified textbox using Worksheet.getTextBoxes().get() method.
  5. Get the text in the specified textbox using XlsTextBoxShape.getText() method.
import com.spire.xls.Workbook;
import com.spire.xls.Worksheet;
import com.spire.xls.core.spreadsheet.shapes.XlsTextBoxShape;

public class ExtractTextFromTextbox {

public static void main(String[] args) {

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

//Load a sample Excel file
workbook.loadFromFile("input.xlsx");

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

//Get the first textbox
XlsTextBoxShape shape = (XlsTextBoxShape)sheet.getTextBoxes().get(0);

//Get the text inside the textbox
String text = shape.getText();
System.out.print(text);
}
}

--

--

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