Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.apache.fesod.sheet.annotation.format.DateTimeFormat;
import org.apache.fesod.sheet.converters.AutoConverter;
import org.apache.fesod.sheet.converters.Converter;

Expand Down Expand Up @@ -74,14 +73,4 @@
* @return Converter
*/
Class<? extends Converter<?>> converter() default AutoConverter.class;

/**
*
* default @see org.apache.fesod.sheet.util.TypeUtil if default is not meet you can set format
*
* @return Format string
* @deprecated please use {@link DateTimeFormat}
*/
@Deprecated
String format() default "";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.apache.fesod.sheet.annotation;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.file.Path;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import lombok.Data;
import org.apache.fesod.sheet.FastExcel;
import org.apache.fesod.sheet.annotation.format.DateTimeFormat;
import org.apache.fesod.sheet.context.AnalysisContext;
import org.apache.fesod.sheet.read.listener.ReadListener;
import org.apache.fesod.sheet.util.StringUtils;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

public class ExcelPropertyFormatTest {

@Data
static class FormatSample {
@ExcelProperty()
@DateTimeFormat("yyyy-MMM-dd")
private Date date2;

@ExcelProperty()
@DateTimeFormat("yyyy-MMM-dd")
private LocalDate dateLocalDate2;
}

@Test
public void testSingleFormatSampleWriteAndRead(@TempDir Path tempDir) throws IOException {
List<FormatSample> singleElementList = new LinkedList<>();
FormatSample sample = new FormatSample();
sample.setDate2(new Date());
sample.setDateLocalDate2(LocalDate.of(2025, 2, 1));
singleElementList.add(sample);
String fileName =
tempDir.resolve(System.currentTimeMillis() + "_single.xlsx").toString();
FastExcel.write(fileName, FormatSample.class).sheet("UnitTest").doWrite(singleElementList);
try (FileInputStream fis = new FileInputStream(fileName);
XSSFWorkbook workbook = new XSSFWorkbook(fis)) {
Row dataRow = workbook.getSheetAt(0).getRow(1);
assertEquals("yyyy-MMM-dd", dataRow.getCell(0).getCellStyle().getDataFormatString());
assertEquals("yyyy-MMM-dd", dataRow.getCell(1).getCellStyle().getDataFormatString());
}
}

/**
* Test cell format string after writing date format pattern with Chinese characters.
*/
@Data
static class ChinesePatternSample {
@ExcelProperty
@DateTimeFormat("yyyy年MM月dd日HH时mm分ss秒")
private Date fullDate;

@ExcelProperty
@DateTimeFormat("yyyy年MM月dd日")
private LocalDate localDate;
}

@Test
public void testChinesePatternFormat(@TempDir Path tempDir) throws IOException {
ChinesePatternSample sample = new ChinesePatternSample();
sample.setFullDate(new Date());
sample.setLocalDate(LocalDate.of(2025, 1, 2));
String fileName = tempDir.resolve("chinese_pattern.xlsx").toString();
FastExcel.write(fileName, ChinesePatternSample.class)
.sheet("ChineseFormat")
.doWrite(Collections.singletonList(sample));
Comment on lines +97 to +99

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

As part of the project's renaming, the deprecated FastExcel class should be replaced with FesodSheet for consistency.

Suggested change
FastExcel.write(fileName, ChinesePatternSample.class)
.sheet("ChineseFormat")
.doWrite(Collections.singletonList(sample));
FesodSheet.write(fileName, ChinesePatternSample.class)
.sheet("ChineseFormat")
.doWrite(Collections.singletonList(sample));

try (FileInputStream fis = new FileInputStream(fileName);
XSSFWorkbook workbook = new XSSFWorkbook(fis)) {
Row dataRow = workbook.getSheetAt(0).getRow(1);
assertEquals(
"yyyy年MM月dd日HH时mm分ss秒", dataRow.getCell(0).getCellStyle().getDataFormatString());
assertEquals("yyyy年MM月dd日", dataRow.getCell(1).getCellStyle().getDataFormatString());
}
}

/**
* Test different fields with different formats.
*/
@Data
static class MultiPatternSample {
@ExcelProperty
@DateTimeFormat("yyyy/MM/dd")
private Date dateSlash;

@ExcelProperty
@DateTimeFormat("dd-MM-yyyy")
private LocalDate dateDash;

@ExcelProperty
@DateTimeFormat("yyyy-MM-dd HH:mm")
private LocalDateTime dateTimeMinute;
}

@Test
public void testMultiplePatternsPerRow(@TempDir Path tempDir) throws IOException {
MultiPatternSample s = new MultiPatternSample();
s.setDateSlash(new Date());
s.setDateDash(LocalDate.of(2024, 12, 31));
s.setDateTimeMinute(LocalDateTime.of(2025, 3, 4, 15, 20));
String file = tempDir.resolve("multi_pattern.xlsx").toString();
FastExcel.write(file, MultiPatternSample.class).sheet("MultiFormat").doWrite(Collections.singletonList(s));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To align with the new project naming conventions, please replace the usage of the deprecated FastExcel class with FesodSheet.

Suggested change
FastExcel.write(file, MultiPatternSample.class).sheet("MultiFormat").doWrite(Collections.singletonList(s));
FesodSheet.write(file, MultiPatternSample.class).sheet("MultiFormat").doWrite(Collections.singletonList(s));

try (FileInputStream fis = new FileInputStream(file);
XSSFWorkbook workbook = new XSSFWorkbook(fis)) {
Row row = workbook.getSheetAt(0).getRow(1);
assertEquals("yyyy/MM/dd", row.getCell(0).getCellStyle().getDataFormatString());
assertEquals("dd-MM-yyyy", row.getCell(1).getCellStyle().getDataFormatString());
assertEquals("yyyy-MM-dd HH:mm", row.getCell(2).getCellStyle().getDataFormatString());
}
}

/**
* Write Date with pattern, read to String field with annotation pattern, verify the read string matches the formatted value.
*/
@Data
static class WriteDateModel {
@ExcelProperty
@DateTimeFormat("yyyy-MM-dd HH:mm:ss")
private Date eventTime;
}

@Data
static class ReadStringModel {
@ExcelProperty
@DateTimeFormat("yyyy-MM-dd HH:mm:ss")
private String eventTime; // Should be formatted as string when reading
}

static class CapturingListener implements ReadListener<ReadStringModel> {
private final List<ReadStringModel> list = new ArrayList<>();

@Override
public void invoke(ReadStringModel data, AnalysisContext context) {
list.add(data);
}

@Override
public void doAfterAllAnalysed(AnalysisContext context) {}

List<ReadStringModel> getList() {
return list;
}
}
Comment on lines +144 to +175

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The classes WriteDateModel, ReadStringModel, and CapturingListener, along with the associated Javadoc, are defined but not used within this test file. This dead code should be removed to improve code clarity and maintainability.


/**
* Test null date field: should write blank cell and not throw exception if value is not set.
*/
@Data
static class NullDateSample {
@ExcelProperty
@DateTimeFormat("yyyy-MM-dd")
private Date mayBeNull;
}

@Test
public void testNullDateFieldWritesBlank(@TempDir Path tempDir) throws IOException {
NullDateSample sample = new NullDateSample();
String file = tempDir.resolve("null_date.xlsx").toString();
FastExcel.write(file, NullDateSample.class).sheet("Null").doWrite(Collections.singletonList(sample));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Please update this call to use FesodSheet instead of the deprecated FastExcel class, in line with the project's refactoring.

Suggested change
FastExcel.write(file, NullDateSample.class).sheet("Null").doWrite(Collections.singletonList(sample));
FesodSheet.write(file, NullDateSample.class).sheet("Null").doWrite(Collections.singletonList(sample));

try (FileInputStream fis = new FileInputStream(file);
XSSFWorkbook workbook = new XSSFWorkbook(fis)) {
Row row = workbook.getSheetAt(0).getRow(1);
assertNotNull(row, "expect row existing");
assertTrue(
StringUtils.isBlank(row.getCell(0).getStringCellValue()),
"Empty date field should write as blank cell");
}
}
}
49 changes: 0 additions & 49 deletions website/docs/help/large-data.md

