---
Product: Aspose.Cells
Platform: java
Page Type: kb
Canonical URL: https://kb.aspose.org/cells/java/how-to-load-spreadsheet-java
---

# How to Load a Spreadsheet in Java

Step-by-step guide to loading an Excel .xlsx workbook in Java using Aspose.Cells FOSS. Covers file-path loading, stream-based loading, and accessing worksheets after load.

## Overview

Aspose.Cells FOSS for Java lets you open existing Excel `.xlsx` workbooks from a
file path or from any `java.io.InputStream`. This guide shows both loading patterns
and explains how to access worksheets and cells after the workbook is loaded.

---

### Prerequisites

| Requirement | Detail |
|-------------|--------|
| Java | 17 or later (JDK) |
| Build tool | Maven 3.9+ or Gradle 8+ |
| Dependency | `org.aspose:aspose-cells-foss:26.7.0` |
| Input file | A valid `.xlsx` workbook |

Add to `pom.xml`:

```xml
<dependency>
  <groupId>org.aspose</groupId>
  <artifactId>aspose-cells-foss</artifactId>
  <version>26.7.0</version>
</dependency>
```

---

### Step 1 — Load from a File Path

Pass the absolute or relative file path to the `Workbook(fileName)` constructor:

```java
import org.aspose.cells_foss.Workbook;

Workbook workbook = new Workbook("data/report.xlsx");
System.out.println("Loaded. Sheets: " + workbook.getWorksheets().getCount());
```

The constructor reads the file and deserializes the XLSX content into memory. A
missing file raises `WorkbookLoadException`; a file that is not a valid XLSX package
raises `InvalidFileFormatException`. Both extend `CellsException`.

---

### Step 2 — Load from a Stream

Use `Workbook(stream)` when the file content comes from a network connection, a
database BLOB, or an in-memory buffer:

```java
import org.aspose.cells_foss.Workbook;
import java.io.FileInputStream;
import java.io.InputStream;

try (InputStream is = new FileInputStream("data/report.xlsx")) {
    Workbook workbook = new Workbook(is);
    System.out.println("Loaded from stream. Sheets: " + workbook.getWorksheets().getCount());
}
```

Always wrap the `InputStream` in a try-with-resources block so the stream is closed
even if the constructor throws.

---

### Step 3 — Load with Options

Use `Workbook(fileName, options)` or `Workbook(stream, options)` to pass a
`LoadOptions` instance when you need fine-grained control over the load behaviour:

```java
import org.aspose.cells_foss.Workbook;
import org.aspose.cells_foss.LoadOptions;

LoadOptions opts = new LoadOptions();
// configure opts here if needed
Workbook workbook = new Workbook("data/report.xlsx", opts);
```

---

### Step 4 — Access Worksheets

After loading, use `Workbook.getWorksheets()` to iterate sheets or retrieve a
specific sheet by index or by name:

```java
import org.aspose.cells_foss.WorksheetCollection;
import org.aspose.cells_foss.Worksheet;

WorksheetCollection sheets = workbook.getWorksheets();
System.out.println("Sheet count: " + sheets.getCount());

// By index
Worksheet first = sheets.get(0);
System.out.println("First sheet: " + first.getName());

// By name
Worksheet named = sheets.get("Summary");
```

---

### Step 5 — Read Cell Values

Once you have a `Worksheet`, use `getCells()` to access individual cells:

```java
import org.aspose.cells_foss.Cells;
import org.aspose.cells_foss.Cell;

Cells cells = first.getCells();

// Read by cell name
Cell a1 = cells.get("A1");
System.out.println("A1 value: " + a1.getStringValue());

// Read by row/column index (0-based)
Cell b2 = cells.get(1, 1);
System.out.println("B2 value: " + b2.getValue());
```

---

### Step 6 — Release Resources

`Workbook` implements `AutoCloseable`. For large files, use try-with-resources:

```java
import org.aspose.cells_foss.Workbook;

try (Workbook workbook = new Workbook("data/large.xlsx")) {
    // read or modify the workbook
    workbook.save("data/output.xlsx");
}
// workbook.close() is called automatically here
```

---

### Next Steps

- [Working with Spreadsheet Management](https://docs.aspose.org/cells/java/developer-guide/working-with-spreadsheet-management/) — full create/modify/save walkthrough
- [How to Create an Aspose.Cells FOSS Workbook](/cells/java/how-to-create-cells-foss-java/) — create workbooks from scratch
- [How to Work with Validation](/cells/java/how-to-work-with-cell-validation-java/) — add data validation rules

## See Also

- [Aspose.Cells for Java — Enterprise Knowledge Base](https://kb.aspose.com/cells/java/)