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 show 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 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"
		 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
		 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>

	<groupId>com.gembox.examples</groupId>
	<artifactId>hello-world</artifactId>
	<version>1.0</version>

	<repositories>
		<repository>
			<id>com.gembox</id>
			<name>GemBox API</name>
			<url>https://gemboxsoftware.com/repo/</url>
		</repository>
	</repositories>

	<dependencies>
		<dependency>
			<groupId>com.gembox</groupId>
			<artifactId>gembox-spreadsheet</artifactId>
			<version>1.1.1079</version> <!-- You can choose other version -->
		</dependency>
	</dependencies>
</project>

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 working modes of GemBox.Spreadsheet for Java 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 object to a file in the desired format.

Simple Excel file created with GemBox.Spreadsheet for java
Screenshot of 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.
        SpreadsheetInfo.setLicense("FREE-LIMITED-KEY");

        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%");
    }
}

Want more?

Next example GitHub

Check the next example or select an example from the menu. You can also download our examples from the GitHub.


Like it?

Download Buy

If you want to try the GemBox.Spreadsheet for Java yourself, you can download the free version. It delivers the same performance and set of features as the professional version, but with some operations limited. To remove the limitation, you need to purchase a license.