This file was deleted.

20 changes: 11 additions & 9 deletions website/docs/introduce.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,25 @@ slug: /

## Introduction

**Apache Fesod (Incubating)** is a high-performance and memory-efficient Java library for reading and writing Excel
**Apache Fesod (Incubating)** is a high-performance and memory-efficient Java library for reading and writing
spreadsheet
files, designed to simplify development and ensure reliability.

Apache Fesod (Incubating) can provide developers and enterprises with great freedom and flexibility. We plan to
introduce more new features in the future to continually enhance user experience and tool usability. Apache Fesod (
Incubating) is committed to being your best choice for handling Excel files.
Incubating) is committed to being your best choice for handling spreadsheet files.

The name fesod(pronounced `/ˈfɛsɒd/`), an acronym for "fast easy spreadsheet and other documents" expresses the
project's origin, background and vision.

### Features

- **High-performance Reading and Writing**: Apache Fesod (Incubating) focuses on performance optimization, capable of
efficiently handling large-scale Excel data. Compared to some traditional Excel processing libraries, it can
efficiently handling large-scale spreadsheet data. Compared to some traditional spreadsheet processing libraries, it
can
significantly reduce memory consumption.
- **Simplicity and Ease of Use**: The library offers a simple and intuitive API, allowing developers to easily integrate
it into projects, whether for simple Excel operations or complex data processing.
it into projects, whether for simple spreadsheet operations or complex data processing.
- **Stream Operations**: Apache Fesod (Incubating) supports stream reading, minimizing the problem of loading large
amounts of data at once. This design is especially important when dealing with hundreds of thousands or even millions
of rows of data.
Expand All @@ -33,7 +35,7 @@ project's origin, background and vision.

