Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 38 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[![License](https://img.shields.io/badge/License-Apache%202.0-green.svg)](LICENSE)
[![GitHub stars](https://img.shields.io/github/stars/chitralabs/sheetz?style=social)](https://github.com/chitralabs/sheetz)

**8 runnable examples** demonstrating every feature of the [Sheetz](https://github.com/chitralabs/sheetz) library — read, write, stream, and validate Excel and CSV files in Java with minimal code.
**9 runnable examples** demonstrating every feature of the [Sheetz](https://github.com/chitralabs/sheetz) library — read, write, stream, and validate Excel and CSV files in Java with minimal code.

```java
// This is all it takes to read an Excel file into Java objects
Expand Down Expand Up @@ -191,7 +191,7 @@ Sheetz.register(BigDecimal.class, new MoneyConverter());

### 08 — Format Conversion

Convert between XLSX, XLS, and CSV formats. Sheetz auto-detects the format from the file extension — converting is just read + write.
Convert between XLSX, XLS, ODS, and CSV formats. Sheetz auto-detects the format from the file extension — converting is just read + write.

```java
// XLSX → CSV
Expand All @@ -207,6 +207,32 @@ Sheetz.write(data, "products.xls");

---

### 09 — Cell Styling

Apply cell formatting with `@Style` annotations and `CellStyleBuilder`. Supports bold, colors, alignment, data formats, hyperlinks, and auto-filter. New in Sheetz 1.1.0.

```java
// Annotation-based styling
@Column("Price")
@Style(backgroundColor = "#FFFF00", horizontalAlignment = "CENTER", dataFormat = "#,##0.00")
public Double price;

// Programmatic header style
CellStyleDef headerStyle = CellStyleBuilder.create()
.bold(true).backgroundColor("#003366").fontColor("#FFFFFF").build();

Sheetz.writer(StyledProduct.class)
.data(products)
.file("styled.xlsx")
.headerStyle(headerStyle)
.autoFilter(true)
.write();
```

[View source](src/main/java/io/github/chitralabs/sheetz/examples/E09_CellStyling.java)

---

## Running Examples

```bash
Expand All @@ -217,7 +243,7 @@ mvn compile exec:java -Dexec.mainClass="io.github.chitralabs.sheetz.examples.E01
mvn compile exec:java -Dexec.mainClass="io.github.chitralabs.sheetz.examples.E03_StreamingLargeFiles"

# Run all examples in sequence
for i in 01 02 03 04 05 06 07 08; do
for i in 01 02 03 04 05 06 07 08 09; do
echo "--- Running E${i} ---"
mvn -q compile exec:java -Dexec.mainClass="io.github.chitralabs.sheetz.examples.E${i}_$(ls src/main/java/io/github/chitralabs/sheetz/examples/E${i}_*.java | xargs basename | sed 's/.java//')"
done
Expand All @@ -237,30 +263,30 @@ done
<dependency>
<groupId>io.github.chitralabs.sheetz</groupId>
<artifactId>sheetz-core</artifactId>
<version>1.0.2</version>
<version>1.1.0</version>
</dependency>
```

**Gradle:**
```groovy
implementation 'io.github.chitralabs.sheetz:sheetz-core:1.0.2'
implementation 'io.github.chitralabs.sheetz:sheetz-core:1.1.0'
```

## 🤝 Add Your Own Example

Have a use case not covered here? **We want your example!**

Ideas we'd love PRs for:
- [ ] E09 — Spring Boot REST endpoint that exports data to Excel
- [ ] E10 — Database import pipeline (read Excel → save to JPA/Hibernate)
- [ ] E11 — Concurrent multi-file processing with ExecutorService
- [ ] E12 — Error recovery — partial import with validation report
- [ ] E13 — Dynamic headers — read files where column order is unknown
- [ ] E14 — Large file memory benchmark — heap usage comparison
- [ ] E10 — Spring Boot REST endpoint that exports data to Excel
- [ ] E11 — Database import pipeline (read Excel → save to JPA/Hibernate)
- [ ] E12 — Concurrent multi-file processing with ExecutorService
- [ ] E13 — Error recovery — partial import with validation report
- [ ] E14 — Dynamic headers — read files where column order is unknown
- [ ] E15 — Large file memory benchmark — heap usage comparison

**How to contribute an example:**
1. Copy an existing example file (e.g. `E01_BasicReadWrite.java`) as a template
2. Name it `E09_YourExampleName.java`
2. Name it `E10_YourExampleName.java`
3. Add it to `README.md` following the existing format
4. Open a PR — your name goes in the changelog!

Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>io.github.chitralabs.sheetz</groupId>
<artifactId>sheetz-examples</artifactId>
<version>1.0.0</version>
<version>1.1.0</version>
<packaging>jar</packaging>

<name>Sheetz Examples</name>
Expand All @@ -24,7 +24,7 @@
<dependency>
<groupId>io.github.chitralabs.sheetz</groupId>
<artifactId>sheetz-core</artifactId>
<version>1.0.2</version>
<version>1.1.0</version>
</dependency>

<!-- SLF4J Simple for log output in examples -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* Demonstrates converting between Excel and CSV formats:
* - XLSX → CSV
* - CSV → XLSX
* - XLSX → ODS (OpenDocument)
* - XLSX → XLS (legacy format)
* - Read and write with format auto-detection from file extension
*/
Expand Down Expand Up @@ -49,6 +50,12 @@ public static void main(String[] args) {
Sheetz.write(fromCsv, newXlsxPath);
System.out.println("Converted " + csvPath + " → " + newXlsxPath);

// --- XLSX → ODS ---
System.out.println("\n--- XLSX → ODS (OpenDocument) ---");
String odsPath = "output/converted.ods";
Sheetz.write(fromXlsx, odsPath);
System.out.println("Converted " + xlsxPath + " → " + odsPath);

// --- XLSX → XLS ---
System.out.println("\n--- XLSX → XLS (legacy format) ---");
String xlsPath = "output/legacy.xls";
Expand All @@ -59,15 +66,18 @@ public static void main(String[] args) {
System.out.println("\n--- Verification: all formats contain same data ---");
List<Product> verifyXlsx = Sheetz.read(newXlsxPath, Product.class);
List<Product> verifyCsv = Sheetz.read(csvPath, Product.class);
List<Product> verifyOds = Sheetz.read(odsPath, Product.class);
List<Product> verifyXls = Sheetz.read(xlsPath, Product.class);

System.out.println("XLSX rows: " + verifyXlsx.size());
System.out.println("CSV rows: " + verifyCsv.size());
System.out.println("ODS rows: " + verifyOds.size());
System.out.println("XLS rows: " + verifyXls.size());

System.out.println("\nFirst product from each format:");
System.out.println(" XLSX: " + verifyXlsx.get(0));
System.out.println(" CSV: " + verifyCsv.get(0));
System.out.println(" ODS: " + verifyOds.get(0));
System.out.println(" XLS: " + verifyXls.get(0));

System.out.println("\nDone!");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package io.github.chitralabs.sheetz.examples;

import io.github.chitralabs.sheetz.Sheetz;
import io.github.chitralabs.sheetz.annotation.Column;
import io.github.chitralabs.sheetz.annotation.Style;
import io.github.chitralabs.sheetz.style.CellStyleBuilder;
import io.github.chitralabs.sheetz.style.CellStyleDef;
import io.github.chitralabs.sheetz.style.HyperlinkValue;

import java.util.List;

/**
* E09: Cell Styling — @Style annotation, programmatic styles, and hyperlinks.
*
* Demonstrates the cell formatting API added in Sheetz 1.1.0.
*/
public class E09_CellStyling {

// --- Model with @Style annotation ---
public static class StyledProduct {
@Column("Product Name")
@Style(bold = true, fontColor = "#0000FF")
public String name;

@Column("Price")
@Style(backgroundColor = "#FFFF00", horizontalAlignment = "CENTER", dataFormat = "#,##0.00")
public Double price;

@Column("Website")
@Style(hyperlink = true)
public HyperlinkValue website;

public StyledProduct() {}

public StyledProduct(String name, Double price, String url) {
this.name = name;
this.price = price;
this.website = new HyperlinkValue(name + " site", url);
}
}

public static void main(String[] args) {
System.out.println("=== E09: Cell Styling ===\n");

// 1. Write with @Style annotations
List<StyledProduct> products = List.of(
new StyledProduct("Widget", 29.99, "https://example.com/widget"),
new StyledProduct("Gadget", 49.99, "https://example.com/gadget"),
new StyledProduct("Gizmo", 19.99, "https://example.com/gizmo")
);

Sheetz.write(products, "styled-products.xlsx");
System.out.println("Wrote styled-products.xlsx with @Style annotations");

// 2. Programmatic header style with CellStyleBuilder
CellStyleDef headerStyle = CellStyleBuilder.create()
.bold(true)
.backgroundColor("#003366")
.fontColor("#FFFFFF")
.horizontalAlignment("CENTER")
.build();

Sheetz.writer(StyledProduct.class)
.data(products)
.file("styled-with-header.xlsx")
.headerStyle(headerStyle)
.autoFilter(true)
.write();

System.out.println("Wrote styled-with-header.xlsx with programmatic header style and auto-filter");

// 3. Read back
List<StyledProduct> readBack = Sheetz.read("styled-products.xlsx", StyledProduct.class);
for (StyledProduct p : readBack) {
System.out.printf(" %s — $%.2f%n", p.name, p.price);
}

System.out.println("\nDone!");
}
}
Loading