Introduction
Aspose.Cells FOSS for Java is an open-source Java 17 library that enables developers
to create, load, modify, and save Excel .xlsx workbooks entirely on the JVM — with
no Microsoft Office installation, no native libraries, and no commercial Aspose runtime
dependency. The public API lives under the com.aspose.cells_foss package and is
released under the MIT license, making it suitable for personal, open-source, and
commercial projects alike.
The library ships as a standard Maven artifact and covers the core OOXML spreadsheet object model: workbooks, worksheets, cells, styles, and collections. It is built with Maven 3.9+ and targets Java 17+, integrating naturally into any modern Java build pipeline.
Add the dependency to your pom.xml and you are ready to generate or process Excel
workbooks from a servlet, a batch job, a Lambda function, or any other Java server-side
context.
Key Features
Workbook and Worksheet Management
The Workbook class is the entry point for all spreadsheet operations. It implements
AutoCloseable so it integrates cleanly with the try-with-resources pattern. You can
create new workbooks, load existing .xlsx files, add and remove worksheets, rename
sheets with setName(), set the active sheet, and control tab visibility.
import com.aspose.cells_foss.Workbook;
import com.aspose.cells_foss.Worksheet;
import com.aspose.cells_foss.WorksheetCollection;
try (Workbook workbook = new Workbook()) {
WorksheetCollection sheets = workbook.getWorksheets();
Worksheet sheet = sheets.get(0);
sheet.setName("Sales");
workbook.save("sales.xlsx");
}
Cell Values and Formulas
The Cell class supports typed value storage via putValue() for strings, integers,
doubles, booleans, and LocalDateTime values. Formula strings are stored with
setFormula() and will be recalculated by Excel on open. The value type is exposed
through CellValueType — STRING, NUMBER, BOOLEAN, DATE_TIME, or FORMULA.
import com.aspose.cells_foss.Cell;
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(12500.75);
Cell c1 = sheet.getCells().get("C1");
c1.setFormula("=B1*1.2");
workbook.save("values.xlsx");
}
Cell Formatting and Styles
Formatting is applied through the Style class, retrieved from cell.getStyle() and
written back with cell.setStyle(). You can configure bold and colour on the Font,
apply HorizontalAlignment, and set custom number format strings via style.setCustom().
Row height and column width are controlled through getRows().get(n).setHeight() and
getColumns().get(n).setWidth().
import com.aspose.cells_foss.Style;
import com.aspose.cells_foss.Cell;
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.5);
Style style = cell.getStyle();
style.getFont().setBold(true);
style.setCustom("#,##0.00");
cell.setStyle(style);
workbook.save("styled.xlsx");
}
Data Validation and Conditional Formatting
Data validation rules are added through sheet.getValidations().add(). Each
Validation object holds a ValidationType (e.g., WHOLE_NUMBER), an OperatorType
(e.g., BETWEEN), and formula strings for the bounds. Conditional formatting is added
through sheet.getConditionalFormattings().add(), which returns a
FormatConditionCollection where you specify cell ranges and conditions.
import com.aspose.cells_foss.CellArea;
import com.aspose.cells_foss.Validation;
import com.aspose.cells_foss.ValidationType;
import com.aspose.cells_foss.OperatorType;
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");
}
AutoFilters and Page Setup
AutoFilters are configured by calling ws.getAutoFilter().setRange() with an A1-notation
range string. The PageSetup object controls paper size, orientation, and fit-to-page
settings for print-ready output. Worksheet protection is applied through protect() with
a WorksheetProtectionModel.
Quick Start
Add the Maven dependency to your pom.xml:
<dependency>
<groupId>com.aspose</groupId>
<artifactId>cells-foss</artifactId>
<version>1.0.0</version>
</dependency>
Create a workbook, populate cells, apply formatting, and save:
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("Report");
sheet.getCells().get("A1").putValue("Revenue");
Cell cell = sheet.getCells().get("B1");
cell.putValue(12500.75);
Style style = cell.getStyle();
style.getFont().setBold(true);
style.setCustom("#,##0.00");
cell.setStyle(style);
sheet.getCells().getRows().get(0).setHeight(22.0);
sheet.getCells().getColumns().get(1).setWidth(14.5);
workbook.save("report.xlsx");
}
}
}
Supported Formats
| Format | Extension | Read | Write |
|---|---|---|---|
| Excel Open XML | .xlsx | ✓ | ✓ |
Saving is currently limited to .xlsx. The library stores and round-trips formulas,
but it is not 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.