Excel API/Library for Java applications

The fastest way to get started with the GemBox.Spreadsheet for Java library is by exploring our collection of Java examples. These are live examples that demonstrate the supported features and APIs that can be used to achieve various Excel-related tasks with the GemBox.Spreadsheet for Java component.

System Requirements

GemBox.Spreadsheet for Java works on systems with Java 8 or higher.

Hello World

The first step in using the GemBox.Spreadsheet for java library is to add a reference to gembox-spreadsheet.jar within your Java project. There are two ways to do that.

a) Add from Maven

You can add GemBox.Spreadsheet for Java as a dependency using following code in your pom.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
		 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">


			<name>GemBox API</name>

			<version>1.1.1079</version> <!-- You can choose other version -->

b) Add from a jar file.

You can download a gembox-spreadsheet.jar file from this page and add a reference by browsing to it.

Adding GemBox.Spreadsheet for Java library from jar in Intellij IDEA
Adding GemBox.Spreadsheet for Java library from jar in Intellij IDEA

The second step is to add a directive for the com.gembox.spreadsheet package:
import com.gembox.spreadsheet.*;

The third step is to set the license key to use GemBox.Spreadsheet for Java in one of its working modes.
To use a Free mode use: SpreadsheetInfo.setLicense("FREE-LIMITED-KEY");.
You can read more about GemBox.Spreadsheet's working modes on the Evaluation and Licensing help page.

The last step is to write your application-specific Excel workbook code, like the following example code, which shows how to create a simple Excel workbook using the API of the library. It shows how to initialize the GemBox.Spreadsheet for Java content model, populate some cells, and then save an ExcelFile instance to a file in the desired format. It also demonstrates support for international characters (Unicode).

Screenshot of simple Excel file created with GemBox.Spreadsheet for Java
Simple Excel file created with GemBox.Spreadsheet for java
import com.gembox.spreadsheet.*;

class Program {

    public static void main(String[] args) throws java.io.IOException {
        // If using Professional version, put your serial key below.

        ExcelFile workbook = new ExcelFile();
        ExcelWorksheet worksheet = workbook.addWorksheet("Hello World");

        worksheet.getCell(0, 0).setValue("English:");
        worksheet.getCell(0, 1).setValue("Hello");

        worksheet.getCell(1, 0).setValue("Russian:");
        // Using UNICODE string.
        worksheet.getCell(1, 1).setValue(new String(new char[] { '\u0417', '\u0434', '\u0440', '\u0430', '\u0432', '\u0441', '\u0442', '\u0432', '\u0443', '\u0439', '\u0442', '\u0435' }));

        worksheet.getCell(2, 0).setValue("Chinese:");
        // Using UNICODE string.
        worksheet.getCell(2, 1).setValue(new String(new char[] { '\u4f60', '\u597d' }));

        worksheet.getCell(4, 0).setValue("In order to see Russian and Chinese characters you need to have appropriate fonts on your PC.");
        worksheet.getCells().getSubrangeAbsolute(4, 0, 4, 7).setMerged(true);

        workbook.save("Hello World.%OutputFileType%");

Check next example or download examples from GitHub.