From f359a5c730f6b4aff4dbc013186b478f41277952 Mon Sep 17 00:00:00 2001
From: sungHeeLee <70899677+hee9841@users.noreply.github.com>
Date: Thu, 6 Nov 2025 21:29:00 +0900
Subject: [PATCH 1/3] chore: java downgrade to 21 in workflows (#68)
---
.github/workflows/ci.yml | 2 +-
.github/workflows/maven-publish.yml | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 52c7218..df1d3ea 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -22,7 +22,7 @@ jobs:
uses: actions/setup-java@v3
with:
distribution: 'temurin'
- java-version: '23'
+ java-version: '21'
- name: Grant execute permission for Gradle
run: chmod +x gradlew
diff --git a/.github/workflows/maven-publish.yml b/.github/workflows/maven-publish.yml
index 980b65c..53d7fc3 100644
--- a/.github/workflows/maven-publish.yml
+++ b/.github/workflows/maven-publish.yml
@@ -19,7 +19,7 @@ jobs:
- name: Set up JDK 11
uses: actions/setup-java@v4
with:
- java-version: '23'
+ java-version: '21'
distribution: 'temurin'
cache: 'gradle'
From 3d9cf99e15d405b43b28206819b1eb296bbe51df Mon Sep 17 00:00:00 2001
From: hee9841
Date: Fri, 7 Nov 2025 00:09:04 +0900
Subject: [PATCH 2/3] =?UTF-8?q?refactor:=20SXSSFExporter=EC=97=90=EC=84=9C?=
=?UTF-8?q?=20Sheet=20=EC=9D=98=EC=A1=B4=EC=84=B1=20=EC=B5=9C=EC=86=8C?=
=?UTF-8?q?=ED=99=94?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
- protected Sheet sheet 필드 제거 (SXSSFExporter)
- 재정의한 write을 final로 변경
- 기존 Sheet생성 + Header 생성 메서드 -> Sheet 생성을 구체 클래스로 이동, Header생성 메서드만 추상클래스에서 정의.
- SXSSFExporter 변경에 따른 인터페이스와 구현체 변경
---
.../core/exporter/DefaultExcelExporter.java | 78 ++++++++++++-------
.../excel/core/exporter/ExcelExporter.java | 3 +-
.../excel/core/exporter/SXSSFExporter.java | 57 +++++++-------
3 files changed, 78 insertions(+), 60 deletions(-)
diff --git a/src/main/java/io/github/hee9841/excel/core/exporter/DefaultExcelExporter.java b/src/main/java/io/github/hee9841/excel/core/exporter/DefaultExcelExporter.java
index a75fe65..931be4b 100644
--- a/src/main/java/io/github/hee9841/excel/core/exporter/DefaultExcelExporter.java
+++ b/src/main/java/io/github/hee9841/excel/core/exporter/DefaultExcelExporter.java
@@ -4,6 +4,7 @@
import io.github.hee9841.excel.strategy.SheetStrategy;
import java.text.MessageFormat;
import java.util.List;
+import org.apache.poi.ss.usermodel.Sheet;
/**
* DefaultExcelExporter is a concrete implementation of {@link SXSSFExporter} that provides functionality
@@ -69,7 +70,7 @@ public class DefaultExcelExporter extends SXSSFExporter {
setSheetStrategy(sheetStrategy);
this.initialize(type, data);
- this.createExcelFile(data);
+ this.createExcel(data);
}
@@ -85,6 +86,22 @@ public static DefaultExcelExporterBuilder builder(Class type, List
return new DefaultExcelExporterBuilder<>(type, data, supplyExcelVersion.getMaxRows());
}
+ /**
+ * Sets the sheet strategy for this exporter.
+ *
+ * This method also configures the workbook's Zip64 mode based on the selected strategy.
+ *
+ * @param strategy The sheet strategy to use (ONE_SHEET or MULTI_SHEET)-
+ */
+ private void setSheetStrategy(SheetStrategy strategy) {
+
+ this.sheetStrategy = strategy;
+ workbook.setZip64Mode(sheetStrategy.getZip64Mode());
+
+ logger.debug("Set sheet strategy and Zip64Mode - strategy: {}, Zip64Mode: {}.",
+ strategy.name(), sheetStrategy.getZip64Mode().name());
+ }
+
/**
* Validates the data size against the maximum rows per sheet limit.
@@ -107,7 +124,7 @@ protected void validate(Class> type, List data) {
}
/**
- * Creates the Excel file with the provided data.
+ * Creates the Excel(workBook) with the provided data.
*
* This method handles the creation of sheets and rows based on the data:
*
@@ -118,17 +135,19 @@ protected void validate(Class> type, List data) {
* @param data The list of data objects to be exported
*/
@Override
- protected void createExcelFile(List data) {
+ protected void createExcel(List data) {
// 1. If data is empty, create createHeader only.
if (data.isEmpty()) {
- createNewSheetWithHeader();
+ Sheet newSheet = createNewSheet();
+ createHeader(newSheet, ROW_START_INDEX);
logger.warn("Empty data provided - Excel file will be created with headers only.");
return;
}
//2. Add rows
- createNewSheetWithHeader();
- addRows(data);
+ Sheet newSheet = createNewSheet();
+ createHeader(newSheet, ROW_START_INDEX);
+ addRows(newSheet, data);
}
/**
@@ -144,10 +163,10 @@ protected void createExcelFile(List data) {
* @throws ExcelException if ONE_SHEET strategy is used and data exceeds max rows limit
*/
@Override
- public void addRows(List data) {
+ public void addRows(Sheet sheet, List data) {
int leftDataSize = data.size();
for (Object renderedData : data) {
- createBody(renderedData, currentRowIndex++);
+ createBody(sheet, renderedData, currentRowIndex++);
leftDataSize--;
if (currentRowIndex == maxRowsPerSheet && leftDataSize > 0) {
//If one sheet strategy, throw exception
@@ -158,27 +177,26 @@ public void addRows(List data) {
}
//If multi sheet strategy, create new sheet
- createNewSheetWithHeader();
+ currentRowIndex = ROW_START_INDEX;
+ sheet = createNewSheet();
+ createHeader(sheet, ROW_START_INDEX);
}
}
}
/**
- * Sets the sheet strategy for this exporter.
+ * Override createHeader Method to add currentRowIndex.
*
- * This method also configures the workbook's Zip64 mode based on the selected strategy.
- *
- * @param strategy The sheet strategy to use (ONE_SHEET or MULTI_SHEET)-
+ * @param sheet The sheet to add headers to
+ * @param headerRowIndex The headers row index
*/
- private void setSheetStrategy(SheetStrategy strategy) {
-
- this.sheetStrategy = strategy;
- workbook.setZip64Mode(sheetStrategy.getZip64Mode());
-
- logger.debug("Set sheet strategy and Zip64Mode - strategy: {}, Zip64Mode: {}.",
- strategy.name(), sheetStrategy.getZip64Mode().name());
+ @Override
+ protected void createHeader(Sheet sheet, Integer headerRowIndex) {
+ super.createHeader(sheet, headerRowIndex);
+ currentRowIndex++;
}
+
/**
* Creates a new sheet with headers.
*
@@ -186,19 +204,19 @@ private void setSheetStrategy(SheetStrategy strategy) {
* If a sheet name is provided, it will be used as a base name with an index(index starts from
* 0) suffix.
*/
- private void createNewSheetWithHeader() {
- currentRowIndex = ROW_START_INDEX;
-
+ private Sheet createNewSheet() {
//If sheet name is provided, create sheet with sheet name + idx
- if (sheetName != null) {
- sheet = workbook.createSheet(String.format("%s%d", sheetName, currentSheetIndex++));
- } else {
- sheet = workbook.createSheet();
- }
+ final String finalSheetName = (sheetName != null)
+ ? String.format("%s%d", sheetName, currentSheetIndex++)
+ : null;
+
+ Sheet sheet = (finalSheetName != null)
+ ? workbook.createSheet(finalSheetName)
+ : workbook.createSheet();
logger.debug("Create new Sheet : {}.", sheet.getSheetName());
- createHeaderWithNewSheet(sheet, ROW_START_INDEX);
- currentRowIndex++;
+ return sheet;
}
+
}
diff --git a/src/main/java/io/github/hee9841/excel/core/exporter/ExcelExporter.java b/src/main/java/io/github/hee9841/excel/core/exporter/ExcelExporter.java
index 30903d5..40aac19 100644
--- a/src/main/java/io/github/hee9841/excel/core/exporter/ExcelExporter.java
+++ b/src/main/java/io/github/hee9841/excel/core/exporter/ExcelExporter.java
@@ -3,6 +3,7 @@
import java.io.IOException;
import java.io.OutputStream;
import java.util.List;
+import org.apache.poi.ss.usermodel.Sheet;
/**
* Core interface for Excel file operations in the library.
@@ -31,5 +32,5 @@ public interface ExcelExporter {
*
* @param data The list of data objects to be added as rows
*/
- void addRows(List data);
+ void addRows(Sheet sheet, List data);
}
diff --git a/src/main/java/io/github/hee9841/excel/core/exporter/SXSSFExporter.java b/src/main/java/io/github/hee9841/excel/core/exporter/SXSSFExporter.java
index 3b6c0d1..1710fbb 100644
--- a/src/main/java/io/github/hee9841/excel/core/exporter/SXSSFExporter.java
+++ b/src/main/java/io/github/hee9841/excel/core/exporter/SXSSFExporter.java
@@ -1,8 +1,8 @@
package io.github.hee9841.excel.core.exporter;
-import io.github.hee9841.excel.exception.ExcelException;
import io.github.hee9841.excel.core.meta.ColumnInfo;
import io.github.hee9841.excel.core.meta.ColumnInfoMapper;
+import io.github.hee9841.excel.exception.ExcelException;
import java.io.IOException;
import java.io.OutputStream;
import java.lang.reflect.Field;
@@ -44,7 +44,6 @@ public abstract class SXSSFExporter implements ExcelExporter {
protected SXSSFWorkbook workbook;
protected Map columnsMappingInfo;
- protected Sheet sheet;
protected String dtoTypeName;
@@ -73,34 +72,15 @@ protected void initialize(Class> type, List data) {
this.columnsMappingInfo = ColumnInfoMapper.of(type, workbook).map();
}
- /**
- * Validates the provided data and type.
- * This method can be overridden by subclasses to add custom validation logic.
- *
- * @param type The class of the data type
- * @param data The list of data objects to be exported
- */
- protected void validate(Class> type, List data) {
- }
-
- /**
- * Creates the Excel file with the provided data.
- * This method must be implemented by subclasses to define their specific sheet management
- * strategy.
- *
- * @param data The list of data objects to be exported
- */
- protected abstract void createExcelFile(List data);
/**
- * Creates headers for a new sheet using the column mapping information.
+ * Creates headers using the column mapping information.
*
- * @param newSheet The sheet to add headers to
- * @param startRowIndex The row index where headers should start
+ * @param sheet The sheet to add headers to
+ * @param headerRowIndex The headers row index
*/
- protected void createHeaderWithNewSheet(Sheet newSheet, Integer startRowIndex) {
- this.sheet = newSheet;
- Row row = sheet.createRow(startRowIndex);
+ protected void createHeader(Sheet sheet, Integer headerRowIndex) {
+ Row row = sheet.createRow(headerRowIndex);
for (Integer colIndex : columnsMappingInfo.keySet()) {
ColumnInfo columnMappingInfo = columnsMappingInfo.get(colIndex);
Cell cell = row.createCell(colIndex);
@@ -113,11 +93,12 @@ protected void createHeaderWithNewSheet(Sheet newSheet, Integer startRowIndex) {
* Creates a row in the Excel sheet for the given data object.
* This method handles field access and cell value setting based on column mapping information.
*
- * @param data The data object to create a row for
+ * @param sheet The Sheet object to create a row.
+ * @param data The data object for rendering data to cell
* @param rowIndex The index of the row to create
* @throws ExcelException if field access fails
*/
- protected void createBody(Object data, int rowIndex) {
+ protected void createBody(Sheet sheet, Object data, int rowIndex) {
logger.debug("Add rows data - row:{}.", rowIndex);
Row row = sheet.createRow(rowIndex);
for (Integer colIndex : columnsMappingInfo.keySet()) {
@@ -146,7 +127,7 @@ protected void createBody(Object data, int rowIndex) {
* @throws IOException if an I/O error occurs during writing
*/
@Override
- public void write(OutputStream stream) throws IOException {
+ public final void write(OutputStream stream) throws IOException {
if (stream == null) {
throw new ExcelException("Output stream is null.");
}
@@ -159,4 +140,22 @@ public void write(OutputStream stream) throws IOException {
}
}
+ /**
+ * Validates the provided data and type.
+ * This method can be overridden by subclasses to add custom validation logic.
+ *
+ * @param type The class of the data type
+ * @param data The list of data objects to be exported
+ */
+ protected abstract void validate(Class> type, List data);
+
+ /**
+ * Creates the Excel file with the provided data.
+ * This method must be implemented by subclasses to define their specific sheet management
+ * strategy.
+ *
+ * @param data The list of data objects to be exported
+ */
+ protected abstract void createExcel(List data);
+
}
From 01bbeb2e71a99c25a3298cb2ad6f1e3db22a287e Mon Sep 17 00:00:00 2001
From: hee9841
Date: Fri, 7 Nov 2025 00:11:27 +0900
Subject: [PATCH 3/3] chore: Release version update to '0.0.3'
---
build.gradle | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/build.gradle b/build.gradle
index 0b5404f..0f111ca 100644
--- a/build.gradle
+++ b/build.gradle
@@ -11,7 +11,7 @@ plugins {
}
group = 'io.github.hee9841.excel'
-version = '0.0.2'
+version = '0.0.3'
repositories {
mavenCentral()