Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
6e57362
feat: head international
GGBOUNDBOY Oct 20, 2025
d285839
feat: head international
GGBOUNDBOY Oct 20, 2025
628f70b
Merge branch 'main' into feature-il8n-2
delei Oct 20, 2025
ca5e74d
feat: head international
GGBOUNDBOY Oct 21, 2025
dee4d59
Merge remote-tracking branch 'origin/feature-il8n-2' into feature-il8n-2
GGBOUNDBOY Oct 21, 2025
87a5779
feat: head international
GGBOUNDBOY Oct 21, 2025
cf030d3
feat: head international
GGBOUNDBOY Oct 21, 2025
c55b63f
feat: head international 增加license header
GGBOUNDBOY Oct 21, 2025
6684619
Merge branch 'main' into feature-il8n-2
GGBOUNDBOY Oct 21, 2025
2631579
Update fesod/src/main/java/org/apache/fesod/excel/util/ClassUtils.java
GGBOUNDBOY Oct 21, 2025
dd04b9b
Update fesod/src/main/java/org/apache/fesod/excel/util/ClassUtils.java
GGBOUNDBOY Oct 21, 2025
e28ca45
Update fesod/src/main/java/org/apache/fesod/excel/util/ClassUtils.java
GGBOUNDBOY Oct 21, 2025
7101178
Update fesod/src/main/java/org/apache/fesod/excel/il8n/ExcelMessageSo…
GGBOUNDBOY Oct 21, 2025
25b1ec1
Update fesod-examples/src/test/java/org/apache/fesod/excel/demo/write…
GGBOUNDBOY Oct 21, 2025
17b1519
Update fesod/src/main/java/org/apache/fesod/excel/read/metadata/holde…
GGBOUNDBOY Oct 21, 2025
442a727
Update fesod-examples/src/test/java/org/apache/fesod/excel/demo/write…
GGBOUNDBOY Oct 21, 2025
494dd77
Update fesod-examples/src/test/java/org/apache/fesod/excel/demo/read/…
GGBOUNDBOY Oct 21, 2025
09db594
Update fesod/src/main/java/org/apache/fesod/excel/metadata/GlobalConf…
GGBOUNDBOY Oct 21, 2025
fa9b6aa
Update fesod/src/main/java/org/apache/fesod/excel/util/ClassUtils.java
GGBOUNDBOY Oct 21, 2025
2f143c7
feat: ai 修正代码后。再修正
GGBOUNDBOY Oct 21, 2025
d862ed0
feat: add file head
GGBOUNDBOY Oct 21, 2025
41fe57a
feat: code style
GGBOUNDBOY Oct 22, 2025
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
@@ -0,0 +1,55 @@
/*
* 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.excel.demo.read;

import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import org.apache.fesod.excel.i18n.ExcelMessageSource;

/**
* AutoMessageSource
*
* @author GGBOUD
* @date 2025/10/20
*/
public class AutoMessageSource implements ExcelMessageSource {
private static final Map<String, Map<Locale, String>> MESSAGE_MAP = new HashMap<>();

@Override
public String resolveCode(String code, Locale locale) {
Map<Locale, String> localeMap = MESSAGE_MAP.get(code);
if (localeMap == null) {
return code;
} else {
String message = localeMap.get(locale);
return message == null ? code : message;
}
}

@Override
public void addMessage(String code, Locale locale, String msg) {
MESSAGE_MAP.computeIfAbsent(code, (key) -> new HashMap<>(4)).put(locale, msg);
}

public void addMessages(Map<String, String> messages, Locale locale) {
messages.forEach((code, msg) -> addMessage(code, locale, msg));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* 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.excel.demo.read;

import com.alibaba.fastjson2.JSON;
import lombok.extern.slf4j.Slf4j;
import org.apache.fesod.excel.context.AnalysisContext;
import org.apache.fesod.excel.read.listener.ReadListener;

/**
* Il8nHeadDemoDataListener
*
* @author GGBOUD
* @date 2025/10/20
*/
@Slf4j
public class Il8nHeadDemoDataListener implements ReadListener<Il8nZhHeadDemoData> {

public Il8nHeadDemoDataListener() {}

@Override
public void invoke(Il8nZhHeadDemoData data, AnalysisContext context) {
log.info("Parsed one row of data: {}", JSON.toJSONString(data));
}

/**
* doAfterAllAnalysed
*
* @param context
*/
@Override
public void doAfterAllAnalysed(AnalysisContext context) {
log.info("All data has been parsed!");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* 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.excel.demo.read;

import java.util.Date;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import org.apache.fesod.excel.annotation.ExcelProperty;

/**
* 基础数据类.这里的排序和excel里面的排序一致
*
*
**/
@Getter
@Setter
@EqualsAndHashCode
public class Il8nZhHeadDemoData {
@ExcelProperty(value = {"head.str"})
private String string;

@ExcelProperty(value = {"head.date"})
private Date date;

@ExcelProperty(value = {"head.doubleData"})
private Double doubleData;

@ExcelProperty(value = {"head.str1"})
private String string1;
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.alibaba.fastjson2.JSON;
import java.io.File;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import lombok.extern.slf4j.Slf4j;
import org.apache.fesod.excel.ExcelReader;
Expand All @@ -44,8 +45,6 @@

/**
* Common approaches for reading Excel files
*
*
*/
@Slf4j
public class ReadTest {
Expand Down Expand Up @@ -404,6 +403,47 @@ public void noModelRead() {
FastExcel.read(fileName, new NoModelDataListener()).sheet().doRead();
}

/**
* Reading without creating objects
*/
@Test
public void il8nZhHeadRead() {
String fileName = TestFileUtil.getPath() + "demo" + File.separator + "il8n-head-demo-zh.xlsx";
AutoMessageSource autoMessageSource = new AutoMessageSource();
autoMessageSource.addMessage("head.str", Locale.CHINA, "这是个中文表头");
autoMessageSource.addMessage("head.date", Locale.CHINA, "Date");
autoMessageSource.addMessage("head.doubleData", Locale.CHINA, "Number");
autoMessageSource.addMessage("head.str", Locale.US, "This is a English head");
autoMessageSource.addMessage("head.date", Locale.US, "Date");
autoMessageSource.addMessage("head.doubleData", Locale.US, "Number");
FastExcel.read(fileName, Il8nZhHeadDemoData.class, new Il8nHeadDemoDataListener())
.locale(Locale.CHINA)
.messageResource(autoMessageSource)
.sheet()
.doRead();
}

/**
* Reading without creating objects
*/
@Test
public void il8nUsHeadRead() {
String fileName = TestFileUtil.getPath() + "demo" + File.separator + "il8n-head-demo-us.xlsx";
AutoMessageSource autoMessageSource = new AutoMessageSource();
autoMessageSource.addMessage("head.str", Locale.CHINA, "这是个中文表头");
autoMessageSource.addMessage("head.date", Locale.CHINA, "Date");
autoMessageSource.addMessage("head.doubleData", Locale.CHINA, "Number");
autoMessageSource.addMessage("head.str", Locale.US, "This is a English head");
autoMessageSource.addMessage("head.date", Locale.US, "Date");
autoMessageSource.addMessage("head.doubleData", Locale.US, "Number");
autoMessageSource.addMessage("head.str1", Locale.US, "这是个中文表头1");
FastExcel.read(fileName, Il8nZhHeadDemoData.class, new Il8nHeadDemoDataListener())
.locale(Locale.US)
.messageResource(autoMessageSource)
.sheet()
.doRead();
}

/**
* Custom modification of CSV configuration
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@
import java.net.URL;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.apache.fesod.excel.ExcelWriter;
import org.apache.fesod.excel.FastExcel;
import org.apache.fesod.excel.annotation.ExcelProperty;
Expand All @@ -35,13 +33,10 @@
import org.apache.fesod.excel.annotation.write.style.ColumnWidth;
import org.apache.fesod.excel.annotation.write.style.ContentRowHeight;
import org.apache.fesod.excel.annotation.write.style.HeadRowHeight;
import org.apache.fesod.excel.demo.read.AutoMessageSource;
import org.apache.fesod.excel.demo.read.Il8nZhHeadDemoData;
import org.apache.fesod.excel.enums.CellDataTypeEnum;
import org.apache.fesod.excel.metadata.data.CommentData;
import org.apache.fesod.excel.metadata.data.FormulaData;
import org.apache.fesod.excel.metadata.data.HyperlinkData;
import org.apache.fesod.excel.metadata.data.ImageData;
import org.apache.fesod.excel.metadata.data.RichTextStringData;
import org.apache.fesod.excel.metadata.data.WriteCellData;
import org.apache.fesod.excel.metadata.data.*;
Copy link

Copilot AI Oct 21, 2025

Choose a reason for hiding this comment

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

Replace wildcard import with explicit imports to improve code clarity and prevent potential naming conflicts.

Suggested change
import org.apache.fesod.excel.metadata.data.*;
import org.apache.fesod.excel.metadata.data.WriteCellData;
import org.apache.fesod.excel.metadata.data.WriteRowData;
import org.apache.fesod.excel.metadata.data.WriteSheetData;
import org.apache.fesod.excel.metadata.data.WriteTableData;

Copilot uses AI. Check for mistakes.
import org.apache.fesod.excel.util.BooleanUtils;
import org.apache.fesod.excel.util.FileUtils;
import org.apache.fesod.excel.util.ListUtils;
Expand All @@ -58,12 +53,7 @@
import org.apache.fesod.excel.write.metadata.style.WriteFont;
import org.apache.fesod.excel.write.style.HorizontalCellStyleStrategy;
import org.apache.fesod.excel.write.style.column.LongestMatchColumnWidthStyleStrategy;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.FillPatternType;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.*;
Copy link

Copilot AI Oct 21, 2025

Choose a reason for hiding this comment

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

Replace wildcard import with explicit imports to clearly document which POI classes are being used.

Suggested change
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.CreationHelper;
import org.apache.poi.ss.usermodel.DataFormat;
import org.apache.poi.ss.usermodel.FillPatternType;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;

Copilot uses AI. Check for mistakes.
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.streaming.SXSSFSheet;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -780,6 +770,32 @@ public void afterSheetDispose(SheetWriteHandlerContext context) {
System.out.println(fileName);
}

@Test
public void sheetIl8nHeadWriteTest() {
List<Locale> locales = new ArrayList<>();
locales.add(Locale.CHINA);
locales.add(Locale.US);
AutoMessageSource autoMessageSource = new AutoMessageSource();
autoMessageSource.addMessage("head.str", Locale.CHINA, "这是个中文表头");
autoMessageSource.addMessage("head.str1", Locale.CHINA, "这是个中文表头2");
autoMessageSource.addMessage("head.date", Locale.CHINA, "Date");
autoMessageSource.addMessage("head.doubleData", Locale.CHINA, "Number");
autoMessageSource.addMessage("head.str", Locale.US, "This is a English head");
autoMessageSource.addMessage("head.date", Locale.US, "Date");
autoMessageSource.addMessage("head.doubleData", Locale.US, "Number");
autoMessageSource.addMessage("head.str1", Locale.US, "这是个中文表头1");
for (Locale locale : locales) {
String fileName = TestFileUtil.getPath() + "simpleWrite" + System.currentTimeMillis() + locale.getLanguage()
+ ".xlsx";
FastExcel.write(fileName, Il8nZhHeadDemoData.class)
.locale(locale)
.messageResource(autoMessageSource)
.sheet("模板")
.doWrite(this::Il8nHeadDemoDataList);
System.out.println(fileName);
}
}

private List<LongestMatchColumnWidthData> dataLong() {
List<LongestMatchColumnWidthData> list = ListUtils.newArrayList();
for (int i = 0; i < 10; i++) {
Expand Down Expand Up @@ -855,4 +871,17 @@ private List<DemoData> dataHex() {
}
return list;
}

private List<Il8nZhHeadDemoData> Il8nHeadDemoDataList() {
List<Il8nZhHeadDemoData> list = ListUtils.newArrayList();
for (int i = 0; i < 10; i++) {
Il8nZhHeadDemoData data = new Il8nZhHeadDemoData();
data.setString("STRING" + i);
data.setDate(new Date());
data.setDoubleData(0.56);
data.setString1("测试000" + i);
list.add(data);
}
return list;
}
}
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* 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.excel.i18n;

import java.util.Locale;

/**
* ExcelMessageSource
*
* @author GGBOUD
* @date 2025/10/20
*/
public interface ExcelMessageSource {

/**
* resolveCode 转换code
*
* @param code
* @param locale
* @return
*/
String resolveCode(String code, Locale locale);

/**
* addMessage 增加词条
*
* @param code
* @param locale
* @param
*/
void addMessage(String code, Locale locale, String msg);
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ public AbstractHolder(BasicParameter basicParameter, AbstractHolder prentAbstrac
} else {
globalConfiguration.setFiledCacheLocation(basicParameter.getFiledCacheLocation());
}
globalConfiguration.setMessageSource(basicParameter.getMessageSource());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.Objects;
import org.apache.fesod.excel.converters.Converter;
import org.apache.fesod.excel.enums.CacheLocationEnum;
import org.apache.fesod.excel.i18n.ExcelMessageSource;
import org.apache.fesod.excel.util.ListUtils;

/**
Expand Down Expand Up @@ -100,6 +101,16 @@ public T locale(Locale locale) {
return self();
}

/**
* message resource
*
* @param excelMessageSource
* @return
*/
public T messageResource(ExcelMessageSource excelMessageSource) {
parameter().setMessageSource(excelMessageSource);
return self();
}
/**
* The cache used when parsing fields such as head.
* <p>
Expand Down
Loading