Introduction

Aspose.Cells FOSS for Java provides a comprehensive set of spreadsheet capabilities for Java 17 applications. Released under the MIT license and distributed as a standard Maven artifact, the library covers everything from basic workbook creation through typed cell values, rich formatting, data validation, and AutoFilter — all without a Microsoft Office dependency.

This post walks through the main feature areas with focused code examples drawn from the verified API surface. All class and method names shown below exist in the library and are available in version 1.0.0.


Key Features

Workbook and Worksheet Management

The Workbook class implements AutoCloseable so it integrates cleanly with the Java try-with-resources pattern. You can create a blank workbook, load an existing .xlsx file, rename worksheets, add or remove sheets, set the active sheet, and control tab visibility.

import com.aspose.cells_foss.Workbook;
import com.aspose.cells_foss.Worksheet;

try (Workbook workbook = new Workbook()) {
    Worksheet sheet = workbook.getWorksheets().get(0);
    sheet.setName("Q1 Report");
    workbook.getWorksheets().addSheet("Summary");
    workbook.save("report.xlsx");
}

Typed Cell Values and Formulas

The Cell class accepts typed values via putValue() for String, int, double, boolean, and LocalDateTime. The getType() method returns a CellValueType enum value — STRING, NUMBER, BOOLEAN, DATE_TIME, or FORMULA — making it easy to branch on value type without parsing strings. Formula strings are stored with setFormula() and will be recalculated by Excel on open.

import com.aspose.cells_foss.Cell;
import com.aspose.cells_foss.CellValueType;
import com.aspose.cells_foss.Workbook;
import com.aspose.cells_foss.Worksheet;

try (Workbook workbook = new Workbook()) {
    Worksheet sheet = workbook.getWorksheets().get(0);
    Cell a1 = sheet.getCells().get("A1");
    a1.putValue("Revenue");
    Cell b1 = sheet.getCells().get("B1");
    b1.putValue(42500.00);
    Cell c1 = sheet.getCells().get("C1");
    c1.setFormula("=B1*1.2");
    // Check type
    assert b1.getType() == CellValueType.NUMBER;
    assert c1.getType() == CellValueType.FORMULA;
    workbook.save("values.xlsx");
}

Cell Formatting and Styles

Formatting is applied through the Style object retrieved from cell.getStyle() and written back with cell.setStyle(). The Font sub-object exposes setBold() and setColor(). HorizontalAlignment controls text alignment — LEFT, CENTER, or RIGHT. Custom number formats use Excel format strings via style.setCustom(). Row height and column width are adjusted through getRows().get(n).setHeight() and getColumns().get(n).setWidth().

import com.aspose.cells_foss.Cell;
import com.aspose.cells_foss.Style;
import com.aspose.cells_foss.Workbook;
import com.aspose.cells_foss.Worksheet;

try (Workbook workbook = new Workbook()) {
    Worksheet sheet = workbook.getWorksheets().get(0);
    Cell cell = sheet.getCells().get("B1");
    cell.putValue(9999.50);
    Style style = cell.getStyle();
    style.getFont().setBold(true);
    style.setCustom("#,##0.00");
    cell.setStyle(style);
    sheet.getCells().getRows().get(0).setHeight(24.0);
    sheet.getCells().getColumns().get(1).setWidth(16.0);
    workbook.save("styled.xlsx");
}

Data Validation

Data validation rules are added through sheet.getValidations().add(). Each Validation object takes a ValidationType (e.g. WHOLE_NUMBER, DECIMAL, LIST) and an OperatorType (e.g. BETWEEN, GREATER_THAN). Formula bounds are stored as strings via setFormula1() and setFormula2().

import com.aspose.cells_foss.CellArea;
import com.aspose.cells_foss.OperatorType;
import com.aspose.cells_foss.Validation;
import com.aspose.cells_foss.ValidationType;
import com.aspose.cells_foss.Workbook;
import com.aspose.cells_foss.Worksheet;

try (Workbook workbook = new Workbook()) {
    Worksheet sheet = workbook.getWorksheets().get(0);
    int vi = sheet.getValidations().add(new CellArea(1, 0, 10, 0));
    Validation validation = sheet.getValidations().get(vi);
    validation.setType(ValidationType.WHOLE_NUMBER);
    validation.setOperator(OperatorType.BETWEEN);
    validation.setFormula1("1");
    validation.setFormula2("100");
    workbook.save("validated.xlsx");
}

AutoFilter

AutoFilters let end users interactively filter data in Excel without any extra configuration. Call ws.getAutoFilter().setRange() with an A1-notation range to enable the filter header row. Additional filter columns and custom criteria can be defined through FilterColumn and AutoFilterCustomFilter.

import com.aspose.cells_foss.Workbook;
import com.aspose.cells_foss.Worksheet;

try (Workbook workbook = new Workbook()) {
    Worksheet sheet = workbook.getWorksheets().get(0);
    sheet.getCells().get("A1").putValue("Product");
    sheet.getCells().get("B1").putValue("Qty");
    sheet.getAutoFilter().setRange("A1:B1");
    workbook.save("filtered.xlsx");
}

Page Setup and Worksheet Protection

The PageSetup class controls paper size, page orientation, and fit-to-page settings for print-ready output. Worksheet protection is applied through protect() with a WorksheetProtectionModel, allowing specific cells to remain editable while locking the rest. Hyperlinks are managed through HyperlinkCollection.


Quick Start

Add the dependency to your pom.xml:

<dependency>
  <groupId>com.aspose</groupId>
  <artifactId>cells-foss</artifactId>
  <version>1.0.0</version>
</dependency>

Create a workbook with all major features in under 20 lines:

import com.aspose.cells_foss.Cell;
import com.aspose.cells_foss.Style;
import com.aspose.cells_foss.Workbook;
import com.aspose.cells_foss.Worksheet;

public class QuickStart {
    public static void main(String[] args) {
        try (Workbook workbook = new Workbook()) {
            Worksheet sheet = workbook.getWorksheets().get(0);
            sheet.setName("Sales");
            sheet.getCells().get("A1").putValue("Revenue");
            Cell b1 = sheet.getCells().get("B1");
            b1.putValue(42500.00);
            Style style = b1.getStyle();
            style.getFont().setBold(true);
            style.setCustom("#,##0.00");
            b1.setStyle(style);
            sheet.getAutoFilter().setRange("A1:B1");
            workbook.save("sales.xlsx");
        }
    }
}

Supported Formats

FormatExtensionReadWrite
Excel Open XML.xlsx

Saving is currently limited to .xlsx. The library stores and round-trips formulas but does not function as a full spreadsheet calculation engine.


Open Source & Licensing

Aspose.Cells FOSS for Java is released under the MIT license. You are free to use, modify, and distribute it in personal, open-source, and commercial projects without restriction. The source code is available at github.com/aspose-cells-foss/Aspose.Cells-FOSS-for-Java.


Getting Started