### Read

Below is an example of reading an Excel document:
Below is an example of reading a spreadsheet document:

```java
// Implement the ReadListener interface to set up operations for reading data
Expand All @@ -51,14 +53,14 @@ public class DemoDataListener implements ReadListener<DemoData> {

public static void main(String[] args) {
String fileName = "demo.xlsx";
// Read Excel file
FastExcel.read(fileName, DemoData.class, new DemoDataListener()).sheet().doRead();
// Read file
Fesod.read(fileName, DemoData.class, new DemoDataListener()).sheet().doRead();
}
```

### Write

Below is a simple example of creating an Excel document:
Below is a simple example of creating a spreadsheet document:

```java
// Sample data class
Expand Down Expand Up @@ -89,6 +91,6 @@ private static List<DemoData> data() {
public static void main(String[] args) {
String fileName = "demo.xlsx";
// Create a "Template" sheet and write data
FastExcel.write(fileName, DemoData.class).sheet("Template").doWrite(data());
FesodSheet.write(fileName, DemoData.class).sheet("Template").doWrite(data());
}
```
16 changes: 8 additions & 8 deletions website/docs/quickstart/example.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ id: 'simple-example'
title: 'Simple example'
---

# Simple example
## Fesod Sheet Examples

## Read
### Read the spreadsheet

Below is an example of reading an Excel document:
Below is an example of reading a spreadsheet document:

```java
// Implement the ReadListener interface to set up operations for reading data
Expand All @@ -25,14 +25,14 @@ public class DemoDataListener implements ReadListener<DemoData> {

public static void main(String[] args) {
String fileName = "demo.xlsx";
// Read Excel file
FastExcel.read(fileName, DemoData.class, new DemoDataListener()).sheet().doRead();
// Read file
FesodSheet.read(fileName, DemoData.class, new DemoDataListener()).sheet().doRead();
}
```

### Write
### Write the spreadsheet

Below is a simple example of creating an Excel document:
Below is a simple example of creating a spreadsheet document:

```java
// Sample data class
Expand Down Expand Up @@ -63,6 +63,6 @@ private static List<DemoData> data() {
public static void main(String[] args) {
String fileName = "demo.xlsx";
// Create a "Template" sheet and write data
FastExcel.write(fileName, DemoData.class).sheet("Template").doWrite(data());
FesodSheet.write(fileName, DemoData.class).sheet("Template").doWrite(data());
}
```
Loading
Loading