list = new ArrayList<>();
+ for (int i = 0; i < 10; i++) {
+ FillData fillData = new FillData();
+ fillData.setName("Zhang San" + i);
+ fillData.setNumber(5.2);
+ fillData.setDate(new Date());
+ list.add(fillData);
+ }
+ return list;
+ }
+}
diff --git a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/fill/FillData.java b/fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/fill/data/FillData.java
similarity index 92%
rename from fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/fill/FillData.java
rename to fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/fill/data/FillData.java
index a469793e3..d4ef417f4 100644
--- a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/fill/FillData.java
+++ b/fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/fill/data/FillData.java
@@ -17,7 +17,7 @@
* under the License.
*/
-package org.apache.fesod.sheet.demo.fill;
+package org.apache.fesod.sheet.examples.fill.data;
import java.util.Date;
import lombok.EqualsAndHashCode;
@@ -25,7 +25,7 @@
import lombok.Setter;
/**
- *
+ * Data class for fill examples.
*/
@Getter
@Setter
diff --git a/fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/quickstart/SimpleReadExample.java b/fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/quickstart/SimpleReadExample.java
new file mode 100644
index 000000000..61f9367b1
--- /dev/null
+++ b/fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/quickstart/SimpleReadExample.java
@@ -0,0 +1,63 @@
+/*
+ * 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.examples.quickstart;
+
+import com.alibaba.fastjson2.JSON;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.fesod.sheet.FesodSheet;
+import org.apache.fesod.sheet.examples.quickstart.data.DemoData;
+import org.apache.fesod.sheet.examples.util.ExampleFileUtil;
+import org.apache.fesod.sheet.read.listener.PageReadListener;
+
+/**
+ * Simplest way to read an Excel file.
+ */
+@Slf4j
+public class SimpleReadExample {
+
+ public static void main(String[] args) {
+ simpleRead();
+ }
+
+ /**
+ * Simplest way to read
+ *
+ * 1. Create an entity class corresponding to the Excel data structure. Refer to {@link DemoData}.
+ *
+ * 2. Since Fesod reads Excel files row by row, you need to create a callback listener for each row.
+ *
+ * 3. Directly read the file.
+ */
+ public static void simpleRead() {
+ String fileName = ExampleFileUtil.getExamplePath("demo.xlsx");
+ log.info("Reading file: {}", fileName);
+
+ // Specify the class to read the data, then read the first sheet.
+ FesodSheet.read(fileName, DemoData.class, new PageReadListener(dataList -> {
+ for (DemoData demoData : dataList) {
+ log.info("Read a row of data: {}", JSON.toJSONString(demoData));
+ }
+ }))
+ .sheet()
+ .doRead();
+
+ log.info("Successfully read file: {}", fileName);
+ }
+}
diff --git a/fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/quickstart/SimpleWriteExample.java b/fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/quickstart/SimpleWriteExample.java
new file mode 100644
index 000000000..936206a7b
--- /dev/null
+++ b/fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/quickstart/SimpleWriteExample.java
@@ -0,0 +1,67 @@
+/*
+ * 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.examples.quickstart;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.fesod.sheet.FesodSheet;
+import org.apache.fesod.sheet.examples.quickstart.data.DemoData;
+import org.apache.fesod.sheet.examples.util.ExampleFileUtil;
+
+/**
+ * Simplest way to write an Excel file.
+ */
+@Slf4j
+public class SimpleWriteExample {
+
+ public static void main(String[] args) {
+ simpleWrite();
+ }
+
+ /**
+ * Simplest way to write
+ *
+ * 1. Create an entity class corresponding to the Excel data structure. Refer to {@link DemoData}.
+ *
+ * 2. Directly write.
+ */
+ public static void simpleWrite() {
+ // Write to system temp directory for output files
+ String fileName = ExampleFileUtil.getTempPath("demo" + System.currentTimeMillis() + ".xlsx");
+
+ // Specify the class to write, then write to the first sheet named "Template"
+ FesodSheet.write(fileName, DemoData.class).sheet("Template").doWrite(data());
+ log.info("Successfully wrote file: {}", fileName);
+ }
+
+ private static List data() {
+ List list = new ArrayList<>();
+ for (int i = 0; i < 10; i++) {
+ DemoData data = new DemoData();
+ data.setString("String" + i);
+ data.setDate(new Date());
+ data.setDoubleData(0.56);
+ list.add(data);
+ }
+ return list;
+ }
+}
diff --git a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/temp/csv/CsvData.java b/fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/quickstart/data/DemoData.java
similarity index 77%
rename from fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/temp/csv/CsvData.java
rename to fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/quickstart/data/DemoData.java
index f7c8319d7..a11695c11 100644
--- a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/temp/csv/CsvData.java
+++ b/fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/quickstart/data/DemoData.java
@@ -17,7 +17,7 @@
* under the License.
*/
-package org.apache.fesod.sheet.temp.csv;
+package org.apache.fesod.sheet.examples.quickstart.data;
import java.util.Date;
import lombok.EqualsAndHashCode;
@@ -27,24 +27,32 @@
import org.apache.fesod.sheet.annotation.ExcelProperty;
/**
- * TODO
- *
- *
+ * Basic data class for quickstart examples.
*/
@Getter
@Setter
@EqualsAndHashCode
-public class CsvData {
- @ExcelProperty("字符串标题")
+public class DemoData {
+ /**
+ * String Title
+ */
+ @ExcelProperty("String Title")
private String string;
- @ExcelProperty("日期标题")
+ /**
+ * Date Title
+ */
+ @ExcelProperty("Date Title")
private Date date;
- @ExcelProperty("数字标题")
+ /**
+ * Number Title
+ */
+ @ExcelProperty("Number Title")
private Double doubleData;
+
/**
- * 忽略这个字段
+ * Ignore this field
*/
@ExcelIgnore
private String ignore;
diff --git a/fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/read/BasicReadExample.java b/fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/read/BasicReadExample.java
new file mode 100644
index 000000000..f9ccf4bac
--- /dev/null
+++ b/fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/read/BasicReadExample.java
@@ -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.sheet.examples.read;
+
+import lombok.extern.slf4j.Slf4j;
+import org.apache.fesod.sheet.FesodSheet;
+import org.apache.fesod.sheet.examples.read.data.DemoData;
+import org.apache.fesod.sheet.examples.read.listeners.DemoDataListener;
+import org.apache.fesod.sheet.examples.util.ExampleFileUtil;
+
+/**
+ * Basic example demonstrating how to read an Excel file.
+ */
+@Slf4j
+public class BasicReadExample {
+
+ public static void main(String[] args) {
+ basicRead();
+ }
+
+ /**
+ * Basic read using a listener.
+ */
+ public static void basicRead() {
+ String fileName = ExampleFileUtil.getExamplePath("demo.xlsx");
+ log.info("Reading file: {}", fileName);
+
+ // Specify the class to read the data, then read the first sheet.
+ FesodSheet.read(fileName, DemoData.class, new DemoDataListener())
+ .sheet()
+ .doRead();
+
+ log.info("Successfully read file: {}", fileName);
+ }
+}
diff --git a/fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/read/ConverterReadExample.java b/fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/read/ConverterReadExample.java
new file mode 100644
index 000000000..aa6df47b5
--- /dev/null
+++ b/fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/read/ConverterReadExample.java
@@ -0,0 +1,56 @@
+/*
+ * 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.examples.read;
+
+import com.alibaba.fastjson2.JSON;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.fesod.sheet.FesodSheet;
+import org.apache.fesod.sheet.examples.read.data.ConverterData;
+import org.apache.fesod.sheet.examples.util.ExampleFileUtil;
+import org.apache.fesod.sheet.read.listener.PageReadListener;
+
+/**
+ * Example demonstrating how to use converters when reading an Excel file.
+ */
+@Slf4j
+public class ConverterReadExample {
+
+ public static void main(String[] args) {
+ converterRead();
+ }
+
+ /**
+ * Read with converters.
+ */
+ public static void converterRead() {
+ String fileName = ExampleFileUtil.getExamplePath("demo.xlsx");
+ log.info("Reading file with converters: {}", fileName);
+
+ FesodSheet.read(fileName, ConverterData.class, new PageReadListener(dataList -> {
+ for (ConverterData data : dataList) {
+ log.info("Read a row of data with converter: {}", JSON.toJSONString(data));
+ }
+ }))
+ .sheet()
+ .doRead();
+
+ log.info("Successfully read file: {}", fileName);
+ }
+}
diff --git a/fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/read/ExceptionHandlingExample.java b/fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/read/ExceptionHandlingExample.java
new file mode 100644
index 000000000..21047fa6f
--- /dev/null
+++ b/fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/read/ExceptionHandlingExample.java
@@ -0,0 +1,51 @@
+/*
+ * 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.examples.read;
+
+import lombok.extern.slf4j.Slf4j;
+import org.apache.fesod.sheet.FesodSheet;
+import org.apache.fesod.sheet.examples.read.data.ExceptionDemoData;
+import org.apache.fesod.sheet.examples.read.listeners.ExceptionListener;
+import org.apache.fesod.sheet.examples.util.ExampleFileUtil;
+
+/**
+ * Example demonstrating how to handle exceptions when reading an Excel file.
+ */
+@Slf4j
+public class ExceptionHandlingExample {
+
+ public static void main(String[] args) {
+ exceptionRead();
+ }
+
+ /**
+ * Read with exception handling.
+ */
+ public static void exceptionRead() {
+ String fileName = ExampleFileUtil.getExamplePath("demo.xlsx");
+ log.info("Reading file with exception handling: {}", fileName);
+
+ FesodSheet.read(fileName, ExceptionDemoData.class, new ExceptionListener())
+ .sheet()
+ .doRead();
+
+ log.info("Successfully read file: {}", fileName);
+ }
+}
diff --git a/fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/read/IndexOrNameReadExample.java b/fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/read/IndexOrNameReadExample.java
new file mode 100644
index 000000000..176b63b2b
--- /dev/null
+++ b/fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/read/IndexOrNameReadExample.java
@@ -0,0 +1,56 @@
+/*
+ * 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.examples.read;
+
+import com.alibaba.fastjson2.JSON;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.fesod.sheet.FesodSheet;
+import org.apache.fesod.sheet.examples.read.data.IndexOrNameData;
+import org.apache.fesod.sheet.examples.util.ExampleFileUtil;
+import org.apache.fesod.sheet.read.listener.PageReadListener;
+
+/**
+ * Example demonstrating how to read an Excel file using column index or name.
+ */
+@Slf4j
+public class IndexOrNameReadExample {
+
+ public static void main(String[] args) {
+ indexOrNameRead();
+ }
+
+ /**
+ * Read using index or name.
+ */
+ public static void indexOrNameRead() {
+ String fileName = ExampleFileUtil.getExamplePath("demo.xlsx");
+ log.info("Reading file with index/name mapping: {}", fileName);
+
+ FesodSheet.read(fileName, IndexOrNameData.class, new PageReadListener(dataList -> {
+ for (IndexOrNameData data : dataList) {
+ log.info("Read a row of data with index or name: {}", JSON.toJSONString(data));
+ }
+ }))
+ .sheet()
+ .doRead();
+
+ log.info("Successfully read file: {}", fileName);
+ }
+}
diff --git a/fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/read/MultiSheetReadExample.java b/fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/read/MultiSheetReadExample.java
new file mode 100644
index 000000000..fd440e562
--- /dev/null
+++ b/fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/read/MultiSheetReadExample.java
@@ -0,0 +1,68 @@
+/*
+ * 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.examples.read;
+
+import lombok.extern.slf4j.Slf4j;
+import org.apache.fesod.sheet.ExcelReader;
+import org.apache.fesod.sheet.FesodSheet;
+import org.apache.fesod.sheet.examples.read.data.DemoData;
+import org.apache.fesod.sheet.examples.read.listeners.DemoDataListener;
+import org.apache.fesod.sheet.examples.util.ExampleFileUtil;
+import org.apache.fesod.sheet.read.metadata.ReadSheet;
+
+/**
+ * Example demonstrating how to read multiple sheets from an Excel file.
+ */
+@Slf4j
+public class MultiSheetReadExample {
+
+ public static void main(String[] args) {
+ repeatedRead();
+ }
+
+ /**
+ * Read multiple sheets.
+ */
+ public static void repeatedRead() {
+ String fileName = ExampleFileUtil.getExamplePath("demo.xlsx");
+ log.info("Reading multiple sheets from file: {}", fileName);
+
+ // 1. Read all sheets
+ FesodSheet.read(fileName, DemoData.class, new DemoDataListener()).doReadAll();
+ log.info("Read all sheets completed");
+
+ // 2. Read specific sheets
+ try (ExcelReader excelReader = FesodSheet.read(fileName).build()) {
+ // Create ReadSheet objects for each sheet you want to read.
+ ReadSheet readSheet1 = FesodSheet.readSheet(0)
+ .head(DemoData.class)
+ .registerReadListener(new DemoDataListener())
+ .build();
+ ReadSheet readSheet2 = FesodSheet.readSheet(1)
+ .head(DemoData.class)
+ .registerReadListener(new DemoDataListener())
+ .build();
+
+ // Read multiple sheets at once.
+ excelReader.read(readSheet1, readSheet2);
+ }
+ log.info("Successfully read file: {}", fileName);
+ }
+}
diff --git a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/temp/simple/HgListener.java b/fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/read/NoModelReadExample.java
similarity index 51%
rename from fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/temp/simple/HgListener.java
rename to fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/read/NoModelReadExample.java
index 93bca3cb5..58cb45953 100644
--- a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/temp/simple/HgListener.java
+++ b/fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/read/NoModelReadExample.java
@@ -17,35 +17,33 @@
* under the License.
*/
-package org.apache.fesod.sheet.temp.simple;
+package org.apache.fesod.sheet.examples.read;
-import com.alibaba.fastjson2.JSON;
-import java.util.Map;
import lombok.extern.slf4j.Slf4j;
-import org.apache.fesod.sheet.context.AnalysisContext;
-import org.apache.fesod.sheet.event.AnalysisEventListener;
+import org.apache.fesod.sheet.FesodSheet;
+import org.apache.fesod.sheet.examples.read.listeners.NoModelDataListener;
+import org.apache.fesod.sheet.examples.util.ExampleFileUtil;
/**
- * 模板的读取类
- *
- *
+ * Example demonstrating how to read an Excel file without a data model.
*/
@Slf4j
-public class HgListener extends AnalysisEventListener> {
+public class NoModelReadExample {
+
+ public static void main(String[] args) {
+ noModelRead();
+ }
/**
- * 每隔5条存储数据库,实际使用中可以100条,然后清理list ,方便内存回收
+ * Read without a model.
*/
- private static final int BATCH_COUNT = 5;
+ public static void noModelRead() {
+ String fileName = ExampleFileUtil.getExamplePath("demo.xlsx");
+ log.info("Reading file (no model): {}", fileName);
- @Override
- public void invoke(Map data, AnalysisContext context) {
- log.info("index:{}", context.readRowHolder().getRowIndex());
- log.info("解析到一条数据:{}", JSON.toJSONString(data));
- }
+ // No need to specify a class, just use NoModelDataListener.
+ FesodSheet.read(fileName, new NoModelDataListener()).sheet().doRead();
- @Override
- public void doAfterAllAnalysed(AnalysisContext context) {
- log.info("所有数据解析完成!");
+ log.info("Successfully read file: {}", fileName);
}
}
diff --git a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/write/CustomStringStringConverter.java b/fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/read/converters/CustomStringStringConverter.java
similarity index 80%
rename from fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/write/CustomStringStringConverter.java
rename to fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/read/converters/CustomStringStringConverter.java
index bce1f630c..907e7bb6a 100644
--- a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/write/CustomStringStringConverter.java
+++ b/fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/read/converters/CustomStringStringConverter.java
@@ -17,7 +17,7 @@
* under the License.
*/
-package org.apache.fesod.sheet.demo.write;
+package org.apache.fesod.sheet.examples.read.converters;
import org.apache.fesod.sheet.converters.Converter;
import org.apache.fesod.sheet.converters.ReadConverterContext;
@@ -26,11 +26,10 @@
import org.apache.fesod.sheet.metadata.data.WriteCellData;
/**
- * String and string converter
- *
- *
+ * Custom string converter for examples.
*/
public class CustomStringStringConverter implements Converter {
+
@Override
public Class> supportJavaTypeKey() {
return String.class;
@@ -41,23 +40,13 @@ public CellDataTypeEnum supportExcelTypeKey() {
return CellDataTypeEnum.STRING;
}
- /**
- * 这里是读的时候会调用 不用管
- *
- * @return
- */
@Override
public String convertToJavaData(ReadConverterContext> context) {
- return context.getReadCellData().getStringValue();
+ return "Custom:" + context.getReadCellData().getStringValue();
}
- /**
- * 这里是写的时候会调用 不用管
- *
- * @return
- */
@Override
public WriteCellData> convertToExcelData(WriteConverterContext context) {
- return new WriteCellData<>("自定义:" + context.getValue());
+ return new WriteCellData<>(context.getValue());
}
}
diff --git a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/read/ConverterData.java b/fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/read/data/ConverterData.java
similarity index 76%
rename from fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/read/ConverterData.java
rename to fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/read/data/ConverterData.java
index e8d67e74d..118886f3e 100644
--- a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/read/ConverterData.java
+++ b/fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/read/data/ConverterData.java
@@ -17,7 +17,7 @@
* under the License.
*/
-package org.apache.fesod.sheet.demo.read;
+package org.apache.fesod.sheet.examples.read.data;
import lombok.EqualsAndHashCode;
import lombok.Getter;
@@ -25,31 +25,30 @@
import org.apache.fesod.sheet.annotation.ExcelProperty;
import org.apache.fesod.sheet.annotation.format.DateTimeFormat;
import org.apache.fesod.sheet.annotation.format.NumberFormat;
+import org.apache.fesod.sheet.examples.read.converters.CustomStringStringConverter;
/**
- * Basic data class. The order here is consistent with the order in the Excel file.
- *
- *
- **/
+ * Data class for converter examples.
+ */
@Getter
@Setter
@EqualsAndHashCode
public class ConverterData {
/**
- * I use a custom converter. No matter what is passed from the database, I prepend "Custom:".
+ * Custom converter.
*/
@ExcelProperty(converter = CustomStringStringConverter.class)
private String string;
/**
- * I use a string to receive the date so that it can be formatted. I want to receive the date in the format of yyyy-MM-dd HH:mm:ss.
+ * Date format.
*/
@DateTimeFormat("yyyy-MM-dd HH:mm:ss")
private String date;
/**
- * I want to receive a number in percentage format.
+ * Number format.
*/
@NumberFormat("#.##%")
private String doubleData;
diff --git a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/temp/fill/FillData2.java b/fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/read/data/DemoDAO.java
similarity index 78%
rename from fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/temp/fill/FillData2.java
rename to fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/read/data/DemoDAO.java
index 82dd08bb7..c9f0bfc76 100644
--- a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/temp/fill/FillData2.java
+++ b/fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/read/data/DemoDAO.java
@@ -17,18 +17,16 @@
* under the License.
*/
-package org.apache.fesod.sheet.temp.fill;
+package org.apache.fesod.sheet.examples.read.data;
-import lombok.EqualsAndHashCode;
-import lombok.Getter;
-import lombok.Setter;
+import java.util.List;
/**
- *
+ * Mock DAO for examples.
*/
-@Getter
-@Setter
-@EqualsAndHashCode
-public class FillData2 {
- private String test;
+public class DemoDAO {
+
+ public void save(List list) {
+ // In actual use, you can use batch insert here.
+ }
}
diff --git a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/write/DemoData.java b/fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/read/data/DemoData.java
similarity index 93%
rename from fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/write/DemoData.java
rename to fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/read/data/DemoData.java
index bc0c31868..a79bdca44 100644
--- a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/write/DemoData.java
+++ b/fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/read/data/DemoData.java
@@ -17,7 +17,7 @@
* under the License.
*/
-package org.apache.fesod.sheet.demo.write;
+package org.apache.fesod.sheet.examples.read.data;
import java.util.Date;
import lombok.EqualsAndHashCode;
@@ -27,10 +27,8 @@
import org.apache.fesod.sheet.annotation.ExcelProperty;
/**
- * Basic data class
- *
- *
- **/
+ * Basic data class for read examples.
+ */
@Getter
@Setter
@EqualsAndHashCode
diff --git a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/read/ExceptionDemoData.java b/fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/read/data/ExceptionDemoData.java
similarity index 82%
rename from fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/read/ExceptionDemoData.java
rename to fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/read/data/ExceptionDemoData.java
index 77e0e0f70..9acac4710 100644
--- a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/read/ExceptionDemoData.java
+++ b/fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/read/data/ExceptionDemoData.java
@@ -17,7 +17,7 @@
* under the License.
*/
-package org.apache.fesod.sheet.demo.read;
+package org.apache.fesod.sheet.examples.read.data;
import java.util.Date;
import lombok.EqualsAndHashCode;
@@ -25,17 +25,14 @@
import lombok.Setter;
/**
- * Basic data class. The order here is consistent with the order in the Excel file.
- *
- *
- **/
+ * Data class for exception handling examples.
+ */
@Getter
@Setter
@EqualsAndHashCode
public class ExceptionDemoData {
-
/**
- * Using a Date to receive a string will definitely cause an error.
+ * Using a Date to receive a string will cause an error.
*/
private Date date;
}
diff --git a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/read/IndexOrNameData.java b/fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/read/data/IndexOrNameData.java
similarity index 77%
rename from fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/read/IndexOrNameData.java
rename to fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/read/data/IndexOrNameData.java
index 9290584e7..3a448ad4c 100644
--- a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/read/IndexOrNameData.java
+++ b/fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/read/data/IndexOrNameData.java
@@ -17,7 +17,7 @@
* under the License.
*/
-package org.apache.fesod.sheet.demo.read;
+package org.apache.fesod.sheet.examples.read.data;
import java.util.Date;
import lombok.EqualsAndHashCode;
@@ -26,22 +26,19 @@
import org.apache.fesod.sheet.annotation.ExcelProperty;
/**
- * Basic data class
- *
- *
- **/
+ * Data class for index or name matching examples.
+ */
@Getter
@Setter
@EqualsAndHashCode
public class IndexOrNameData {
/**
- * Force reading the third column. It is not recommended to use both index and name at the same time.
- * Either use index only or use name only for matching within a single object.
+ * Force reading the third column.
*/
@ExcelProperty(index = 2)
private Double doubleData;
/**
- * Match by name. Note that if the name is duplicated, only one field will be populated with data.
+ * Match by name.
*/
@ExcelProperty("String")
private String string;
diff --git a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/read/DemoDataListener.java b/fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/read/listeners/DemoDataListener.java
similarity index 61%
rename from fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/read/DemoDataListener.java
rename to fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/read/listeners/DemoDataListener.java
index d1574de19..1f900e868 100644
--- a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/read/DemoDataListener.java
+++ b/fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/read/listeners/DemoDataListener.java
@@ -17,29 +17,28 @@
* under the License.
*/
-package org.apache.fesod.sheet.demo.read;
+package org.apache.fesod.sheet.examples.read.listeners;
import com.alibaba.fastjson2.JSON;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
import org.apache.fesod.common.util.ListUtils;
import org.apache.fesod.sheet.context.AnalysisContext;
+import org.apache.fesod.sheet.examples.read.data.DemoDAO;
+import org.apache.fesod.sheet.examples.read.data.DemoData;
import org.apache.fesod.sheet.read.listener.ReadListener;
/**
- * Template reading class
- *
- *
+ * Template reading class.
+ *
+ * An important point is that DemoDataListener should not be managed by Spring.
+ * It needs to be newly created each time an Excel file is read.
*/
-// An important point is that DemoDataListener should not be managed by Spring.
-// It needs to be newly created each time an Excel file is read.
-// If Spring is used inside, it can be passed through the constructor.
@Slf4j
public class DemoDataListener implements ReadListener {
/**
- * Store data in the database every 5 records. In actual use, it can be 100 records,
- * and then clear the list to facilitate memory recycling.
+ * Store data in the database every 100 records.
*/
private static final int BATCH_COUNT = 100;
/**
@@ -47,19 +46,17 @@ public class DemoDataListener implements ReadListener {
*/
private List cachedDataList = ListUtils.newArrayListWithExpectedSize(BATCH_COUNT);
/**
- * Assume this is a DAO. Of course, if there is business logic, this can also be a service.
- * If the data does not need to be stored, this object is useless.
+ * Mock DAO
*/
private DemoDAO demoDAO;
public DemoDataListener() {
- // This is a demo, so a new instance is created here. In actual use with Spring,
- // please use the constructor with parameters below.
+ // This is a demo, so a new instance is created here.
demoDAO = new DemoDAO();
}
/**
- * If Spring is used, please use this constructor. When creating a Listener, the class managed by Spring needs to be passed in.
+ * If Spring is used, please use this constructor.
*
* @param demoDAO
*/
@@ -70,19 +67,15 @@ public DemoDataListener(DemoDAO demoDAO) {
/**
* This method will be called for each data parsed.
*
- * @param data one row value. It is same as {@link AnalysisContext#readRowHolder()}
+ * @param data one row value.
* @param context
*/
@Override
public void invoke(DemoData data, AnalysisContext context) {
log.info("Parsed one row of data: {}", JSON.toJSONString(data));
cachedDataList.add(data);
- // When the number of records reaches BATCH_COUNT, the data needs to be stored in the database to prevent tens
- // of
- // thousands of records from being held in memory, which can easily cause OutOfMemoryError (OOM).
if (cachedDataList.size() >= BATCH_COUNT) {
saveData();
- // Clear the list after storage
cachedDataList = ListUtils.newArrayListWithExpectedSize(BATCH_COUNT);
}
}
@@ -94,17 +87,15 @@ public void invoke(DemoData data, AnalysisContext context) {
*/
@Override
public void doAfterAllAnalysed(AnalysisContext context) {
- // Data needs to be saved here to ensure that any remaining data is stored in the database.
saveData();
log.info("All data has been parsed!");
}
/**
- * Store data in the database
+ * Save data to database.
*/
private void saveData() {
- log.info("{} records are being stored in the database!", cachedDataList.size());
+ log.info("{} records saved to database!", cachedDataList.size());
demoDAO.save(cachedDataList);
- log.info("Data has been successfully stored in the database!");
}
}
diff --git a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/read/DemoExceptionListener.java b/fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/read/listeners/ExceptionListener.java
similarity index 66%
rename from fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/read/DemoExceptionListener.java
rename to fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/read/listeners/ExceptionListener.java
index f6b0c0b30..48f307d81 100644
--- a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/read/DemoExceptionListener.java
+++ b/fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/read/listeners/ExceptionListener.java
@@ -17,7 +17,7 @@
* under the License.
*/
-package org.apache.fesod.sheet.demo.read;
+package org.apache.fesod.sheet.examples.read.listeners;
import com.alibaba.fastjson2.JSON;
import java.util.List;
@@ -25,37 +25,24 @@
import lombok.extern.slf4j.Slf4j;
import org.apache.fesod.common.util.ListUtils;
import org.apache.fesod.sheet.context.AnalysisContext;
+import org.apache.fesod.sheet.examples.read.data.ExceptionDemoData;
import org.apache.fesod.sheet.exception.ExcelDataConvertException;
import org.apache.fesod.sheet.metadata.data.ReadCellData;
import org.apache.fesod.sheet.read.listener.ReadListener;
/**
- * Read and convert exceptions.
- *
- *
+ * Listener for handling read and convert exceptions.
*/
@Slf4j
-public class DemoExceptionListener implements ReadListener {
+public class ExceptionListener implements ReadListener {
- /**
- * Save to the database every 5 records. In actual use, it can be set to 100 records, and then clear the list to facilitate memory recycling.
- */
- private static final int BATCH_COUNT = 5;
+ private static final int BATCH_COUNT = 100;
private List cachedDataList = ListUtils.newArrayListWithExpectedSize(BATCH_COUNT);
- /**
- * This interface will be called in case of conversion exceptions or other exceptions. If an exception is thrown here, reading will be stopped. If no exception is thrown, the next line will continue to be read.
- *
- * @param exception The exception that occurred.
- * @param context The analysis context.
- * @throws Exception If an exception needs to be propagated.
- */
@Override
public void onException(Exception exception, AnalysisContext context) {
log.error("Parsing failed, but continue parsing the next line: {}", exception.getMessage());
- // If it is a cell conversion exception, the specific row number can be obtained.
- // If the header information is needed, use it in conjunction with invokeHeadMap.
if (exception instanceof ExcelDataConvertException) {
ExcelDataConvertException excelDataConvertException = (ExcelDataConvertException) exception;
log.error(
@@ -66,12 +53,6 @@ public void onException(Exception exception, AnalysisContext context) {
}
}
- /**
- * This method will return the header row line by line.
- *
- * @param headMap The header map containing column index and cell data.
- * @param context The analysis context.
- */
@Override
public void invokeHead(Map> headMap, AnalysisContext context) {
log.info("Parsed a header row: {}", JSON.toJSONString(headMap));
@@ -80,6 +61,7 @@ public void invokeHead(Map> headMap, AnalysisContext co
@Override
public void invoke(ExceptionDemoData data, AnalysisContext context) {
log.info("Parsed a data row: {}", JSON.toJSONString(data));
+ cachedDataList.add(data);
if (cachedDataList.size() >= BATCH_COUNT) {
saveData();
cachedDataList = ListUtils.newArrayListWithExpectedSize(BATCH_COUNT);
@@ -92,11 +74,7 @@ public void doAfterAllAnalysed(AnalysisContext context) {
log.info("All data parsing completed!");
}
- /**
- * Save data to the database.
- */
private void saveData() {
- log.info("{} records, starting to save to the database!", cachedDataList.size());
- log.info("Data saved to the database successfully!");
+ log.info("{} records saved to database!", cachedDataList.size());
}
}
diff --git a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/read/NoModelDataListener.java b/fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/read/listeners/NoModelDataListener.java
similarity index 89%
rename from fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/read/NoModelDataListener.java
rename to fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/read/listeners/NoModelDataListener.java
index 16c805f8f..1178e8749 100644
--- a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/read/NoModelDataListener.java
+++ b/fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/read/listeners/NoModelDataListener.java
@@ -17,7 +17,7 @@
* under the License.
*/
-package org.apache.fesod.sheet.demo.read;
+package org.apache.fesod.sheet.examples.read.listeners;
import com.alibaba.fastjson2.JSON;
import java.util.List;
@@ -29,16 +29,14 @@
/**
* Directly receive data using a map.
- *
- *
*/
@Slf4j
public class NoModelDataListener extends AnalysisEventListener> {
/**
- * Save to the database every 5 records. In actual use, it can be set to 100 records, and then clear the list to facilitate memory recycling.
+ * Save to the database every 100 records.
*/
- private static final int BATCH_COUNT = 5;
+ private static final int BATCH_COUNT = 100;
private List> cachedDataList = ListUtils.newArrayListWithExpectedSize(BATCH_COUNT);
diff --git a/fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/util/ExampleDataGenerator.java b/fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/util/ExampleDataGenerator.java
new file mode 100644
index 000000000..8b0e8852d
--- /dev/null
+++ b/fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/util/ExampleDataGenerator.java
@@ -0,0 +1,59 @@
+/*
+ * 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.examples.util;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * Utility for generating example data.
+ */
+public class ExampleDataGenerator {
+
+ /**
+ * Generates a list of strings.
+ *
+ * @param count number of strings to generate
+ * @return list of strings
+ */
+ public static List generateStrings(int count) {
+ List list = new ArrayList<>();
+ for (int i = 0; i < count; i++) {
+ list.add("Data " + i);
+ }
+ return list;
+ }
+
+ /**
+ * Generates a list of dates.
+ *
+ * @param count number of dates to generate
+ * @return list of dates
+ */
+ public static List generateDates(int count) {
+ List list = new ArrayList<>();
+ long now = System.currentTimeMillis();
+ for (int i = 0; i < count; i++) {
+ list.add(new Date(now + i * 1000 * 60 * 60 * 24));
+ }
+ return list;
+ }
+}
diff --git a/fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/util/ExampleFileUtil.java b/fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/util/ExampleFileUtil.java
new file mode 100644
index 000000000..369836e62
--- /dev/null
+++ b/fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/util/ExampleFileUtil.java
@@ -0,0 +1,66 @@
+/*
+ * 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.examples.util;
+
+import java.io.File;
+import java.nio.file.Files;
+import lombok.SneakyThrows;
+
+/**
+ * Utility for example files.
+ */
+public class ExampleFileUtil {
+
+ public static final String EXAMPLE = "example";
+
+ public static String getPath() {
+ java.net.URL resource = ExampleFileUtil.class.getClassLoader().getResource("");
+ if (resource == null) {
+ throw new IllegalStateException("Cannot find classpath root resource");
+ }
+ return resource.getPath();
+ }
+
+ /**
+ * Get the path to a file in the example resource directory.
+ *
+ * @param fileName the file name relative to the example directory (e.g., "demo.xlsx" or "templates/simple.xlsx")
+ * @return the full path to the file
+ */
+ public static String getExamplePath(String fileName) {
+ java.net.URL resource = ExampleFileUtil.class.getClassLoader().getResource(EXAMPLE + "/" + fileName);
+ if (resource != null) {
+ return resource.getPath();
+ }
+ // Fallback to classpath root + example path
+ return getPath() + EXAMPLE + File.separator + fileName;
+ }
+
+ /**
+ * Get the path to write output files in the system temp directory.
+ *
+ * @param fileName the output file name
+ * @return the full path to the output file in temp directory
+ */
+ @SneakyThrows
+ public static String getTempPath(String fileName) {
+ return Files.createTempDirectory("fesod-sheet-examples").toAbsolutePath() + File.separator + fileName;
+ }
+}
diff --git a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/web/DownloadData.java b/fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/web/DownloadData.java
similarity index 81%
rename from fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/web/DownloadData.java
rename to fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/web/DownloadData.java
index 0cfe55918..05223b118 100644
--- a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/web/DownloadData.java
+++ b/fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/web/DownloadData.java
@@ -17,29 +17,21 @@
* under the License.
*/
-package org.apache.fesod.sheet.demo.web;
+package org.apache.fesod.sheet.examples.web;
import java.util.Date;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
-import org.apache.fesod.sheet.annotation.ExcelProperty;
/**
- * 基础数据类
- *
- *
- **/
+ * Data class for web download examples.
+ */
@Getter
@Setter
@EqualsAndHashCode
public class DownloadData {
- @ExcelProperty("字符串标题")
private String string;
-
- @ExcelProperty("日期标题")
private Date date;
-
- @ExcelProperty("数字标题")
private Double doubleData;
}
diff --git a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/web/FesodApplication.java b/fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/web/FesodWebApplication.java
similarity index 83%
rename from fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/web/FesodApplication.java
rename to fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/web/FesodWebApplication.java
index b20c65533..c41314b3d 100644
--- a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/web/FesodApplication.java
+++ b/fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/web/FesodWebApplication.java
@@ -17,15 +17,18 @@
* under the License.
*/
-package org.apache.fesod.sheet.demo.web;
+package org.apache.fesod.sheet.examples.web;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
+/**
+ * Spring Boot application for web examples.
+ */
@SpringBootApplication
-public class FesodApplication {
+public class FesodWebApplication {
public static void main(String[] args) {
- SpringApplication.run(FesodApplication.class, args);
+ SpringApplication.run(FesodWebApplication.class, args);
}
}
diff --git a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/web/UploadDAO.java b/fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/web/UploadDAO.java
similarity index 74%
rename from fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/web/UploadDAO.java
rename to fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/web/UploadDAO.java
index ad9a21aff..b4fb47da6 100644
--- a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/web/UploadDAO.java
+++ b/fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/web/UploadDAO.java
@@ -17,20 +17,18 @@
* under the License.
*/
-package org.apache.fesod.sheet.demo.web;
+package org.apache.fesod.sheet.examples.web;
import java.util.List;
import org.springframework.stereotype.Repository;
/**
- * 假设这个是你的DAO存储。当然还要这个类让spring管理,当然你不用需要存储,也不需要这个类。
- *
- *
- **/
+ * Mock DAO for web upload examples.
+ */
@Repository
public class UploadDAO {
public void save(List list) {
- // 如果是mybatis,尽量别直接调用多次insert,自己写一个mapper里面新增一个方法batchInsert,所有数据一次性插入
+ // In actual use, you can use batch insert here.
}
}
diff --git a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/web/UploadData.java b/fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/web/UploadData.java
similarity index 92%
rename from fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/web/UploadData.java
rename to fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/web/UploadData.java
index e60db3e4e..8a7629cf9 100644
--- a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/web/UploadData.java
+++ b/fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/web/UploadData.java
@@ -17,7 +17,7 @@
* under the License.
*/
-package org.apache.fesod.sheet.demo.web;
+package org.apache.fesod.sheet.examples.web;
import java.util.Date;
import lombok.EqualsAndHashCode;
@@ -25,10 +25,8 @@
import lombok.Setter;
/**
- * 基础数据类
- *
- *
- **/
+ * Data class for web upload examples.
+ */
@Getter
@Setter
@EqualsAndHashCode
diff --git a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/read/CellDataDemoHeadDataListener.java b/fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/web/UploadDataListener.java
similarity index 67%
rename from fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/read/CellDataDemoHeadDataListener.java
rename to fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/web/UploadDataListener.java
index f648a25a4..f4bcb7829 100644
--- a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/read/CellDataDemoHeadDataListener.java
+++ b/fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/web/UploadDataListener.java
@@ -17,7 +17,7 @@
* under the License.
*/
-package org.apache.fesod.sheet.demo.read;
+package org.apache.fesod.sheet.examples.web;
import com.alibaba.fastjson2.JSON;
import java.util.List;
@@ -27,22 +27,23 @@
import org.apache.fesod.sheet.read.listener.ReadListener;
/**
- * Read header
- *
- *
+ * Listener for web upload examples.
*/
@Slf4j
-public class CellDataDemoHeadDataListener implements ReadListener {
- /**
- * Store data to database every 5 records. In actual use, it can be 100 records, then clear the list to facilitate memory recycling
- */
+public class UploadDataListener implements ReadListener {
+
private static final int BATCH_COUNT = 100;
+ private List cachedDataList = ListUtils.newArrayListWithExpectedSize(BATCH_COUNT);
+ private UploadDAO uploadDAO;
- private List cachedDataList = ListUtils.newArrayListWithExpectedSize(BATCH_COUNT);
+ public UploadDataListener(UploadDAO uploadDAO) {
+ this.uploadDAO = uploadDAO;
+ }
@Override
- public void invoke(CellDataReadDemoData data, AnalysisContext context) {
- log.info("Parsed one record: {}", JSON.toJSONString(data));
+ public void invoke(UploadData data, AnalysisContext context) {
+ log.info("Parsed a data row: {}", JSON.toJSONString(data));
+ cachedDataList.add(data);
if (cachedDataList.size() >= BATCH_COUNT) {
saveData();
cachedDataList = ListUtils.newArrayListWithExpectedSize(BATCH_COUNT);
@@ -55,11 +56,8 @@ public void doAfterAllAnalysed(AnalysisContext context) {
log.info("All data parsing completed!");
}
- /**
- * Save data to database
- */
private void saveData() {
- log.info("{} records, starting to save to database!", cachedDataList.size());
- log.info("Successfully saved to database!");
+ log.info("{} records saved to database!", cachedDataList.size());
+ uploadDAO.save(cachedDataList);
}
}
diff --git a/fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/web/WebExampleController.java b/fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/web/WebExampleController.java
new file mode 100644
index 000000000..ab0e028b6
--- /dev/null
+++ b/fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/web/WebExampleController.java
@@ -0,0 +1,83 @@
+/*
+ * 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.examples.web;
+
+import java.io.IOException;
+import java.net.URLEncoder;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import javax.servlet.http.HttpServletResponse;
+import org.apache.fesod.sheet.FesodSheet;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.web.multipart.MultipartFile;
+
+/**
+ * Controller for web read and write examples.
+ */
+@Controller
+public class WebExampleController {
+
+ @Autowired
+ private UploadDAO uploadDAO;
+
+ /**
+ * File download.
+ */
+ @GetMapping("download")
+ public void download(HttpServletResponse response) throws IOException {
+ response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
+ response.setCharacterEncoding("utf-8");
+ String fileName = URLEncoder.encode("test", "UTF-8").replaceAll("\\+", "%20");
+ response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");
+
+ FesodSheet.write(response.getOutputStream(), DownloadData.class)
+ .sheet("Template")
+ .doWrite(data());
+ }
+
+ /**
+ * File upload.
+ */
+ @PostMapping("upload")
+ @ResponseBody
+ public String upload(MultipartFile file) throws IOException {
+ FesodSheet.read(file.getInputStream(), UploadData.class, new UploadDataListener(uploadDAO))
+ .sheet()
+ .doRead();
+ return "success";
+ }
+
+ private List data() {
+ List list = new ArrayList<>();
+ for (int i = 0; i < 10; i++) {
+ DownloadData data = new DownloadData();
+ data.setString("String" + i);
+ data.setDate(new Date());
+ data.setDoubleData(0.56);
+ list.add(data);
+ }
+ return list;
+ }
+}
diff --git a/fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/write/BasicWriteExample.java b/fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/write/BasicWriteExample.java
new file mode 100644
index 000000000..b52fde557
--- /dev/null
+++ b/fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/write/BasicWriteExample.java
@@ -0,0 +1,62 @@
+/*
+ * 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.examples.write;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.fesod.sheet.FesodSheet;
+import org.apache.fesod.sheet.examples.util.ExampleFileUtil;
+import org.apache.fesod.sheet.examples.write.data.DemoData;
+
+/**
+ * Basic example demonstrating how to write an Excel file.
+ */
+@Slf4j
+public class BasicWriteExample {
+
+ public static void main(String[] args) {
+ basicWrite();
+ }
+
+ /**
+ * Basic write.
+ */
+ public static void basicWrite() {
+ String fileName = ExampleFileUtil.getTempPath("basicWrite" + System.currentTimeMillis() + ".xlsx");
+
+ // Specify the class to write, then write to the first sheet.
+ FesodSheet.write(fileName, DemoData.class).sheet("Template").doWrite(data());
+ log.info("Successfully wrote file: {}", fileName);
+ }
+
+ private static List data() {
+ List list = new ArrayList<>();
+ for (int i = 0; i < 10; i++) {
+ DemoData data = new DemoData();
+ data.setString("String" + i);
+ data.setDate(new Date());
+ data.setDoubleData(0.56);
+ list.add(data);
+ }
+ return list;
+ }
+}
diff --git a/fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/write/ImageWriteExample.java b/fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/write/ImageWriteExample.java
new file mode 100644
index 000000000..281d20654
--- /dev/null
+++ b/fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/write/ImageWriteExample.java
@@ -0,0 +1,146 @@
+/*
+ * 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.examples.write;
+
+import java.io.File;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.fesod.sheet.FesodSheet;
+import org.apache.fesod.sheet.enums.CellDataTypeEnum;
+import org.apache.fesod.sheet.examples.util.ExampleFileUtil;
+import org.apache.fesod.sheet.examples.write.data.ImageDemoData;
+import org.apache.fesod.sheet.metadata.data.ImageData;
+import org.apache.fesod.sheet.metadata.data.WriteCellData;
+import org.apache.fesod.sheet.util.FileUtils;
+
+/**
+ * Example demonstrating how to export images to an Excel file.
+ *
+ * This example shows:
+ *
+ * Multiple ways to add images: File, InputStream, String path, byte[], URL
+ * Advanced image positioning with WriteCellData
+ * Adding multiple images to a single cell with custom positioning
+ * Combining images with text in the same cell
+ *
+ *
+ * Important Notes:
+ *
+ * All images will be loaded into memory. For large numbers of images, consider:
+ *
+ * Uploading images to cloud storage (e.g., AWS S3, Aliyun OSS) and using URLs
+ * Using image compression tools like Thumbnailator
+ *
+ *
+ *
+ */
+@Slf4j
+public class ImageWriteExample {
+
+ public static void main(String[] args) throws Exception {
+ imageWrite();
+ }
+
+ /**
+ * Demonstrates how to write images to Excel in various formats.
+ *
+ * @throws Exception if file operations fail
+ */
+ public static void imageWrite() throws Exception {
+ String fileName = ExampleFileUtil.getTempPath("imageWrite" + System.currentTimeMillis() + ".xlsx");
+
+ // Note: All images will be loaded into memory. For large volumes, consider:
+ // 1. Upload images to cloud storage (e.g., https://www.aliyun.com/product/oss) and use URLs
+ // 2. Use image compression tools like: https://github.com/coobird/thumbnailator
+
+ String imagePath = ExampleFileUtil.getPath() + "example/sample-data" + File.separator + "img.jpg";
+ try (InputStream inputStream = FileUtils.openInputStream(new File(imagePath))) {
+ List list = new ArrayList<>();
+ ImageDemoData imageDemoData = new ImageDemoData();
+ list.add(imageDemoData);
+
+ // Five types of image export - in practice, choose only one method
+ imageDemoData.setByteArray(FileUtils.readFileToByteArray(new File(imagePath)));
+ imageDemoData.setFile(new File(imagePath));
+ imageDemoData.setString(imagePath);
+ imageDemoData.setInputStream(inputStream);
+ imageDemoData.setUrl(new URL("https://poi.apache.org/images/project-header.png"));
+
+ // Advanced example demonstrating:
+ // - Adding text to the cell in addition to images
+ // - Adding 2 images to the same cell
+ // - First image aligned to the left
+ // - Second image aligned to the right and spanning into adjacent cells
+ WriteCellData writeCellData = new WriteCellData<>();
+ imageDemoData.setWriteCellDataFile(writeCellData);
+ // Can be set to EMPTY if no additional data is needed
+ writeCellData.setType(CellDataTypeEnum.STRING);
+ writeCellData.setStringValue("Additional text content");
+
+ // Can add multiple images to a single cell
+ List imageDataList = new ArrayList<>();
+ ImageData imageData = new ImageData();
+ imageDataList.add(imageData);
+ writeCellData.setImageDataList(imageDataList);
+ // Set image as binary data
+ imageData.setImage(FileUtils.readFileToByteArray(new File(imagePath)));
+ // Set image type
+ imageData.setImageType(ImageData.ImageType.PICTURE_TYPE_PNG);
+ // Top, Right, Bottom, Left margins
+ // Similar to CSS margin
+ // Note: Setting values too large (exceeding cell size) may cause repair prompts when opening.
+ // No perfect solution found yet.
+ imageData.setTop(5);
+ imageData.setRight(40);
+ imageData.setBottom(5);
+ imageData.setLeft(5);
+
+ // Add second image
+ imageData = new ImageData();
+ imageDataList.add(imageData);
+ writeCellData.setImageDataList(imageDataList);
+ imageData.setImage(FileUtils.readFileToByteArray(new File(imagePath)));
+ imageData.setImageType(ImageData.ImageType.PICTURE_TYPE_PNG);
+ imageData.setTop(5);
+ imageData.setRight(5);
+ imageData.setBottom(5);
+ imageData.setLeft(50);
+ // Position the image to span from current cell to the cell on its right
+ // Starting point is relative to current cell (0 - can be omitted)
+ imageData.setRelativeFirstRowIndex(0);
+ imageData.setRelativeFirstColumnIndex(0);
+ imageData.setRelativeLastRowIndex(0);
+ // The first 3 can be omitted. This one must be set - the ending position
+ // needs to move one column to the right relative to the current cell
+ // This means the image will cover the current cell and the next cell to its right
+ imageData.setRelativeLastColumnIndex(1);
+
+ // Write data
+ FesodSheet.write(fileName, ImageDemoData.class).sheet().doWrite(list);
+ log.info("Successfully wrote image file: {}", fileName);
+ // If image resources are inaccessible, XLSX format may error: SXSSFWorkbook - Failed to dispose sheet
+ // Consider declaring as XLS format in such cases:
+ // FesodSheet.write(fileName, ImageDemoData.class).excelType(ExcelTypeEnum.XLS).sheet().doWrite(list);
+ }
+ }
+}
diff --git a/fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/write/MergeWriteExample.java b/fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/write/MergeWriteExample.java
new file mode 100644
index 000000000..21fafa117
--- /dev/null
+++ b/fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/write/MergeWriteExample.java
@@ -0,0 +1,75 @@
+/*
+ * 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.examples.write;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.fesod.sheet.FesodSheet;
+import org.apache.fesod.sheet.examples.util.ExampleFileUtil;
+import org.apache.fesod.sheet.examples.write.data.DemoMergeData;
+import org.apache.fesod.sheet.write.merge.LoopMergeStrategy;
+
+/**
+ * Example demonstrating how to merge cells when writing an Excel file.
+ */
+@Slf4j
+public class MergeWriteExample {
+
+ public static void main(String[] args) {
+ mergeWrite();
+ }
+
+ /**
+ * Write with merged cells.
+ */
+ public static void mergeWrite() {
+ String fileName = ExampleFileUtil.getTempPath("mergeWrite" + System.currentTimeMillis() + ".xlsx");
+
+ // Method 1: Use annotations (see DemoMergeData)
+ FesodSheet.write(fileName, DemoMergeData.class)
+ .sheet("Annotation Merge")
+ .doWrite(data());
+ log.info("Successfully wrote file: {}", fileName);
+
+ // Method 2: Use a merge strategy
+ fileName = ExampleFileUtil.getTempPath("mergeWriteStrategy" + System.currentTimeMillis() + ".xlsx");
+ // Merge every 2 rows in the 0th column.
+ LoopMergeStrategy loopMergeStrategy = new LoopMergeStrategy(2, 0);
+ FesodSheet.write(fileName, DemoMergeData.class)
+ .registerWriteHandler(loopMergeStrategy)
+ .sheet("Strategy Merge")
+ .doWrite(data());
+ log.info("Successfully wrote file: {}", fileName);
+ }
+
+ private static List data() {
+ List list = new ArrayList<>();
+ for (int i = 0; i < 10; i++) {
+ DemoMergeData data = new DemoMergeData();
+ data.setString("String" + (i / 2)); // Same string for merged rows
+ data.setDate(new Date());
+ data.setDoubleData(0.56);
+ list.add(data);
+ }
+ return list;
+ }
+}
diff --git a/fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/write/StyleWriteExample.java b/fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/write/StyleWriteExample.java
new file mode 100644
index 000000000..c11bfd540
--- /dev/null
+++ b/fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/write/StyleWriteExample.java
@@ -0,0 +1,61 @@
+/*
+ * 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.examples.write;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.fesod.sheet.FesodSheet;
+import org.apache.fesod.sheet.examples.util.ExampleFileUtil;
+import org.apache.fesod.sheet.examples.write.data.DemoStyleData;
+
+/**
+ * Example demonstrating how to set styles when writing an Excel file.
+ */
+@Slf4j
+public class StyleWriteExample {
+
+ public static void main(String[] args) {
+ styleWrite();
+ }
+
+ /**
+ * Write with styles.
+ */
+ public static void styleWrite() {
+ String fileName = ExampleFileUtil.getTempPath("styleWrite" + System.currentTimeMillis() + ".xlsx");
+
+ FesodSheet.write(fileName, DemoStyleData.class).sheet("Template").doWrite(data());
+ log.info("Successfully wrote file: {}", fileName);
+ }
+
+ private static List data() {
+ List list = new ArrayList<>();
+ for (int i = 0; i < 10; i++) {
+ DemoStyleData data = new DemoStyleData();
+ data.setString("String" + i);
+ data.setDate(new Date());
+ data.setDoubleData(0.56);
+ list.add(data);
+ }
+ return list;
+ }
+}
diff --git a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/temp/DemoData2.java b/fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/write/data/DemoData.java
similarity index 71%
rename from fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/temp/DemoData2.java
rename to fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/write/data/DemoData.java
index 9a56c22b3..016c27239 100644
--- a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/temp/DemoData2.java
+++ b/fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/write/data/DemoData.java
@@ -17,38 +17,38 @@
* under the License.
*/
-package org.apache.fesod.sheet.temp;
+package org.apache.fesod.sheet.examples.write.data;
-import java.math.BigDecimal;
import java.util.Date;
-import lombok.EqualsAndHashCode;
-import lombok.Getter;
-import lombok.Setter;
+import lombok.Data;
import org.apache.fesod.sheet.annotation.ExcelIgnore;
import org.apache.fesod.sheet.annotation.ExcelProperty;
/**
- * 基础数据类
- *
- *
- **/
-@Getter
-@Setter
-@EqualsAndHashCode
-public class DemoData2 {
- @ExcelProperty("字符串标题")
+ * Basic data class for write examples.
+ */
+@Data
+public class DemoData {
+ /**
+ * String Title
+ */
+ @ExcelProperty("String Title")
private String string;
- @ExcelProperty("日期标题")
+ /**
+ * Date Title
+ */
+ @ExcelProperty("Date Title")
private Date date;
- @ExcelProperty("数字标题")
+ /**
+ * Number Title
+ */
+ @ExcelProperty("Number Title")
private Double doubleData;
- @ExcelProperty("数字标题2")
- private BigDecimal bigDecimal;
/**
- * 忽略这个字段
+ * Ignore this field
*/
@ExcelIgnore
private String ignore;
diff --git a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/write/DemoMergeData.java b/fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/write/data/DemoMergeData.java
similarity index 81%
rename from fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/write/DemoMergeData.java
rename to fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/write/data/DemoMergeData.java
index 0e33c2071..1ae9339dc 100644
--- a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/write/DemoMergeData.java
+++ b/fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/write/data/DemoMergeData.java
@@ -17,7 +17,7 @@
* under the License.
*/
-package org.apache.fesod.sheet.demo.write;
+package org.apache.fesod.sheet.examples.write.data;
import java.util.Date;
import lombok.EqualsAndHashCode;
@@ -27,17 +27,15 @@
import org.apache.fesod.sheet.annotation.write.style.ContentLoopMerge;
/**
- * Style data class
- *
- *
- **/
+ * Data class for merge examples.
+ */
@Getter
@Setter
@EqualsAndHashCode
-// Merge columns 2-3 of rows 6-7 into one cell
-// @OnceAbsoluteMerge(firstRowIndex = 5, lastRowIndex = 6, firstColumnIndex = 1, lastColumnIndex = 2)
public class DemoMergeData {
- // Merge this column every 2 rows
+ /**
+ * Merge cells every 2 rows in this column.
+ */
@ContentLoopMerge(eachRow = 2)
@ExcelProperty("String Title")
private String string;
@@ -45,6 +43,6 @@ public class DemoMergeData {
@ExcelProperty("Date Title")
private Date date;
- @ExcelProperty("Double Title")
+ @ExcelProperty("Number Title")
private Double doubleData;
}
diff --git a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/write/DemoStyleData.java b/fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/write/data/DemoStyleData.java
similarity index 85%
rename from fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/write/DemoStyleData.java
rename to fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/write/data/DemoStyleData.java
index 3b21486f3..2127ceb28 100644
--- a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/write/DemoStyleData.java
+++ b/fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/write/data/DemoStyleData.java
@@ -17,7 +17,7 @@
* under the License.
*/
-package org.apache.fesod.sheet.demo.write;
+package org.apache.fesod.sheet.examples.write.data;
import java.util.Date;
import lombok.EqualsAndHashCode;
@@ -31,29 +31,19 @@
import org.apache.fesod.sheet.enums.poi.FillPatternTypeEnum;
/**
- * Style data class
- *
- *
- **/
+ * Data class for style examples.
+ */
@Getter
@Setter
@EqualsAndHashCode
-// Head background red
@HeadStyle(fillPatternType = FillPatternTypeEnum.SOLID_FOREGROUND, fillForegroundColor = 10)
-// Head font size 20
@HeadFontStyle(fontHeightInPoints = 20)
-// Content background green
@ContentStyle(fillPatternType = FillPatternTypeEnum.SOLID_FOREGROUND, fillForegroundColor = 17)
-// Content font size 20
@ContentFontStyle(fontHeightInPoints = 20)
public class DemoStyleData {
- // String head background pink
@HeadStyle(fillPatternType = FillPatternTypeEnum.SOLID_FOREGROUND, fillForegroundColor = 14)
- // String head font size 30
@HeadFontStyle(fontHeightInPoints = 30)
- // String content background sky blue
@ContentStyle(fillPatternType = FillPatternTypeEnum.SOLID_FOREGROUND, fillForegroundColor = 40)
- // String content font size 30
@ContentFontStyle(fontHeightInPoints = 30)
@ExcelProperty("String Title")
private String string;
@@ -61,6 +51,6 @@ public class DemoStyleData {
@ExcelProperty("Date Title")
private Date date;
- @ExcelProperty("Double Title")
+ @ExcelProperty("Number Title")
private Double doubleData;
}
diff --git a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/write/ImageDemoData.java b/fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/write/data/ImageDemoData.java
similarity index 84%
rename from fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/write/ImageDemoData.java
rename to fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/write/data/ImageDemoData.java
index 722d3ee50..c935b1ddd 100644
--- a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/write/ImageDemoData.java
+++ b/fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/write/data/ImageDemoData.java
@@ -17,7 +17,7 @@
* under the License.
*/
-package org.apache.fesod.sheet.demo.write;
+package org.apache.fesod.sheet.examples.write.data;
import java.io.File;
import java.io.InputStream;
@@ -32,7 +32,7 @@
import org.apache.fesod.sheet.metadata.data.WriteCellData;
/**
- * Image export class
+ * Data class for image export examples.
*/
@Getter
@Setter
@@ -43,23 +43,19 @@ public class ImageDemoData {
private File file;
private InputStream inputStream;
/**
- * If it is a String type, a converter must be specified; String is converted to String by default.
+ * If string type, a converter must be specified.
*/
@ExcelProperty(converter = StringImageConverter.class)
private String string;
private byte[] byteArray;
/**
- * Export by URL
- *
- * @since 2.1.1
+ * Export by URL.
*/
private URL url;
/**
- * Export by file and set the export location.
- *
- * @since 3.0.0-beta1
+ * Export by file and set the export position.
*/
private WriteCellData writeCellDataFile;
}
diff --git a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/write/CommentWriteHandler.java b/fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/write/handlers/CommentWriteHandler.java
similarity index 84%
rename from fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/write/CommentWriteHandler.java
rename to fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/write/handlers/CommentWriteHandler.java
index af2063c31..b7d9c0af3 100644
--- a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/write/CommentWriteHandler.java
+++ b/fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/write/handlers/CommentWriteHandler.java
@@ -17,7 +17,7 @@
* under the License.
*/
-package org.apache.fesod.sheet.demo.write;
+package org.apache.fesod.sheet.examples.write.handlers;
import lombok.extern.slf4j.Slf4j;
import org.apache.fesod.common.util.BooleanUtils;
@@ -30,9 +30,7 @@
import org.apache.poi.xssf.usermodel.XSSFRichTextString;
/**
- * Custom handler. Add comment to the header of the first row.
- *
- *
+ * Custom row write handler for adding comments.
*/
@Slf4j
public class CommentWriteHandler implements RowWriteHandler {
@@ -42,12 +40,10 @@ public void afterRowDispose(RowWriteHandlerContext context) {
if (BooleanUtils.isTrue(context.getHead())) {
Sheet sheet = context.getWriteSheetHolder().getSheet();
Drawing> drawingPatriarch = sheet.createDrawingPatriarch();
- // Create a comment in the first row, second column
+ // Create a comment in the first row, second column.
Comment comment =
drawingPatriarch.createCellComment(new XSSFClientAnchor(0, 0, 0, 0, (short) 1, 0, (short) 2, 1));
- // Input comment information
- comment.setString(new XSSFRichTextString("Create comment!"));
- // Add comment to cell object
+ comment.setString(new XSSFRichTextString("Created a comment!"));
sheet.getRow(0).getCell(1).setCellComment(comment);
}
}
diff --git a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/write/CustomCellWriteHandler.java b/fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/write/handlers/CustomCellWriteHandler.java
similarity index 87%
rename from fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/write/CustomCellWriteHandler.java
rename to fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/write/handlers/CustomCellWriteHandler.java
index 01dfc4a33..497baf6a8 100644
--- a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/write/CustomCellWriteHandler.java
+++ b/fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/write/handlers/CustomCellWriteHandler.java
@@ -17,7 +17,7 @@
* under the License.
*/
-package org.apache.fesod.sheet.demo.write;
+package org.apache.fesod.sheet.examples.write.handlers;
import lombok.extern.slf4j.Slf4j;
import org.apache.fesod.common.util.BooleanUtils;
@@ -29,9 +29,7 @@
import org.apache.poi.ss.usermodel.Hyperlink;
/**
- * Custom handler
- *
- *
+ * Custom cell write handler for examples.
*/
@Slf4j
public class CustomCellWriteHandler implements CellWriteHandler {
@@ -39,13 +37,12 @@ public class CustomCellWriteHandler implements CellWriteHandler {
@Override
public void afterCellDispose(CellWriteHandlerContext context) {
Cell cell = context.getCell();
- // Can perform any operation on the cell here
- log.info("Finished writing row {}, column {}", cell.getRowIndex(), cell.getColumnIndex());
+ log.info("Row {}, Column {} write completed.", cell.getRowIndex(), cell.getColumnIndex());
if (BooleanUtils.isTrue(context.getHead()) && cell.getColumnIndex() == 0) {
CreationHelper createHelper =
context.getWriteSheetHolder().getSheet().getWorkbook().getCreationHelper();
Hyperlink hyperlink = createHelper.createHyperlink(HyperlinkType.URL);
- hyperlink.setAddress("https://github.com/fast-excel/fastexcel");
+ hyperlink.setAddress("https://github.com/apache/fesod");
cell.setHyperlink(hyperlink);
}
}
diff --git a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/write/CustomSheetWriteHandler.java b/fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/write/handlers/CustomSheetWriteHandler.java
similarity index 82%
rename from fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/write/CustomSheetWriteHandler.java
rename to fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/write/handlers/CustomSheetWriteHandler.java
index 02c28ec25..e53721263 100644
--- a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/write/CustomSheetWriteHandler.java
+++ b/fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/write/handlers/CustomSheetWriteHandler.java
@@ -17,7 +17,7 @@
* under the License.
*/
-package org.apache.fesod.sheet.demo.write;
+package org.apache.fesod.sheet.examples.write.handlers;
import lombok.extern.slf4j.Slf4j;
import org.apache.fesod.sheet.write.handler.SheetWriteHandler;
@@ -28,19 +28,16 @@
import org.apache.poi.ss.util.CellRangeAddressList;
/**
- * Custom handler. Add dropdown to first column of first and second data rows, displaying "Test1", "Test2"
- *
- *
+ * Custom sheet write handler for examples.
*/
@Slf4j
public class CustomSheetWriteHandler implements SheetWriteHandler {
@Override
public void afterSheetCreate(SheetWriteHandlerContext context) {
- log.info("Sheet {} write success.", context.getWriteSheetHolder().getSheetNo());
+ log.info("Sheet {} write successful.", context.getWriteSheetHolder().getSheetNo());
- // Set range for first column, first and second data rows. Since the first row is head, the data is actually in
- // the 2nd and 3rd rows.
+ // Add a dropdown list to the first column of the second and third rows.
CellRangeAddressList cellRangeAddressList = new CellRangeAddressList(1, 2, 0, 0);
DataValidationHelper helper = context.getWriteSheetHolder().getSheet().getDataValidationHelper();
DataValidationConstraint constraint = helper.createExplicitListConstraint(new String[] {"Test1", "Test2"});
diff --git a/fesod-examples/fesod-sheet-examples/src/test/resources/demo/demo.xlsx b/fesod-examples/fesod-sheet-examples/src/main/resources/example/demo.xlsx
similarity index 100%
rename from fesod-examples/fesod-sheet-examples/src/test/resources/demo/demo.xlsx
rename to fesod-examples/fesod-sheet-examples/src/main/resources/example/demo.xlsx
diff --git a/fesod-examples/fesod-sheet-examples/src/test/resources/converter/img.jpg b/fesod-examples/fesod-sheet-examples/src/main/resources/example/sample-data/img.jpg
similarity index 100%
rename from fesod-examples/fesod-sheet-examples/src/test/resources/converter/img.jpg
rename to fesod-examples/fesod-sheet-examples/src/main/resources/example/sample-data/img.jpg
diff --git a/fesod-examples/fesod-sheet-examples/src/test/resources/demo/fill/list.xlsx b/fesod-examples/fesod-sheet-examples/src/main/resources/example/templates/list.xlsx
similarity index 100%
rename from fesod-examples/fesod-sheet-examples/src/test/resources/demo/fill/list.xlsx
rename to fesod-examples/fesod-sheet-examples/src/main/resources/example/templates/list.xlsx
diff --git a/fesod-examples/fesod-sheet-examples/src/test/resources/demo/fill/simple.xlsx b/fesod-examples/fesod-sheet-examples/src/main/resources/example/templates/simple.xlsx
similarity index 100%
rename from fesod-examples/fesod-sheet-examples/src/test/resources/demo/fill/simple.xlsx
rename to fesod-examples/fesod-sheet-examples/src/main/resources/example/templates/simple.xlsx
diff --git a/fesod-examples/fesod-sheet-examples/src/test/resources/logback.xml b/fesod-examples/fesod-sheet-examples/src/main/resources/logback.xml
similarity index 84%
rename from fesod-examples/fesod-sheet-examples/src/test/resources/logback.xml
rename to fesod-examples/fesod-sheet-examples/src/main/resources/logback.xml
index 6ef9578b8..b18f5687b 100644
--- a/fesod-examples/fesod-sheet-examples/src/test/resources/logback.xml
+++ b/fesod-examples/fesod-sheet-examples/src/main/resources/logback.xml
@@ -20,16 +20,17 @@
-->
-
-
- ${CONSOLE_LOG_PATTERN}
+ %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
utf8
-
+
+
+
+
diff --git a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/fill/FillTest.java b/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/fill/FillTest.java
deleted file mode 100644
index 1d65a91cf..000000000
--- a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/fill/FillTest.java
+++ /dev/null
@@ -1,302 +0,0 @@
-/*
- * 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.demo.fill;
-
-import java.io.File;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import org.apache.fesod.common.util.ListUtils;
-import org.apache.fesod.common.util.MapUtils;
-import org.apache.fesod.sheet.ExcelWriter;
-import org.apache.fesod.sheet.FesodSheet;
-import org.apache.fesod.sheet.enums.WriteDirectionEnum;
-import org.apache.fesod.sheet.util.TestFileUtil;
-import org.apache.fesod.sheet.write.handler.SheetWriteHandler;
-import org.apache.fesod.sheet.write.handler.context.SheetWriteHandlerContext;
-import org.apache.fesod.sheet.write.metadata.WriteSheet;
-import org.apache.fesod.sheet.write.metadata.fill.FillConfig;
-import org.apache.fesod.sheet.write.metadata.fill.FillWrapper;
-import org.apache.poi.ss.usermodel.Sheet;
-import org.apache.poi.ss.util.CellRangeAddress;
-import org.junit.jupiter.api.Test;
-
-/**
- * Example of writing and filling data into Excel
- */
-public class FillTest {
- /**
- * Simplest example of filling data
- */
- @Test
- public void simpleFill() {
- // Template note: Use {} to indicate variables. If there are existing "{", "}" characters, use "\{", "\}"
- // instead.
- String templateFileName =
- TestFileUtil.getPath() + "demo" + File.separator + "fill" + File.separator + "simple.xlsx";
-
- // Option 1: Fill based on an object
- String fileName = TestFileUtil.getPath() + "simpleFill" + System.currentTimeMillis() + ".xlsx";
- // This will fill the first sheet, and the file stream will be automatically closed.
- FillData fillData = new FillData();
- fillData.setName("Zhang San");
- fillData.setNumber(5.2);
- FesodSheet.write(fileName).withTemplate(templateFileName).sheet().doFill(fillData);
-
- // Option 2: Fill based on a Map
- fileName = TestFileUtil.getPath() + "simpleFill" + System.currentTimeMillis() + ".xlsx";
- // This will fill the first sheet, and the file stream will be automatically closed.
- Map map = MapUtils.newHashMap();
- map.put("name", "Zhang San");
- map.put("number", 5.2);
- FesodSheet.write(fileName).withTemplate(templateFileName).sheet().doFill(map);
- }
-
- /**
- * Example of filling a list
- */
- @Test
- public void listFill() {
- // Template note: Use {} to indicate variables. If there are existing "{", "}" characters, use "\{", "\}"
- // instead.
- // When filling a list, note that {.} in the template indicates a list.
- // If the object filling the list is a Map, it must contain all keys of the list, even if the data is null. Use
- // map.put(key, null).
- String templateFileName =
- TestFileUtil.getPath() + "demo" + File.separator + "fill" + File.separator + "list.xlsx";
-
- // Option 1: Load all data into memory at once and fill
- String fileName = TestFileUtil.getPath() + "listFill" + System.currentTimeMillis() + ".xlsx";
- // This will fill the first sheet, and the file stream will be automatically closed.
- FesodSheet.write(fileName).withTemplate(templateFileName).sheet().doFill(data());
-
- // Option 2: Fill in multiple passes, using file caching (saves memory)
- fileName = TestFileUtil.getPath() + "listFill" + System.currentTimeMillis() + ".xlsx";
- try (ExcelWriter excelWriter =
- FesodSheet.write(fileName).withTemplate(templateFileName).build()) {
- WriteSheet writeSheet = FesodSheet.writerSheet().build();
- excelWriter.fill(data(), writeSheet);
- excelWriter.fill(data(), writeSheet);
- }
- }
-
- /**
- * Example of complex filling
- */
- @Test
- public void complexFill() {
- // Template note: Use {} to indicate variables. If there are existing "{", "}" characters, use "\{", "\}"
- // instead.
- // {} represents a normal variable, {.} represents a list variable.
- String templateFileName =
- TestFileUtil.getPath() + "demo" + File.separator + "fill" + File.separator + "complex.xlsx";
-
- String fileName = TestFileUtil.getPath() + "complexFill" + System.currentTimeMillis() + ".xlsx";
- // Option 1
- try (ExcelWriter excelWriter =
- FesodSheet.write(fileName).withTemplate(templateFileName).build()) {
- WriteSheet writeSheet = FesodSheet.writerSheet().build();
- // Note: The forceNewRow parameter is used here. When writing a list, it will always create a new row, and
- // the data below will be shifted down. Default is false, which will use the next row if available,
- // otherwise create a new one.
- // forceNewRow: If set to true, it will load all data into memory, so use it with caution.
- // In short, if your template has a list and the list is not the last row, and there is data below that
- // needs to be filled, you must set forceNewRow=true. However, this will consume a lot of memory.
- // For large datasets where the list is not the last row, refer to the next example.
- FillConfig fillConfig =
- FillConfig.builder().forceNewRow(Boolean.TRUE).build();
- excelWriter.fill(data(), fillConfig, writeSheet);
- excelWriter.fill(data(), fillConfig, writeSheet);
- Map map = MapUtils.newHashMap();
- map.put("date", "2019-10-09 13:28:28");
- map.put("total", 1000);
- excelWriter.fill(map, writeSheet);
- }
- }
-
- /**
- * Example of complex filling with large datasets
- *
- * The solution here is to ensure that the list in the template is the last row, and then append a table. For Excel 2003, there is no solution other than increasing memory.
- */
- @Test
- public void complexFillWithTable() {
- // Template note: Use {} to indicate variables. If there are existing "{", "}" characters, use "\{", "\}"
- // instead.
- // {} represents a normal variable, {.} represents a list variable.
- // Here, the template deletes the data after the list, i.e., the summary row.
- String templateFileName = TestFileUtil.getPath() + "demo" + File.separator + "fill" + File.separator
- + "complexFillWithTable.xlsx";
-
- String fileName = TestFileUtil.getPath() + "complexFillWithTable" + System.currentTimeMillis() + ".xlsx";
-
- // Option 1
- try (ExcelWriter excelWriter =
- FesodSheet.write(fileName).withTemplate(templateFileName).build()) {
- WriteSheet writeSheet = FesodSheet.writerSheet().build();
- // Directly write data
- excelWriter.fill(data(), writeSheet);
- excelWriter.fill(data(), writeSheet);
-
- // Write data before the list
- Map map = new HashMap();
- map.put("date", "2019-10-09 13:28:28");
- excelWriter.fill(map, writeSheet);
-
- // There is a summary after the list, which needs to be written manually.
- // Here, we use a list for simplicity. You can also use an object.
- List> totalListList = ListUtils.newArrayList();
- List totalList = ListUtils.newArrayList();
- totalListList.add(totalList);
- totalList.add(null);
- totalList.add(null);
- totalList.add(null);
- // Fourth column
- totalList.add("Total:1000");
- // Note: Use write here, not fill.
- excelWriter.write(totalListList, writeSheet);
- // Overall, the writing is complex, but there is no better solution. Asynchronous writing to Excel does not
- // support row deletion or movement, nor does it support writing comments, so this approach is used.
- // The idea is to create a new sheet and copy data bit by bit. However, when adding rows to the list, the
- // data in the columns below cannot be shifted. A better solution will be explored in the future.
- }
- }
-
- /**
- * Example of horizontal filling
- */
- @Test
- public void horizontalFill() {
- // Template note: Use {} to indicate variables. If there are existing "{", "}" characters, use "\{", "\}"
- // instead.
- // {} represents a normal variable, {.} represents a list variable.
- String templateFileName =
- TestFileUtil.getPath() + "demo" + File.separator + "fill" + File.separator + "horizontal.xlsx";
-
- String fileName = TestFileUtil.getPath() + "horizontalFill" + System.currentTimeMillis() + ".xlsx";
- // Option 1
- try (ExcelWriter excelWriter =
- FesodSheet.write(fileName).withTemplate(templateFileName).build()) {
- WriteSheet writeSheet = FesodSheet.writerSheet().build();
- FillConfig fillConfig = FillConfig.builder()
- .direction(WriteDirectionEnum.HORIZONTAL)
- .build();
- excelWriter.fill(data(), fillConfig, writeSheet);
- excelWriter.fill(data(), fillConfig, writeSheet);
-
- Map map = new HashMap<>();
- map.put("date", "2019-10-09 13:28:28");
- excelWriter.fill(map, writeSheet);
- }
- }
-
- /**
- * Example of composite filling with multiple lists
- */
- @Test
- public void compositeFill() {
- // Template note: Use {} to indicate variables. If there are existing "{", "}" characters, use "\{", "\}"
- // instead.
- // {} represents a normal variable, {.} represents a list variable, {prefix.} prefix can distinguish different
- // lists.
- String templateFileName =
- TestFileUtil.getPath() + "demo" + File.separator + "fill" + File.separator + "composite.xlsx";
-
- String fileName = TestFileUtil.getPath() + "compositeFill" + System.currentTimeMillis() + ".xlsx";
-
- // Option 1
- try (ExcelWriter excelWriter =
- FesodSheet.write(fileName).withTemplate(templateFileName).build()) {
- WriteSheet writeSheet = FesodSheet.writerSheet().build();
- FillConfig fillConfig = FillConfig.builder()
- .direction(WriteDirectionEnum.HORIZONTAL)
- .build();
- // If there are multiple lists, the template must have {prefix.}. Here, the prefix is data1, and multiple
- // lists must be wrapped with FillWrapper.
- excelWriter.fill(new FillWrapper("data1", data()), fillConfig, writeSheet);
- excelWriter.fill(new FillWrapper("data1", data()), fillConfig, writeSheet);
- excelWriter.fill(new FillWrapper("data2", data()), writeSheet);
- excelWriter.fill(new FillWrapper("data2", data()), writeSheet);
- excelWriter.fill(new FillWrapper("data3", data()), writeSheet);
- excelWriter.fill(new FillWrapper("data3", data()), writeSheet);
-
- Map map = new HashMap();
- map.put("date", new Date());
-
- excelWriter.fill(map, writeSheet);
- }
- }
-
- /**
- * Example of filling an Excel template with date formatting.
- *
- * This method demonstrates how to fill an Excel template where date fields
- * are already formatted in the template. The written data will automatically
- * follow the predefined date format in the template.
- */
- @Test
- public void dateFormatFill() {
- // Define the path to the template file.
- // The template should have predefined date formatting.
- String templateFileName =
- TestFileUtil.getPath() + "demo" + File.separator + "fill" + File.separator + "dateFormat.xlsx";
-
- // Generate a new output file name with a timestamp to avoid overwriting.
- String fileName = TestFileUtil.getPath() + "dateFormatFill" + System.currentTimeMillis() + ".xlsx";
-
- // Fill the template with data.
- // The dates in the data will be formatted according to the template's settings.
- FesodSheet.write(fileName).withTemplate(templateFileName).sheet().doFill(data());
- }
-
- @Test
- public void testFillSheetDispose() {
- String templateFileName =
- TestFileUtil.getPath() + "demo" + File.separator + "fill" + File.separator + "simple.xlsx";
- String fileName = TestFileUtil.getPath() + "simpleFill" + System.currentTimeMillis() + ".xlsx";
- FillData fillData = new FillData();
- fillData.setName("Zhang San");
- fillData.setNumber(5.2);
- FesodSheet.write(fileName)
- .withTemplate(templateFileName)
- .sheet()
- .registerWriteHandler(new SheetWriteHandler() {
- @Override
- public void afterSheetDispose(SheetWriteHandlerContext context) {
- Sheet sheet = context.getWriteSheetHolder().getSheet();
- sheet.addMergedRegionUnsafe(new CellRangeAddress(1, 2, 0, 1));
- }
- })
- .doFill(fillData);
- }
-
- private List data() {
- List list = ListUtils.newArrayList();
- for (int i = 0; i < 10; i++) {
- FillData fillData = new FillData();
- list.add(fillData);
- fillData.setName("Zhang San");
- fillData.setNumber(5.2);
- fillData.setDate(new Date());
- }
- return list;
- }
-}
diff --git a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/rare/WriteTest.java b/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/rare/WriteTest.java
deleted file mode 100644
index f47697e91..000000000
--- a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/rare/WriteTest.java
+++ /dev/null
@@ -1,158 +0,0 @@
-/*
- * 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.demo.rare;
-
-import java.io.File;
-import java.util.Date;
-import java.util.List;
-import lombok.extern.slf4j.Slf4j;
-import org.apache.fesod.common.util.ListUtils;
-import org.apache.fesod.sheet.ExcelWriter;
-import org.apache.fesod.sheet.FesodSheet;
-import org.apache.fesod.sheet.demo.read.DemoData;
-import org.apache.fesod.sheet.util.FileUtils;
-import org.apache.fesod.sheet.util.TestFileUtil;
-import org.apache.fesod.sheet.write.handler.RowWriteHandler;
-import org.apache.fesod.sheet.write.handler.WorkbookWriteHandler;
-import org.apache.fesod.sheet.write.handler.context.RowWriteHandlerContext;
-import org.apache.fesod.sheet.write.handler.context.WorkbookWriteHandlerContext;
-import org.apache.fesod.sheet.write.metadata.WriteSheet;
-import org.apache.poi.ss.usermodel.Cell;
-import org.apache.poi.ss.usermodel.Row;
-import org.apache.poi.ss.usermodel.Sheet;
-import org.apache.poi.ss.usermodel.Workbook;
-import org.apache.poi.xssf.streaming.SXSSFWorkbook;
-import org.junit.jupiter.api.Test;
-
-/**
- * Record some uncommon cases
- *
- *
- */
-@Slf4j
-public class WriteTest {
-
- /**
- * Compress temporary files
- * When exporting an Excel file in xlsx format, a temporary XML file will be generated, which can be quite large.
- * If disk space is limited, you can compress these files.
- * Note that compression consumes performance.
- */
- @Test
- public void compressedTemporaryFile() {
- log.info("Temporary XML files are stored at: {}", FileUtils.getPoiFilesPath());
- File file = TestFileUtil.createNewFile("rare/compressedTemporaryFile" + System.currentTimeMillis() + ".xlsx");
-
- // Specify which class to use for writing here
- try (ExcelWriter excelWriter = FesodSheet.write(file, DemoData.class)
- .registerWriteHandler(new WorkbookWriteHandler() {
-
- /**
- * Intercept the Workbook creation completion event
- * @param context
- */
- @Override
- public void afterWorkbookCreate(WorkbookWriteHandlerContext context) {
- // Get the Workbook object
- Workbook workbook = context.getWriteWorkbookHolder().getWorkbook();
- // Temporary files are only generated in SXSSFWorkbook mode
- if (workbook instanceof SXSSFWorkbook) {
- SXSSFWorkbook sxssfWorkbook = (SXSSFWorkbook) workbook;
- // Enable temporary file compression. Note that this will consume CPU performance, but the
- // temporary files will be smaller
- sxssfWorkbook.setCompressTempFiles(true);
- }
- }
- })
- .build()) {
- // Note that the same sheet should only be created once
- WriteSheet writeSheet = FesodSheet.writerSheet("Template").build();
- // 100,000 data entries to ensure sufficient space
- for (int i = 0; i < 10000; i++) {
- // Query data from the database page by page. Here you can query data for each page from the database
- List data = data();
- excelWriter.write(data, writeSheet);
- }
- log.info("Writing completed, preparing to migrate and compress files.");
- }
- }
-
- /**
- * Write data to a specified cell
- */
- @Test
- public void specifiedCellWrite() {
- File file = TestFileUtil.createNewFile("rare/specifiedCellWrite" + System.currentTimeMillis() + ".xlsx");
-
- // It is necessary to distinguish whether it is before or after the last row
- // The reason for the distinction is: Excel can only move forward, and only 100 rows are stored in memory. The
- // afterRowDispose event is called after each row is written, so modifying a row requires intercepting this
- // event
- // If it is after the last row, since there will be no more data afterwards, just intercept the
- // afterWorkbookDispose event and write the data when the Excel file is almost done
- FesodSheet.write(file, DemoData.class)
- // Writing value before the last row
- .registerWriteHandler(new RowWriteHandler() {
- @Override
- public void afterRowDispose(RowWriteHandlerContext context) {
- if (context.getRow().getRowNum() == 2) {
- Cell cell = context.getRow().getCell(2);
- if (cell == null) {
- cell = context.getRow().createCell(2);
- }
- cell.setCellValue("Test data for the second row");
- }
- }
- })
- // Writing value after the last row
- .registerWriteHandler(new WorkbookWriteHandler() {
- @Override
- public void afterWorkbookDispose(WorkbookWriteHandlerContext context) {
- Workbook workbook = context.getWriteWorkbookHolder().getWorkbook();
- Sheet sheet = workbook.getSheetAt(0);
- Row row = sheet.getRow(99);
- if (row == null) {
- row = sheet.createRow(99);
- }
- Cell cell = row.getCell(2);
- if (cell == null) {
- cell = row.createCell(2);
- }
- cell.setCellValue("Test data for row 99");
- }
- })
- .sheet("Template")
- .doWrite(data());
-
- log.info("Writing to file completed:{}", file);
- }
-
- private List data() {
- List list = ListUtils.newArrayList();
- for (int i = 0; i < 10; i++) {
- DemoData data = new DemoData();
- data.setString("String" + i);
- data.setDate(new Date());
- data.setDoubleData(0.56);
- list.add(data);
- }
- return list;
- }
-}
diff --git a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/read/CellDataReadDemoData.java b/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/read/CellDataReadDemoData.java
deleted file mode 100644
index 432d069a2..000000000
--- a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/read/CellDataReadDemoData.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * 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.demo.read;
-
-import java.util.Date;
-import lombok.EqualsAndHashCode;
-import lombok.Getter;
-import lombok.Setter;
-import org.apache.fesod.sheet.metadata.data.CellData;
-
-/**
- * Basic data class. The order here is consistent with the order in Excel
- *
- *
- **/
-@Getter
-@Setter
-@EqualsAndHashCode
-public class CellDataReadDemoData {
- private CellData string;
- // Note that although this is a date, the type stored is number because excel stores it as number
- private CellData date;
- private CellData doubleData;
- // This may not be perfectly retrieved. Some formulas are dependent and may not be read. This issue will be fixed
- // later
- private CellData formulaValue;
-}
diff --git a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/read/ConverterDataListener.java b/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/read/ConverterDataListener.java
deleted file mode 100644
index 127574947..000000000
--- a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/read/ConverterDataListener.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * 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.demo.read;
-
-import com.alibaba.fastjson2.JSON;
-import java.util.List;
-import lombok.extern.slf4j.Slf4j;
-import org.apache.fesod.common.util.ListUtils;
-import org.apache.fesod.sheet.context.AnalysisContext;
-import org.apache.fesod.sheet.read.listener.ReadListener;
-
-/**
- * Template data reading class
- *
- *
- */
-@Slf4j
-public class ConverterDataListener implements ReadListener {
-
- /**
- * Save to the database every 5 records. In actual use, you might use 100 records,
- * then clear the list to facilitate memory recycling.
- */
- private static final int BATCH_COUNT = 5;
-
- private List cachedDataList = ListUtils.newArrayListWithExpectedSize(BATCH_COUNT);
-
- @Override
- public void invoke(ConverterData data, AnalysisContext context) {
- log.info("Parsed a piece of data: {}", JSON.toJSONString(data));
- cachedDataList.add(data);
- if (cachedDataList.size() >= BATCH_COUNT) {
- saveData();
- cachedDataList = ListUtils.newArrayListWithExpectedSize(BATCH_COUNT);
- }
- }
-
- @Override
- public void doAfterAllAnalysed(AnalysisContext context) {
- saveData();
- log.info("All data has been parsed and processed!");
- }
-
- /**
- * Simulate saving data to the database
- */
- private void saveData() {
- log.info("Saving {} records to the database!", cachedDataList.size());
- log.info("Data saved to the database successfully!");
- }
-}
diff --git a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/read/DemoChainAccessorsData.java b/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/read/DemoChainAccessorsData.java
deleted file mode 100644
index 24e45ed20..000000000
--- a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/read/DemoChainAccessorsData.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * 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.demo.read;
-
-import java.util.Date;
-import lombok.Data;
-import lombok.experimental.Accessors;
-
-/**
- * 基础数据类.这里的排序和excel里面的排序一致
- *
- *
- **/
-@Data
-@Accessors(chain = true)
-public class DemoChainAccessorsData {
- private String string;
- private Date date;
- private Double doubleData;
-}
diff --git a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/read/DemoCompatibleHeaderDataListener.java b/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/read/DemoCompatibleHeaderDataListener.java
deleted file mode 100644
index 064d4b3b4..000000000
--- a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/read/DemoCompatibleHeaderDataListener.java
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * 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.demo.read;
-
-import com.alibaba.fastjson2.JSON;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import lombok.extern.slf4j.Slf4j;
-import org.apache.fesod.common.util.ListUtils;
-import org.apache.fesod.sheet.context.AnalysisContext;
-import org.apache.fesod.sheet.event.AnalysisEventListener;
-import org.apache.fesod.sheet.metadata.data.ReadCellData;
-
-/**
- * Listener to read headers with compatibility for both Chinese and English.
- */
-@Slf4j
-public class DemoCompatibleHeaderDataListener extends AnalysisEventListener {
-
- /**
- * Store data in batches of 100. In practice, you can adjust this number based on your needs.
- * After storing, clear the list to facilitate memory recovery.
- */
- private static final int BATCH_COUNT = 100;
-
- /**
- * Map various header names to their corresponding annotation header information.
- */
- private final Map headerMapping = new HashMap<>(8);
-
- /**
- * Cache data in a list.
- */
- private List cachedDataList = ListUtils.newArrayListWithExpectedSize(BATCH_COUNT);
-
- {
- // Initialize the header mapping with examples.
- headerMapping.put("字符串标题", "String");
- headerMapping.put("日期标题", "Date");
- headerMapping.put("数字标题", "DoubleData");
- }
-
- /**
- * This method will be called for each row of headers.
- *
- * @param headMap A map containing the header information.
- * @param context The analysis context.
- */
- @Override
- public void invokeHead(Map> headMap, AnalysisContext context) {
- log.info("Parsed one header row:{}", JSON.toJSONString(headMap));
- headMap.forEach((key, value) -> {
- // Here, a header mapping relationship is established. You can customize this logic as needed,
- // such as case conversion, suffix removal, space deletion, etc.
- String stringValue = value.getStringValue();
- value.setStringValue(headerMapping.getOrDefault(stringValue, stringValue));
- });
- }
-
- /**
- * This method is called for each parsed data row.
- *
- * @param data One row of data. It is the same as {@link AnalysisContext#readRowHolder()}.
- * @param context The analysis context.
- */
- @Override
- public void invoke(DemoCompatibleHeaderData data, AnalysisContext context) {
- log.info("Parsed one data row:{}", JSON.toJSONString(data));
- cachedDataList.add(data);
- // When the cached data reaches BATCH_COUNT, store it to prevent OOM issues with large datasets.
- if (cachedDataList.size() >= BATCH_COUNT) {
- saveData();
- // Clear the list after storage.
- cachedDataList = ListUtils.newArrayListWithExpectedSize(BATCH_COUNT);
- }
- }
-
- /**
- * Called when all data has been analyzed.
- *
- * @param context The analysis context.
- */
- @Override
- public void doAfterAllAnalysed(AnalysisContext context) {
- saveData();
- log.info("All data parsing completed!");
- }
-
- /**
- * Simulates saving data to a database.
- */
- private void saveData() {
- log.info("{} rows of data, starting to save to the database!", cachedDataList.size());
- log.info("Data saved successfully to the database!");
- }
-}
diff --git a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/read/DemoData.java b/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/read/DemoData.java
deleted file mode 100644
index ce90bf84b..000000000
--- a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/read/DemoData.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * 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.demo.read;
-
-import java.util.Date;
-import lombok.EqualsAndHashCode;
-import lombok.Getter;
-import lombok.Setter;
-
-/**
- * 基础数据类.这里的排序和excel里面的排序一致
- *
- *
- **/
-@Getter
-@Setter
-@EqualsAndHashCode
-public class DemoData {
- private String string;
- private Date date;
- private Double doubleData;
-}
diff --git a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/read/DemoDataAnother.java b/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/read/DemoDataAnother.java
deleted file mode 100644
index ec9b41fc0..000000000
--- a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/read/DemoDataAnother.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * 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.demo.read;
-
-import lombok.EqualsAndHashCode;
-import lombok.Getter;
-import lombok.Setter;
-import lombok.ToString;
-
-@Getter
-@Setter
-@EqualsAndHashCode
-@ToString
-public class DemoDataAnother {
- private String strA;
- private String strB;
- private String strC;
-}
diff --git a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/read/DemoExtraListener.java b/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/read/DemoExtraListener.java
deleted file mode 100644
index cade0789d..000000000
--- a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/read/DemoExtraListener.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * 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.demo.read;
-
-import com.alibaba.fastjson2.JSON;
-import lombok.extern.slf4j.Slf4j;
-import org.apache.fesod.sheet.context.AnalysisContext;
-import org.apache.fesod.sheet.metadata.CellExtra;
-import org.apache.fesod.sheet.read.listener.ReadListener;
-import org.junit.jupiter.api.Assertions;
-
-/**
- * Listener to read cell comments, hyperlinks, and merged cells.
- *
- *
- **/
-@Slf4j
-public class DemoExtraListener implements ReadListener {
-
- @Override
- public void invoke(DemoExtraData data, AnalysisContext context) {}
-
- @Override
- public void doAfterAllAnalysed(AnalysisContext context) {}
-
- @Override
- public void extra(CellExtra extra, AnalysisContext context) {
- log.info("Read an extra piece of information: {}", JSON.toJSONString(extra));
- switch (extra.getType()) {
- case COMMENT:
- log.info(
- "The extra information is a comment, at rowIndex:{}, columnIndex:{}, content:{}",
- extra.getRowIndex(),
- extra.getColumnIndex(),
- extra.getText());
- break;
- case HYPERLINK:
- if ("Sheet1!A1".equals(extra.getText())) {
- log.info(
- "The extra information is a hyperlink, at rowIndex:{}, columnIndex:{}, content:{}",
- extra.getRowIndex(),
- extra.getColumnIndex(),
- extra.getText());
- } else if ("Sheet2!A1".equals(extra.getText())) {
- log.info(
- "The extra information is a hyperlink, covering a range, firstRowIndex:{}, firstColumnIndex:{}, "
- + "lastRowIndex:{}, lastColumnIndex:{}, content:{}",
- extra.getFirstRowIndex(),
- extra.getFirstColumnIndex(),
- extra.getLastRowIndex(),
- extra.getLastColumnIndex(),
- extra.getText());
- } else {
- Assertions.fail("Unknown hyperlink!");
- }
- break;
- case MERGE:
- log.info(
- "The extra information is a merged cell, covering a range, firstRowIndex:{}, firstColumnIndex:{}, "
- + "lastRowIndex:{}, lastColumnIndex:{}",
- extra.getFirstRowIndex(),
- extra.getFirstColumnIndex(),
- extra.getLastRowIndex(),
- extra.getLastColumnIndex());
- break;
- default:
- }
- }
-}
diff --git a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/read/DemoHeadDataListener.java b/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/read/DemoHeadDataListener.java
deleted file mode 100644
index e06b90d58..000000000
--- a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/read/DemoHeadDataListener.java
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * 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.demo.read;
-
-import com.alibaba.fastjson2.JSON;
-import java.util.List;
-import java.util.Map;
-import lombok.extern.slf4j.Slf4j;
-import org.apache.fesod.common.util.ListUtils;
-import org.apache.fesod.sheet.context.AnalysisContext;
-import org.apache.fesod.sheet.exception.ExcelDataConvertException;
-import org.apache.fesod.sheet.metadata.data.ReadCellData;
-import org.apache.fesod.sheet.read.listener.ReadListener;
-
-/**
- * Reading headers
- *
- *
- */
-@Slf4j
-public class DemoHeadDataListener implements ReadListener {
-
- /**
- * Save to the database every 5 records. In actual use, you might use 100 records,
- * then clear the list to facilitate memory recycling.
- */
- private static final int BATCH_COUNT = 5;
-
- private List cachedDataList = ListUtils.newArrayListWithExpectedSize(BATCH_COUNT);
-
- /**
- * This method is called when a conversion exception or other exceptions occur.
- * Throwing an exception will stop the reading process. If no exception is thrown here,
- * the reading will continue to the next row.
- *
- * @param exception The exception that occurred.
- * @param context The analysis context.
- * @throws Exception If an exception is thrown to stop reading.
- */
- @Override
- public void onException(Exception exception, AnalysisContext context) {
- log.error("Parsing failed, but continue parsing the next row: {}", exception.getMessage());
- if (exception instanceof ExcelDataConvertException) {
- ExcelDataConvertException excelDataConvertException = (ExcelDataConvertException) exception;
- log.error(
- "Row {}, Column {} parsing exception, data is: {}",
- excelDataConvertException.getRowIndex(),
- excelDataConvertException.getColumnIndex(),
- excelDataConvertException.getCellData());
- }
- }
-
- /**
- * This method is called for each header row.
- *
- * @param headMap The header data as a map.
- * @param context The analysis context.
- */
- @Override
- public void invokeHead(Map> headMap, AnalysisContext context) {
- log.info("Parsed a header row: {}", JSON.toJSONString(headMap));
- // If you want to convert it to a Map:
- // Solution 1: Do not implement ReadListener, but extend AnalysisEventListener.
- // Solution 2: Call ConverterUtils.convertToStringMap(headMap, context) to convert automatically.
- }
-
- @Override
- public void invoke(DemoData data, AnalysisContext context) {
- log.info("Parsed a piece of data: {}", JSON.toJSONString(data));
- if (cachedDataList.size() >= BATCH_COUNT) {
- saveData();
- cachedDataList = ListUtils.newArrayListWithExpectedSize(BATCH_COUNT);
- }
- }
-
- @Override
- public void doAfterAllAnalysed(AnalysisContext context) {
- saveData();
- log.info("All data has been parsed and processed!");
- }
-
- /**
- * Simulate saving data to the database.
- */
- private void saveData() {
- log.info("Saving {} records to the database!", cachedDataList.size());
- log.info("Data saved to the database successfully!");
- }
-}
diff --git a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/read/GenericHeaderTypeDataListener.java b/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/read/GenericHeaderTypeDataListener.java
deleted file mode 100644
index 6dd9b9a02..000000000
--- a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/read/GenericHeaderTypeDataListener.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * 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.demo.read;
-
-import lombok.extern.slf4j.Slf4j;
-import org.apache.fesod.sheet.context.AnalysisContext;
-import org.apache.fesod.sheet.read.listener.ReadListener;
-
-/**
- * A data listener example that specifies the header type through generics.
- *
- * @param
- */
-@Slf4j
-public class GenericHeaderTypeDataListener implements ReadListener {
-
- private final Class headerClass;
-
- private GenericHeaderTypeDataListener(Class headerClass) {
- this.headerClass = headerClass;
- }
-
- @Override
- public void invoke(T data, AnalysisContext context) {
- log.info("data:{}", data);
- // Execute business logic
- }
-
- @Override
- public void doAfterAllAnalysed(AnalysisContext context) {
- // Perform cleanup tasks
- }
-
- public static GenericHeaderTypeDataListener build(Class excelHeaderClass) {
- return new GenericHeaderTypeDataListener<>(excelHeaderClass);
- }
-
- public Class getHeaderClass() {
- return headerClass;
- }
-}
diff --git a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/read/IndexOrNameDataListener.java b/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/read/IndexOrNameDataListener.java
deleted file mode 100644
index 0335c0456..000000000
--- a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/read/IndexOrNameDataListener.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * 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.demo.read;
-
-import com.alibaba.fastjson2.JSON;
-import java.util.List;
-import lombok.extern.slf4j.Slf4j;
-import org.apache.fesod.common.util.ListUtils;
-import org.apache.fesod.sheet.context.AnalysisContext;
-import org.apache.fesod.sheet.event.AnalysisEventListener;
-
-/**
- * Template reading class
- *
- *
- */
-@Slf4j
-public class IndexOrNameDataListener extends AnalysisEventListener {
-
- /**
- * Store data in the database every 5 records. In actual use, it can be 100 records,
- * and then clear the list to facilitate memory recycling.
- */
- private static final int BATCH_COUNT = 5;
-
- private List cachedDataList = ListUtils.newArrayListWithExpectedSize(BATCH_COUNT);
-
- @Override
- public void invoke(IndexOrNameData data, AnalysisContext context) {
- log.info("Parsed one row of data: {}", JSON.toJSONString(data));
- cachedDataList.add(data);
- if (cachedDataList.size() >= BATCH_COUNT) {
- saveData();
- cachedDataList = ListUtils.newArrayListWithExpectedSize(BATCH_COUNT);
- }
- }
-
- @Override
- public void doAfterAllAnalysed(AnalysisContext context) {
- saveData();
- log.info("All data has been parsed!");
- }
-
- /**
- * Store data in the database
- */
- private void saveData() {
- log.info("{} records are being stored in the database!", cachedDataList.size());
- log.info("Data has been successfully stored in the database!");
- }
-}
diff --git a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/read/ReadTest.java b/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/read/ReadTest.java
deleted file mode 100644
index aba7545e8..000000000
--- a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/read/ReadTest.java
+++ /dev/null
@@ -1,454 +0,0 @@
-/*
- * 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.demo.read;
-
-import com.alibaba.fastjson2.JSON;
-import java.io.File;
-import java.util.List;
-import java.util.Map;
-import lombok.extern.slf4j.Slf4j;
-import org.apache.fesod.common.util.ListUtils;
-import org.apache.fesod.sheet.ExcelReader;
-import org.apache.fesod.sheet.FesodSheet;
-import org.apache.fesod.sheet.annotation.ExcelProperty;
-import org.apache.fesod.sheet.annotation.format.DateTimeFormat;
-import org.apache.fesod.sheet.annotation.format.NumberFormat;
-import org.apache.fesod.sheet.context.AnalysisContext;
-import org.apache.fesod.sheet.converters.DefaultConverterLoader;
-import org.apache.fesod.sheet.enums.CellExtraTypeEnum;
-import org.apache.fesod.sheet.read.listener.PageReadListener;
-import org.apache.fesod.sheet.read.listener.ReadListener;
-import org.apache.fesod.sheet.read.metadata.ReadSheet;
-import org.apache.fesod.sheet.read.metadata.holder.csv.CsvReadWorkbookHolder;
-import org.apache.fesod.sheet.util.TestFileUtil;
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.Nested;
-import org.junit.jupiter.api.Test;
-
-/**
- * Common approaches for reading Excel files
- *
- *
- */
-@Slf4j
-public class ReadTest {
-
- /**
- * Simplest way to read
- *
- * 1. Create an entity class corresponding to the Excel data structure. Refer to {@link DemoData}.
- *
- * 2. Since Fesod reads Excel files row by row, you need to create a callback listener for each row. Refer to {@link DemoDataListener}.
- *
- * 3. Directly read the file.
- */
- @Test
- public void simpleRead() {
- // Approach 1: JDK8+, no need to create a separate DemoDataListener
- // since: 3.0.0-beta1
- String fileName = TestFileUtil.getPath() + "demo" + File.separator + "demo.xlsx";
- // Specify the class to read the data, then read the first sheet. The file stream will be automatically closed.
- // By default, it reads 100 rows at a time. You can process the data directly.
- // The number of rows to read can be set in the constructor of `PageReadListener`.
- FesodSheet.read(fileName, DemoData.class, new PageReadListener(dataList -> {
- for (DemoData demoData : dataList) {
- log.info("Reading a row of data: {}", JSON.toJSONString(demoData));
- }
- }))
- .numRows(2)
- .sheet()
- .doRead();
-
- // Approach 2:
- // Anonymous inner class, no need to create a separate DemoDataListener
- fileName = TestFileUtil.getPath() + "demo" + File.separator + "demo.xlsx";
- // Specify the class to read the data, then read the first sheet. The file stream will be automatically closed.
- FesodSheet.read(fileName, DemoData.class, new ReadListener() {
- /**
- * Batch size for caching data
- */
- public static final int BATCH_COUNT = 100;
- /**
- * Temporary storage
- */
- private List cachedDataList = ListUtils.newArrayListWithExpectedSize(BATCH_COUNT);
-
- @Override
- public void invoke(DemoData data, AnalysisContext context) {
- cachedDataList.add(data);
- if (cachedDataList.size() >= BATCH_COUNT) {
- saveData();
- // Clear the list after saving
- cachedDataList = ListUtils.newArrayListWithExpectedSize(BATCH_COUNT);
- }
- }
-
- @Override
- public void doAfterAllAnalysed(AnalysisContext context) {
- saveData();
- }
-
- /**
- * Simulate saving data to the database
- */
- private void saveData() {
- log.info("Saving {} rows of data to the database!", cachedDataList.size());
- log.info("Data saved successfully!");
- }
- })
- .sheet()
- .doRead();
-
- // Important note: DemoDataListener should not be managed by Spring. It needs to be instantiated every time you
- // read an Excel file.
- // Approach 3:
- fileName = TestFileUtil.getPath() + "demo" + File.separator + "demo.xlsx";
- // Specify the class to read the data, then read the first sheet. The file stream will be automatically closed.
- FesodSheet.read(fileName, DemoData.class, new DemoDataListener())
- .sheet()
- .doRead();
-
- // Approach 4
- fileName = TestFileUtil.getPath() + "demo" + File.separator + "demo.xlsx";
- // One reader per file
- try (ExcelReader excelReader = FesodSheet.read(fileName, DemoData.class, new DemoDataListener())
- .build()) {
- // Build a sheet. You can specify the name or index.
- ReadSheet readSheet = FesodSheet.readSheet(0).build();
- readSheet.setNumRows(2);
- // Read a single sheet
- excelReader.read(readSheet);
- }
- }
-
- @Test
- public void genericHeaderTypeRead() {
- String fileName = TestFileUtil.getPath() + "demo" + File.separator + "generic-demo.xlsx";
- // Simulate obtaining the Excel header's Class> object through any possible means
- Class> excelHeaderClass = DemoDataAnother.class;
- FesodSheet.read(fileName, excelHeaderClass, GenericHeaderTypeDataListener.build(excelHeaderClass))
- .sheet()
- .doRead();
- }
-
- /**
- * Specify column indexes or names
- *
- * 1. Create an entity class corresponding to the Excel data structure and use the {@link ExcelProperty} annotation. Refer to {@link IndexOrNameData}.
- *
- * 2. Since Fesod reads Excel files row by row, you need to create a callback listener for each row. Refer to {@link IndexOrNameDataListener}.
- *
- * 3. Directly read the file.
- */
- @Test
- public void indexOrNameRead() {
- String fileName = TestFileUtil.getPath() + "demo" + File.separator + "demo.xlsx";
- // By default, read the first sheet
- FesodSheet.read(fileName, IndexOrNameData.class, new IndexOrNameDataListener())
- .numRows(1)
- .sheet()
- .doRead();
- }
-
- /**
- * Read multiple or all sheets. Note that a sheet cannot be read multiple times; multiple reads require re-reading the file.
- *
- * 1. Create an entity class corresponding to the Excel data structure. Refer to {@link DemoData}.
- *
- * 2. Since Fesod reads Excel files row by row, you need to create a callback listener for each row. Refer to {@link DemoDataListener}.
- *
- * 3. Directly read the file.
- */
- @Test
- public void repeatedRead() {
- String fileName = TestFileUtil.getPath() + "demo" + File.separator + "demo.xlsx";
- // Read all sheets
- // Note: The `doAfterAllAnalysed` method of DemoDataListener will be called once after each sheet is read.
- // All sheets will write to the same DemoDataListener.
- FesodSheet.read(fileName, DemoData.class, new DemoDataListener()).doReadAll();
-
- // Read some sheets
- fileName = TestFileUtil.getPath() + "demo" + File.separator + "demo.xlsx";
-
- // Method 1
- try (ExcelReader excelReader = FesodSheet.read(fileName).build()) {
- // For simplicity, the same head and Listener are registered here.
- // In actual use, different Listeners must be used.
- ReadSheet readSheet1 = FesodSheet.readSheet(0)
- .head(DemoData.class)
- .registerReadListener(new DemoDataListener())
- .build();
- ReadSheet readSheet2 = FesodSheet.readSheet(1)
- .head(DemoData.class)
- .registerReadListener(new DemoDataListener())
- .build();
- // Note: All sheets (sheet1 and sheet2) must be passed together.
- // Otherwise, for Excel 2003 files, the same sheet may be read multiple times, wasting performance.
- excelReader.read(readSheet1, readSheet2);
- }
- }
-
- /**
- * Date, number, or custom format conversion
- *
- * Default converter: {@link DefaultConverterLoader#loadDefaultReadConverter()}
- *
- * 1. Create an entity class corresponding to the Excel data structure. Refer to {@link ConverterData}.
- * Annotations such as {@link DateTimeFormat}, {@link NumberFormat}, or custom annotations can be used.
- *
- * 2. Since Fesod reads Excel files row by row, you need to create a callback listener for each row. Refer to {@link ConverterDataListener}.
- *
- * 3. Directly read the file.
- */
- @Test
- public void converterRead() {
- String fileName = TestFileUtil.getPath() + "demo" + File.separator + "demo.xlsx";
- // Specify the class to read, then read the first sheet
- FesodSheet.read(fileName, ConverterData.class, new ConverterDataListener())
- // Note: We can also register a custom converter using `registerConverter`.
- // However, this converter will be global, and all fields with Java type `String` and Excel type
- // `String` will use this converter.
- // If you want to use it for a single field, specify the converter using `@ExcelProperty`.
- // .registerConverter(new CustomStringStringConverter())
- // Read the sheet
- .sheet()
- .doRead();
- }
-
- /**
- * Multi-row header
- *
- *
- * 1. Create an entity class corresponding to the Excel data structure. Refer to {@link DemoData}.
- *
- * 2. Since Fesod reads Excel files row by row, you need to create a callback listener for each row. Refer to {@link DemoDataListener}.
- *
- * 3. Set the `headRowNumber` parameter, then read. Note that if `headRowNumber` is not specified,
- * the number of rows will be determined by the number of headers in the `@ExcelProperty#value()` of the class you provide.
- * If no class is provided, the default is 1. Of course, if you specify `headRowNumber`, it will be used regardless of whether a class is provided.
- */
- @Test
- public void complexHeaderRead() {
- String fileName = TestFileUtil.getPath() + "demo" + File.separator + "demo.xlsx";
- // Specify the class to read, then read the first sheet
- FesodSheet.read(fileName, DemoData.class, new DemoDataListener())
- .sheet()
- // Set to 1 here because the header is one row. For multi-row headers, set to other values.
- // You can also omit this, as the default behavior will parse based on DemoData, which does not specify
- // a header, meaning the default is 1 row.
- .headRowNumber(1)
- .doRead();
- }
-
- /**
- * Method to read Excel files with headers that support compatibility, such as case sensitivity or simultaneous
- * support for Chinese and English headers.
- *
- *
- * 1. Create an entity object corresponding to the Excel data structure. Refer to {@link DemoCompatibleHeaderData}
- * for implementation details.
- *
- *
- *
- * 2. Since Fesod reads the Excel file row by row by default, you need to create a listener that handles each
- * row's data accordingly. Refer to {@link DemoCompatibleHeaderDataListener} for implementation details. In this
- * listener, you should override the `invokeHead` method to transform the uploaded headers as needed.
- *
- *
- *
- * 3. Simply proceed to read the file.
- *
- */
- @Test
- public void compatibleHeaderRead() {
- String fileName = TestFileUtil.getPath() + "demo" + File.separator + "demo.xlsx";
- // Specify the class used for reading and choose to read the first sheet.
- FesodSheet.read(fileName, DemoCompatibleHeaderData.class, new DemoCompatibleHeaderDataListener())
- .sheet()
- .doRead();
- }
-
- /**
- * Read header data
- *
- *
- * 1. Create an entity object corresponding to the Excel data structure. Refer to {@link DemoData}.
- *
- * 2. Since Fesod reads Excel files row by row, you need to create a callback listener for each row. Refer to {@link DemoHeadDataListener}.
- *
- * 3. Directly read the file.
- */
- @Test
- public void headerRead() {
- String fileName = TestFileUtil.getPath() + "demo" + File.separator + "demo.xlsx";
- // Specify the class to read, then read the first sheet
- FesodSheet.read(fileName, DemoData.class, new DemoHeadDataListener())
- .sheet()
- .doRead();
- }
-
- /**
- * Additional information (comments, hyperlinks, merged cell information)
- *
- * Since it is stream-based reading, it is not possible to directly read additional information when reading cell data.
- * Therefore, only notifications of which cells contain additional information can be provided at the end.
- *
- *
- * 1. Create an entity object corresponding to the Excel data structure. Refer to {@link DemoExtraData}.
- *
- * 2. Since Fesod reads Excel files row by row by default, you need to create a callback listener for each row. Refer to {@link DemoExtraListener}.
- *
- * 3. Directly read the file.
- */
- @Test
- public void extraRead() {
- String fileName = TestFileUtil.getPath() + "demo" + File.separator + "extra.xlsx";
- // Specify the class to read, then read the first sheet
- FesodSheet.read(fileName, DemoExtraData.class, new DemoExtraListener())
- // Read comments (default is not to read)
- .extraRead(CellExtraTypeEnum.COMMENT)
- // Read hyperlinks (default is not to read)
- .extraRead(CellExtraTypeEnum.HYPERLINK)
- // Read merged cell information (default is not to read)
- .extraRead(CellExtraTypeEnum.MERGE)
- .sheet()
- .doRead();
- }
-
- /**
- * Read formulas and cell types
- *
- *
- * 1. Create an entity object corresponding to the Excel data structure. Refer to {@link CellDataReadDemoData}.
- *
- * 2. Since Fesod reads Excel files row by row by default, you need to create a callback listener for each row. Refer to {@link CellDataDemoHeadDataListener}.
- *
- * 3. Directly read the file.
- */
- @Test
- public void cellDataRead() {
- String fileName = TestFileUtil.getPath() + "demo" + File.separator + "cellDataDemo.xlsx";
- // Specify the class to read, then read the first sheet
- FesodSheet.read(fileName, CellDataReadDemoData.class, new CellDataDemoHeadDataListener())
- .sheet()
- .doRead();
- }
-
- /**
- * Exception handling for data conversion, etc.
- *
- *
- * 1. Create an entity object corresponding to the Excel data structure. Refer to {@link ExceptionDemoData}.
- *
- * 2. Since Fesod reads Excel files row by row by default, you need to create a callback listener for each row. Refer to {@link DemoExceptionListener}.
- *
- * 3. Directly read the file.
- */
- @Test
- public void exceptionRead() {
- String fileName = TestFileUtil.getPath() + "demo" + File.separator + "demo.xlsx";
- // Specify the class to read, then read the first sheet
- FesodSheet.read(fileName, ExceptionDemoData.class, new DemoExceptionListener())
- .sheet()
- .doRead();
- }
-
- /**
- * Synchronous return is not recommended, as it will store data in memory if the data volume is large.
- */
- @Test
- public void synchronousRead() {
- String fileName = TestFileUtil.getPath() + "demo" + File.separator + "demo.xlsx";
- // Specify the class to read, then read the first sheet. Synchronous reading will automatically finish.
- List list =
- FesodSheet.read(fileName).head(DemoData.class).sheet().doReadSync();
- for (DemoData data : list) {
- log.info("Read data:{}", JSON.toJSONString(data));
- }
-
- // Alternatively, you can read without specifying a class, returning a list, then read the first sheet.
- // Synchronous reading will automatically finish.
- List> listMap = FesodSheet.read(fileName).sheet().doReadSync();
- for (Map data : listMap) {
- // Return key-value pairs for each data item, representing the column index and its value.
- log.info("Read data:{}", JSON.toJSONString(data));
- }
- }
-
- /**
- * Reading without creating objects
- */
- @Test
- public void noModelRead() {
- String fileName = TestFileUtil.getPath() + "demo" + File.separator + "demo.xlsx";
- // Simply read the first sheet. Synchronous reading will automatically finish.
- FesodSheet.read(fileName, new NoModelDataListener()).sheet().doRead();
- }
-
- /**
- * Custom modification of CSV configuration
- */
- @Nested
- class ReadCsvFormat {
-
- @Test
- void asNormalJavaBean() {
- String fileName = TestFileUtil.getPath() + "demo" + File.separator + "demo.csv";
- try (ExcelReader excelReader = FesodSheet.read(fileName, DemoData.class, new DemoDataListener())
- .build()) {
- // Check if it is a CSV file
- if (excelReader.analysisContext().readWorkbookHolder() instanceof CsvReadWorkbookHolder) {
- CsvReadWorkbookHolder csvReadWorkbookHolder = (CsvReadWorkbookHolder)
- excelReader.analysisContext().readWorkbookHolder();
- // Set to comma-separated (default is also comma-separated)
- // Note: `withDelimiter` will regenerate the format, so it needs to be set back.
- csvReadWorkbookHolder.setCsvFormat(
- csvReadWorkbookHolder.getCsvFormat().withDelimiter(','));
- }
-
- // Get all sheets
- List readSheetList = excelReader.excelExecutor().sheetList();
- // If you only want to read the first sheet, you can pass the parameter accordingly.
- // ReadSheet readSheet = FesodSheet.readSheet(0).build();
- excelReader.read(readSheetList);
- }
- }
-
- @Test
- void asChainedAccessorsJavaBean() {
- String fileName = TestFileUtil.getPath() + "demo" + File.separator + "demo.csv";
- try (ExcelReader excelReader = FesodSheet.read(
- fileName, DemoChainAccessorsData.class, new ReadListener() {
- @Override
- public void invoke(DemoChainAccessorsData data, AnalysisContext context) {
- Assertions.assertNotNull(data.getString());
- Assertions.assertNotNull(data.getDate());
- Assertions.assertNotNull(data.getDoubleData());
- }
-
- @Override
- public void doAfterAllAnalysed(AnalysisContext context) {}
- })
- .build()) {
- excelReader.readAll();
- }
- }
- }
-}
diff --git a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/read/Sample.java b/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/read/Sample.java
deleted file mode 100644
index c76f40396..000000000
--- a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/read/Sample.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * 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.demo.read;
-
-import lombok.EqualsAndHashCode;
-import lombok.Getter;
-import lombok.NoArgsConstructor;
-import lombok.Setter;
-
-@Getter
-@Setter
-@EqualsAndHashCode
-@NoArgsConstructor
-public class Sample {
-
- private String header;
-}
diff --git a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/web/UploadDataListener.java b/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/web/UploadDataListener.java
deleted file mode 100644
index 50f443bd1..000000000
--- a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/web/UploadDataListener.java
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * 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.demo.web;
-
-import com.alibaba.fastjson2.JSON;
-import java.util.List;
-import lombok.extern.slf4j.Slf4j;
-import org.apache.fesod.common.util.ListUtils;
-import org.apache.fesod.sheet.context.AnalysisContext;
-import org.apache.fesod.sheet.read.listener.ReadListener;
-
-/**
- * 模板的读取类
- *
- *
- */
-// 有个很重要的点 DemoDataListener 不能被spring管理,要每次读取excel都要new,然后里面用到spring可以构造方法传进去
-@Slf4j
-public class UploadDataListener implements ReadListener {
- /**
- * 每隔5条存储数据库,实际使用中可以100条,然后清理list ,方便内存回收
- */
- private static final int BATCH_COUNT = 5;
-
- private List cachedDataList = ListUtils.newArrayListWithExpectedSize(BATCH_COUNT);
- /**
- * 假设这个是一个DAO,当然有业务逻辑这个也可以是一个service。当然如果不用存储这个对象没用。
- */
- private UploadDAO uploadDAO;
-
- public UploadDataListener() {
- // 这里是demo,所以随便new一个。实际使用如果到了spring,请使用下面的有参构造函数
- uploadDAO = new UploadDAO();
- }
-
- /**
- * 如果使用了spring,请使用这个构造方法。每次创建Listener的时候需要把spring管理的类传进来
- *
- * @param uploadDAO
- */
- public UploadDataListener(UploadDAO uploadDAO) {
- this.uploadDAO = uploadDAO;
- }
-
- /**
- * 这个每一条数据解析都会来调用
- *
- * @param data one row value. It is same as {@link AnalysisContext#readRowHolder()}
- * @param context
- */
- @Override
- public void invoke(UploadData data, AnalysisContext context) {
- log.info("解析到一条数据:{}", JSON.toJSONString(data));
- cachedDataList.add(data);
- // 达到BATCH_COUNT了,需要去存储一次数据库,防止数据几万条数据在内存,容易OOM
- if (cachedDataList.size() >= BATCH_COUNT) {
- saveData();
- // 存储完成清理 list
- cachedDataList = ListUtils.newArrayListWithExpectedSize(BATCH_COUNT);
- }
- }
-
- /**
- * 所有数据解析完成了 都会来调用
- *
- * @param context
- */
- @Override
- public void doAfterAllAnalysed(AnalysisContext context) {
- // 这里也要保存数据,确保最后遗留的数据也存储到数据库
- saveData();
- log.info("所有数据解析完成!");
- }
-
- /**
- * 加上存储数据库
- */
- private void saveData() {
- log.info("{}条数据,开始存储数据库!", cachedDataList.size());
- uploadDAO.save(cachedDataList);
- log.info("存储数据库成功!");
- }
-}
diff --git a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/web/WebTest.java b/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/web/WebTest.java
deleted file mode 100644
index f63490edc..000000000
--- a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/web/WebTest.java
+++ /dev/null
@@ -1,133 +0,0 @@
-/*
- * 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.demo.web;
-
-import com.alibaba.fastjson2.JSON;
-import java.io.IOException;
-import java.net.URLEncoder;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-import javax.servlet.http.HttpServletResponse;
-import org.apache.fesod.common.util.ListUtils;
-import org.apache.fesod.common.util.MapUtils;
-import org.apache.fesod.sheet.FesodSheet;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Controller;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.ResponseBody;
-import org.springframework.web.multipart.MultipartFile;
-
-/**
- * Web read and write examples
- *
- *
- **/
-@Controller
-public class WebTest {
-
- @Autowired
- private UploadDAO uploadDAO;
-
- /**
- * File download (returns an Excel with partial data if failed)
- *
- * 1. Create the entity object corresponding to Excel. Refer to {@link DownloadData}
- *
- * 2. Set the return parameters
- *
- * 3. Write directly. Note that the OutputStream will be automatically closed when finish is called. It's fine to close the stream outside as well
- */
- @GetMapping("download")
- public void download(HttpServletResponse response) throws IOException {
- // Note: Some students reported that using Swagger causes various issues, please use browser directly or use
- // Postman
- response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
- response.setCharacterEncoding("utf-8");
- // Here URLEncoder.encode can prevent Chinese character encoding issues, which is unrelated to Fesod
- String fileName = URLEncoder.encode("test", "UTF-8").replaceAll("\\+", "%20");
- response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");
-
- FesodSheet.write(response.getOutputStream(), DownloadData.class)
- .sheet("Template")
- .doWrite(data());
- }
-
- /**
- * File download that returns JSON when failed (by default, returns an Excel with partial data when failed)
- */
- @GetMapping("downloadFailedUsingJson")
- public void downloadFailedUsingJson(HttpServletResponse response) throws IOException {
- // Note: Some students reported that using Swagger causes various issues, please use browser directly or use
- // Postman
- try {
- response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
- response.setCharacterEncoding("utf-8");
- // Here URLEncoder.encode can prevent Chinese character encoding issues, which is unrelated to Fesod
- String fileName = URLEncoder.encode("test", "UTF-8").replaceAll("\\+", "%20");
- response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");
- // Here we need to set not to close the stream
- FesodSheet.write(response.getOutputStream(), DownloadData.class)
- .autoCloseStream(Boolean.FALSE)
- .sheet("Template")
- .doWrite(data());
- } catch (Exception e) {
- // Reset response
- response.reset();
- response.setContentType("application/json");
- response.setCharacterEncoding("utf-8");
- Map map = MapUtils.newHashMap();
- map.put("status", "failure");
- map.put("message", "Failed to download file: " + e.getMessage());
- response.getWriter().println(JSON.toJSONString(map));
- }
- }
-
- /**
- * File upload
- *
- * 1. Create the entity object corresponding to Excel. Refer to {@link UploadData}
- *
- * 2. Since Excel is read row by row by default, you need to create a row-by-row callback listener for Excel. Refer to {@link UploadDataListener}
- *
- * 3. Read directly
- */
- @PostMapping("upload")
- @ResponseBody
- public String upload(MultipartFile file) throws IOException {
- FesodSheet.read(file.getInputStream(), UploadData.class, new UploadDataListener(uploadDAO))
- .sheet()
- .doRead();
- return "success";
- }
-
- private List data() {
- List list = ListUtils.newArrayList();
- for (int i = 0; i < 10; i++) {
- DownloadData data = new DownloadData();
- data.setString("String" + 0);
- data.setDate(new Date());
- data.setDoubleData(0.56);
- list.add(data);
- }
- return list;
- }
-}
diff --git a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/write/ColorDemoData.java b/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/write/ColorDemoData.java
deleted file mode 100644
index 0f80e71de..000000000
--- a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/write/ColorDemoData.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * 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.demo.write;
-
-import lombok.AllArgsConstructor;
-import lombok.EqualsAndHashCode;
-import lombok.Getter;
-import lombok.NoArgsConstructor;
-import lombok.Setter;
-import org.apache.fesod.sheet.annotation.ExcelProperty;
-import org.apache.fesod.sheet.annotation.write.style.HeadFontStyle;
-import org.apache.poi.ss.usermodel.Font;
-
-/**
- * Basic data class for test color
- *
- **/
-@Getter
-@Setter
-@EqualsAndHashCode
-@AllArgsConstructor
-@NoArgsConstructor
-public class ColorDemoData {
-
- @ExcelProperty("Name")
- private String name;
-
- @ExcelProperty("Age")
- @HeadFontStyle(color = Font.COLOR_RED)
- private Integer age;
-
- @ExcelProperty("Sex")
- private String sex;
-}
diff --git a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/write/ComplexHeadData.java b/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/write/ComplexHeadData.java
deleted file mode 100644
index 4ed4c4ddf..000000000
--- a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/write/ComplexHeadData.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * 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.demo.write;
-
-import java.util.Date;
-import lombok.EqualsAndHashCode;
-import lombok.Getter;
-import lombok.Setter;
-import org.apache.fesod.sheet.annotation.ExcelProperty;
-
-/**
- * Complex header data. The final effect is a main title on the first row, and categories on the second row.
- *
- *
- **/
-@Getter
-@Setter
-@EqualsAndHashCode
-public class ComplexHeadData {
- @ExcelProperty({"Main Title", "String Title"})
- private String string;
-
- @ExcelProperty({"Main Title", "Date Title"})
- private Date date;
-
- @ExcelProperty({"Main Title", "Double Title"})
- private Double doubleData;
-}
diff --git a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/write/ConverterData.java b/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/write/ConverterData.java
deleted file mode 100644
index 9448d3b1d..000000000
--- a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/write/ConverterData.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * 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.demo.write;
-
-import java.util.Date;
-import lombok.EqualsAndHashCode;
-import lombok.Getter;
-import lombok.Setter;
-import org.apache.fesod.sheet.annotation.ExcelProperty;
-import org.apache.fesod.sheet.annotation.format.DateTimeFormat;
-import org.apache.fesod.sheet.annotation.format.NumberFormat;
-
-/**
- * Basic data class. The sorting here is consistent with the sorting in Excel.
- *
- *
- **/
-@Getter
-@Setter
-@EqualsAndHashCode
-public class ConverterData {
- /**
- * I want to add "Custom:" to the beginning of all strings.
- */
- @ExcelProperty(value = "String Title", converter = CustomStringStringConverter.class)
- private String string;
- /**
- * I want to write to Excel using the format "yyyy-MM-dd HH:mm:ss"
- */
- @DateTimeFormat("yyyy-MM-dd HH:mm:ss")
- @ExcelProperty("Date Title")
- private Date date;
- /**
- * I want to write to Excel using percentage format.
- */
- @NumberFormat("#.##%")
- @ExcelProperty(value = "Double Title")
- private Double doubleData;
-}
diff --git a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/write/EscapeHexCellWriteHandlerTest.java b/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/write/EscapeHexCellWriteHandlerTest.java
deleted file mode 100644
index 0d5d266e5..000000000
--- a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/write/EscapeHexCellWriteHandlerTest.java
+++ /dev/null
@@ -1,303 +0,0 @@
-/*
- * 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.demo.write;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileReader;
-import java.nio.file.Path;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import org.apache.fesod.sheet.FesodSheet;
-import org.apache.fesod.sheet.support.ExcelTypeEnum;
-import org.apache.fesod.sheet.write.handler.EscapeHexCellWriteHandler;
-import org.apache.poi.ss.usermodel.Cell;
-import org.apache.poi.ss.usermodel.Row;
-import org.apache.poi.ss.usermodel.Sheet;
-import org.apache.poi.ss.usermodel.Workbook;
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.io.TempDir;
-
-public class EscapeHexCellWriteHandlerTest {
-
- @TempDir
- Path tempDir;
-
- private DemoData createDemoData(String str) {
- DemoData data = new DemoData();
- data.setString(str);
- data.setDate(new Date());
- data.setDoubleData(123.45);
- data.setIgnore("ignoreMe");
- return data;
- }
-
- @Test
- public void testEscapeHex_xlsx_singleHex() throws Exception {
- List list = new ArrayList<>();
- list.add(createDemoData("_xB9f0_"));
-
- File file = tempDir.resolve("testEscapeHex.xlsx").toFile();
- FesodSheet.write(file, DemoData.class)
- .registerWriteHandler(new EscapeHexCellWriteHandler())
- .sheet("TestSheet")
- .doWrite(list);
-
- // Verify the result
- try (Workbook workbook = org.apache.poi.ss.usermodel.WorkbookFactory.create(file)) {
- Sheet sheet = workbook.getSheetAt(0);
- Row row = sheet.getRow(1); // Data row (header is row 0)
- Cell cell = row.getCell(0); // String column
- String actualValue = cell.getStringCellValue();
- System.out.println("XLSX result: " + actualValue);
- Assertions.assertNotEquals("_x005F_xB9f0_", actualValue, "xlsx should not escape _xB9f0_ to _x005F_xB9f0_");
- }
- }
-
- @Test
- public void testEscapeHex_xls_singleHex() throws Exception {
- List list = new ArrayList<>();
- list.add(createDemoData("_xB9f0_"));
-
- File file = tempDir.resolve("testEscapeHex.xls").toFile();
- FesodSheet.write(file, DemoData.class)
- .excelType(ExcelTypeEnum.XLS)
- .registerWriteHandler(new EscapeHexCellWriteHandler())
- .sheet("TestSheet")
- .doWrite(list);
-
- // Verify the result
- try (Workbook workbook = org.apache.poi.ss.usermodel.WorkbookFactory.create(file)) {
- Sheet sheet = workbook.getSheetAt(0);
- Row row = sheet.getRow(1);
- Cell cell = row.getCell(0);
- Assertions.assertNotEquals(
- "_x005F_xB9f0_", cell.getStringCellValue(), "xls should not escape _xB9f0_ to _x005F_xB9f0_");
- }
- }
-
- @Test
- public void testEscapeHex_csv_singleHex() throws Exception {
- List list = new ArrayList<>();
- list.add(createDemoData("_xB9f0_"));
-
- File file = tempDir.resolve("testEscapeHex.csv").toFile();
- FesodSheet.write(file, DemoData.class)
- .excelType(ExcelTypeEnum.CSV)
- .registerWriteHandler(new EscapeHexCellWriteHandler())
- .sheet("TestSheet")
- .doWrite(list);
-
- // Verify the result
- try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
- reader.readLine(); // Skip header
- String dataLine = reader.readLine();
- Assertions.assertNotNull(dataLine);
- Assertions.assertFalse(
- dataLine.contains("_x005F_xB9f0_"),
- "csv should not contain escaped _x005F_xB9f0_, but was: " + dataLine);
- }
- }
-
- @Test
- public void testEscapeHex_multipleHexInOneString() throws Exception {
- List list = new ArrayList<>();
- list.add(createDemoData("_xB9f0_ and _x1234_ and _xABCD_"));
-
- File file = tempDir.resolve("testMultipleHex.xlsx").toFile();
- FesodSheet.write(file, DemoData.class)
- .registerWriteHandler(new EscapeHexCellWriteHandler())
- .sheet("TestSheet")
- .doWrite(list);
-
- try (Workbook workbook = org.apache.poi.ss.usermodel.WorkbookFactory.create(file)) {
- Sheet sheet = workbook.getSheetAt(0);
- Row row = sheet.getRow(1);
- Cell cell = row.getCell(0);
- String expected = "_xB9f0_ and _x1234_ and _xABCD_";
- Assertions.assertEquals(expected, cell.getStringCellValue(), "Multiple hex patterns should all be escaped");
- }
- }
-
- @Test
- public void testEscapeHex_noHexPattern() throws Exception {
- List list = new ArrayList<>();
- list.add(createDemoData("normalString"));
-
- File file = tempDir.resolve("testNoHex.xlsx").toFile();
- FesodSheet.write(file, DemoData.class)
- .registerWriteHandler(new EscapeHexCellWriteHandler())
- .sheet("TestSheet")
- .doWrite(list);
-
- try (Workbook workbook = org.apache.poi.ss.usermodel.WorkbookFactory.create(file)) {
- Sheet sheet = workbook.getSheetAt(0);
- Row row = sheet.getRow(1);
- Cell cell = row.getCell(0);
- Assertions.assertEquals("normalString", cell.getStringCellValue(), "Normal strings should not be modified");
- }
- }
-
- @Test
- public void testEscapeHex_partialHexPattern() throws Exception {
- List list = new ArrayList<>();
- list.add(createDemoData("_x123_ _xABC_ _x12345_")); // Invalid patterns
-
- File file = tempDir.resolve("testPartialHex.xlsx").toFile();
- FesodSheet.write(file, DemoData.class)
- .registerWriteHandler(new EscapeHexCellWriteHandler())
- .sheet("TestSheet")
- .doWrite(list);
-
- try (Workbook workbook = org.apache.poi.ss.usermodel.WorkbookFactory.create(file)) {
- Sheet sheet = workbook.getSheetAt(0);
- Row row = sheet.getRow(1);
- Cell cell = row.getCell(0);
- Assertions.assertEquals(
- "_x123_ _xABC_ _x12345_", cell.getStringCellValue(), "Invalid hex patterns should not be modified");
- }
- }
-
- @Test
- public void testEscapeHex_mixedValidAndInvalidPatterns() throws Exception {
- List list = new ArrayList<>();
- list.add(createDemoData("_x1234_ _x123_ _xABCD_ _xGHIJ_"));
-
- File file = tempDir.resolve("testMixedHex.xlsx").toFile();
- FesodSheet.write(file, DemoData.class)
- .registerWriteHandler(new EscapeHexCellWriteHandler())
- .sheet("TestSheet")
- .doWrite(list);
-
- try (Workbook workbook = org.apache.poi.ss.usermodel.WorkbookFactory.create(file)) {
- Sheet sheet = workbook.getSheetAt(0);
- Row row = sheet.getRow(1);
- Cell cell = row.getCell(0);
- String expected = "_x1234_ _x123_ _xABCD_ _xGHIJ_";
- Assertions.assertEquals(expected, cell.getStringCellValue(), "Only valid hex patterns should be escaped");
- }
- }
-
- @Test
- public void testEscapeHex_emptyAndNullStrings() throws Exception {
- List list = new ArrayList<>();
- DemoData data1 = createDemoData("");
- DemoData data2 = createDemoData(null);
- list.add(data1);
- list.add(data2);
-
- File file = tempDir.resolve("testEmptyNull.xlsx").toFile();
- FesodSheet.write(file, DemoData.class)
- .registerWriteHandler(new EscapeHexCellWriteHandler())
- .sheet("TestSheet")
- .doWrite(list);
-
- try (Workbook workbook = org.apache.poi.ss.usermodel.WorkbookFactory.create(file)) {
- Sheet sheet = workbook.getSheetAt(0);
-
- // Check empty string
- Row row1 = sheet.getRow(1);
- Cell cell1 = row1.getCell(0);
- Assertions.assertEquals("", cell1.getStringCellValue(), "Empty string should remain empty");
-
- // Check null string
- Row row2 = sheet.getRow(2);
- Cell cell2 = row2.getCell(0);
- if (cell2 != null) {
- Assertions.assertEquals("", cell2.getStringCellValue(), "Null string should be handled gracefully");
- }
- }
- }
-
- @Test
- public void testEscapeHex_caseInsensitiveHex() throws Exception {
- List list = new ArrayList<>();
- list.add(createDemoData("_x1a2B_ _XC3d4_ _x9F8e_"));
-
- File file = tempDir.resolve("testCaseInsensitive.xlsx").toFile();
- FesodSheet.write(file, DemoData.class)
- .registerWriteHandler(new EscapeHexCellWriteHandler())
- .sheet("TestSheet")
- .doWrite(list);
-
- try (Workbook workbook = org.apache.poi.ss.usermodel.WorkbookFactory.create(file)) {
- Sheet sheet = workbook.getSheetAt(0);
- Row row = sheet.getRow(1);
- Cell cell = row.getCell(0);
- String expected = "_x1a2B_ _XC3d4_ _x9F8e_";
- Assertions.assertEquals(
- expected, cell.getStringCellValue(), "Case-sensitive hex patterns should be handled correctly");
- }
- }
-
- @Test
- public void testEscapeHex_multipleDifferentFormats() throws Exception {
- List list = new ArrayList<>();
- list.add(createDemoData("_xB9f0_"));
-
- // Test xlsx
- File xlsxFile = tempDir.resolve("testFormats.xlsx").toFile();
- FesodSheet.write(xlsxFile, DemoData.class)
- .registerWriteHandler(new EscapeHexCellWriteHandler())
- .sheet("TestSheet")
- .doWrite(list);
-
- // Test xls
- File xlsFile = tempDir.resolve("testFormats.xls").toFile();
- FesodSheet.write(xlsFile, DemoData.class)
- .excelType(ExcelTypeEnum.XLS)
- .registerWriteHandler(new EscapeHexCellWriteHandler())
- .sheet("TestSheet")
- .doWrite(list);
-
- // Test csv
- File csvFile = tempDir.resolve("testFormats.csv").toFile();
- FesodSheet.write(csvFile, DemoData.class)
- .excelType(ExcelTypeEnum.CSV)
- .registerWriteHandler(new EscapeHexCellWriteHandler())
- .sheet("TestSheet")
- .doWrite(list);
-
- // Verify all formats produce the same escaped result
- try (Workbook xlsxWorkbook = org.apache.poi.ss.usermodel.WorkbookFactory.create(xlsxFile);
- Workbook xlsWorkbook = org.apache.poi.ss.usermodel.WorkbookFactory.create(xlsFile);
- BufferedReader csvReader = new BufferedReader(new FileReader(csvFile))) {
-
- // Check xlsx
- String xlsxValue = xlsxWorkbook.getSheetAt(0).getRow(1).getCell(0).getStringCellValue();
- Assertions.assertEquals("_xB9f0_", xlsxValue);
-
- // Check xls
- String xlsValue = xlsWorkbook.getSheetAt(0).getRow(1).getCell(0).getStringCellValue();
- Assertions.assertEquals("_xB9f0_", xlsValue);
-
- // Check csv
- csvReader.readLine(); // Skip header
- String csvLine = csvReader.readLine();
- Assertions.assertTrue(csvLine.contains("_xB9f0_"));
- Assertions.assertFalse(csvLine.contains("_x005F_xB9f0_"));
-
- // All formats should produce the same result
- Assertions.assertEquals(xlsxValue, xlsValue, "xlsx, csv and xls should produce the same escaped result");
- }
- }
-}
diff --git a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/write/ImageDataWithAnnotation.java b/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/write/ImageDataWithAnnotation.java
deleted file mode 100644
index 59d7b4ace..000000000
--- a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/write/ImageDataWithAnnotation.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * 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.demo.write;
-
-import java.io.File;
-import java.io.InputStream;
-import java.net.URL;
-import lombok.EqualsAndHashCode;
-import lombok.Getter;
-import lombok.Setter;
-import org.apache.fesod.sheet.annotation.ExcelProperty;
-import org.apache.fesod.sheet.annotation.write.style.ColumnWidth;
-import org.apache.fesod.sheet.annotation.write.style.ContentRowHeight;
-import org.apache.fesod.sheet.converters.string.StringImageConverter;
-
-/**
- * 图片导出类
- */
-@Getter
-@Setter
-@EqualsAndHashCode
-@ContentRowHeight(100)
-@ColumnWidth(100 / 8)
-public class ImageDataWithAnnotation {
- private File file;
- private InputStream inputStream;
- /**
- * 如果string类型 必须指定转换器,string默认转换成string
- */
- @ExcelProperty(converter = StringImageConverter.class)
- private String string;
-
- private byte[] byteArray;
- /**
- * 根据url导出
- */
- private URL url;
-}
diff --git a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/write/IndexData.java b/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/write/IndexData.java
deleted file mode 100644
index f4e6129d2..000000000
--- a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/write/IndexData.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * 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.demo.write;
-
-import java.util.Date;
-import lombok.EqualsAndHashCode;
-import lombok.Getter;
-import lombok.Setter;
-import org.apache.fesod.sheet.annotation.ExcelProperty;
-
-/**
- * Basic data class
- *
- *
- **/
-@Getter
-@Setter
-@EqualsAndHashCode
-public class IndexData {
- @ExcelProperty(value = "String Title", index = 0)
- private String string;
-
- @ExcelProperty(value = "Date Title", index = 1)
- private Date date;
- /**
- * Setting index to 3 will result in the second column being empty.
- */
- @ExcelProperty(value = "Double Title", index = 3)
- private Double doubleData;
-}
diff --git a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/write/LongestMatchColumnWidthData.java b/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/write/LongestMatchColumnWidthData.java
deleted file mode 100644
index b3ae2ea28..000000000
--- a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/write/LongestMatchColumnWidthData.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * 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.demo.write;
-
-import java.util.Date;
-import lombok.EqualsAndHashCode;
-import lombok.Getter;
-import lombok.Setter;
-import org.apache.fesod.sheet.annotation.ExcelProperty;
-
-/**
- * Basic data class
- *
- *
- **/
-@Getter
-@Setter
-@EqualsAndHashCode
-public class LongestMatchColumnWidthData {
- @ExcelProperty("String Title")
- private String string;
-
- @ExcelProperty("Date Title is very long Date Title is very long")
- private Date date;
-
- @ExcelProperty("Double")
- private Double doubleData;
-}
diff --git a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/write/WidthAndHeightData.java b/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/write/WidthAndHeightData.java
deleted file mode 100644
index 6b7fe8c5c..000000000
--- a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/write/WidthAndHeightData.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * 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.demo.write;
-
-import java.util.Date;
-import lombok.EqualsAndHashCode;
-import lombok.Getter;
-import lombok.Setter;
-import org.apache.fesod.sheet.annotation.ExcelProperty;
-import org.apache.fesod.sheet.annotation.write.style.ColumnWidth;
-import org.apache.fesod.sheet.annotation.write.style.ContentRowHeight;
-import org.apache.fesod.sheet.annotation.write.style.HeadRowHeight;
-
-/**
- * Basic data class
- *
- *
- **/
-@Getter
-@Setter
-@EqualsAndHashCode
-@ContentRowHeight(10)
-@HeadRowHeight(20)
-@ColumnWidth(25)
-public class WidthAndHeightData {
- @ExcelProperty("String Title")
- private String string;
-
- @ExcelProperty("Date Title")
- private Date date;
- /**
- * Width is 50
- */
- @ColumnWidth(50)
- @ExcelProperty("Double Title")
- private Double doubleData;
-}
diff --git a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/write/WriteCellDemoData.java b/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/write/WriteCellDemoData.java
deleted file mode 100644
index 02704925a..000000000
--- a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/write/WriteCellDemoData.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * 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.demo.write;
-
-import lombok.EqualsAndHashCode;
-import lombok.Getter;
-import lombok.Setter;
-import org.apache.fesod.sheet.metadata.data.WriteCellData;
-
-/**
- * Write via WriteCellData
- *
- *
- */
-@Getter
-@Setter
-@EqualsAndHashCode
-public class WriteCellDemoData {
- /**
- * Hyperlink
- *
- * @since 3.0.0-beta1
- */
- private WriteCellData hyperlink;
-
- /**
- * Comment
- *
- * @since 3.0.0-beta1
- */
- private WriteCellData commentData;
-
- /**
- * Formula
- *
- * @since 3.0.0-beta1
- */
- private WriteCellData formulaData;
-
- /**
- * Specify cell style. Annotations can also be used.
- *
- * @since 3.0.0-beta1
- */
- private WriteCellData writeCellStyle;
-
- /**
- * Specify multiple styles for a single cell
- *
- * @since 3.0.0-beta1
- */
- private WriteCellData richText;
-}
diff --git a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/write/WriteTest.java b/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/write/WriteTest.java
deleted file mode 100644
index 0c8c6a061..000000000
--- a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/write/WriteTest.java
+++ /dev/null
@@ -1,899 +0,0 @@
-/*
- * 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.demo.write;
-
-import java.io.File;
-import java.io.InputStream;
-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.common.util.BooleanUtils;
-import org.apache.fesod.common.util.ListUtils;
-import org.apache.fesod.sheet.ExcelWriter;
-import org.apache.fesod.sheet.FesodSheet;
-import org.apache.fesod.sheet.annotation.ExcelProperty;
-import org.apache.fesod.sheet.annotation.format.DateTimeFormat;
-import org.apache.fesod.sheet.annotation.format.NumberFormat;
-import org.apache.fesod.sheet.annotation.write.style.ColumnWidth;
-import org.apache.fesod.sheet.annotation.write.style.ContentRowHeight;
-import org.apache.fesod.sheet.annotation.write.style.HeadRowHeight;
-import org.apache.fesod.sheet.enums.CellDataTypeEnum;
-import org.apache.fesod.sheet.metadata.data.CommentData;
-import org.apache.fesod.sheet.metadata.data.FormulaData;
-import org.apache.fesod.sheet.metadata.data.HyperlinkData;
-import org.apache.fesod.sheet.metadata.data.ImageData;
-import org.apache.fesod.sheet.metadata.data.RichTextStringData;
-import org.apache.fesod.sheet.metadata.data.WriteCellData;
-import org.apache.fesod.sheet.util.FileUtils;
-import org.apache.fesod.sheet.util.TestFileUtil;
-import org.apache.fesod.sheet.write.handler.CellWriteHandler;
-import org.apache.fesod.sheet.write.handler.EscapeHexCellWriteHandler;
-import org.apache.fesod.sheet.write.handler.SheetWriteHandler;
-import org.apache.fesod.sheet.write.handler.context.CellWriteHandlerContext;
-import org.apache.fesod.sheet.write.handler.context.SheetWriteHandlerContext;
-import org.apache.fesod.sheet.write.merge.LoopMergeStrategy;
-import org.apache.fesod.sheet.write.metadata.WriteSheet;
-import org.apache.fesod.sheet.write.metadata.WriteTable;
-import org.apache.fesod.sheet.write.metadata.style.WriteCellStyle;
-import org.apache.fesod.sheet.write.metadata.style.WriteFont;
-import org.apache.fesod.sheet.write.style.HorizontalCellStyleStrategy;
-import org.apache.fesod.sheet.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.util.CellRangeAddress;
-import org.apache.poi.xssf.streaming.SXSSFSheet;
-import org.junit.jupiter.api.Test;
-
-/**
- * Common writing examples
- *
- *
- */
-public class WriteTest {
-
- /**
- * Simple write
- *
- * 1. Create the entity object corresponding to Excel. Refer to {@link DemoData}
- *
- * 2. Write directly
- */
- @Test
- public void simpleWrite() {
- // Note: simpleWrite can be used when the data volume is not large (within 5000, depending on the actual
- // situation). For large data volumes, refer to repeated writes.
-
- // Method 1 JDK8+
- // since: 3.0.0-beta1
- String fileName = TestFileUtil.getPath() + "simpleWrite" + System.currentTimeMillis() + ".xlsx";
- // Specify the class to use for writing, then write to the first sheet with the name "Template". The file stream
- // will be automatically closed.
- // If you want to use Excel 03, pass the excelType parameter.
- FesodSheet.write(fileName, DemoData.class).sheet("Template").doWrite(() -> {
- // Paging query data
- return data();
- });
-
- // Method 2
- fileName = TestFileUtil.getPath() + "simpleWrite" + System.currentTimeMillis() + ".xlsx";
- // Specify the class to use for writing, then write to the first sheet with the name "Template". The file stream
- // will be automatically closed.
- // If you want to use Excel 03, pass the excelType parameter.
- FesodSheet.write(fileName, DemoData.class).sheet("Template").doWrite(data());
-
- // Method 3
- fileName = TestFileUtil.getPath() + "simpleWrite" + System.currentTimeMillis() + ".xlsx";
- // Specify the class to use for writing
- try (ExcelWriter excelWriter =
- FesodSheet.write(fileName, DemoData.class).build()) {
- WriteSheet writeSheet = FesodSheet.writerSheet("Template").build();
- excelWriter.write(data(), writeSheet);
- }
- }
-
- @Test
- public void testEscapeHex() {
- String fileName = TestFileUtil.getPath() + "simpleWrite" + System.currentTimeMillis() + ".xlsx";
- FesodSheet.write(fileName, DemoData.class)
- .sheet("Template")
- .registerWriteHandler(new EscapeHexCellWriteHandler())
- .doWrite(() -> {
- return dataHex();
- });
- }
-
- /**
- * Export only specified columns based on parameters
- *
- * 1. Create the entity object corresponding to Excel. Refer to {@link DemoData}
- *
- * 2. Include or exclude columns as needed
- *
- * 3. Write directly
- */
- @Test
- public void excludeOrIncludeWrite() {
- String fileName = TestFileUtil.getPath() + "excludeOrIncludeWrite" + System.currentTimeMillis() + ".xlsx";
- // Note: When using the ExcelProperty annotation, if you want to avoid empty columns, you need to use the
- // 'order' field instead of 'index'. 'order' will ignore empty columns and continue sequentially, while 'index'
- // will not ignore empty columns (it stays in the specified column).
-
- // Based on user input fields, assuming we want to ignore 'date'
- Set excludeColumnFieldNames = new HashSet<>();
- excludeColumnFieldNames.add("date");
- // Specify the class to use for writing, then write to the first sheet with the name "Template". The file stream
- // will be automatically closed.
- FesodSheet.write(fileName, DemoData.class)
- .excludeColumnFieldNames(excludeColumnFieldNames)
- .sheet("Template")
- .doWrite(data());
-
- fileName = TestFileUtil.getPath() + "excludeOrIncludeWrite" + System.currentTimeMillis() + ".xlsx";
- // Based on user input fields, assuming we only want to export 'date'
- Set includeColumnFieldNames = new HashSet<>();
- includeColumnFieldNames.add("date");
- // Specify the class to use for writing, then write to the first sheet with the name "Template". The file stream
- // will be automatically closed.
- FesodSheet.write(fileName, DemoData.class)
- .includeColumnFieldNames(includeColumnFieldNames)
- .sheet("Template")
- .doWrite(data());
- }
-
- /**
- * Specify columns to write
- *
- * 1. Create the entity object corresponding to Excel. Refer to {@link IndexData}
- *
- * 2. Use {@link ExcelProperty} annotation to specify columns to write
- *
- * 3. Write directly
- */
- @Test
- public void indexWrite() {
- String fileName = TestFileUtil.getPath() + "indexWrite" + System.currentTimeMillis() + ".xlsx";
- // Specify the class to use for writing, then write to the first sheet with the name "Template". The file stream
- // will be automatically closed.
- FesodSheet.write(fileName, IndexData.class).sheet("Template").doWrite(data());
- }
-
- /**
- * Complex header writing
- *
- * 1. Create the entity object corresponding to Excel. Refer to {@link ComplexHeadData}
- *
- * 2. Use {@link ExcelProperty} annotation to specify complex headers
- *
- * 3. Write directly
- */
- @Test
- public void complexHeadWrite() {
- String fileName = TestFileUtil.getPath() + "complexHeadWrite" + System.currentTimeMillis() + ".xlsx";
- // Specify the class to use for writing, then write to the first sheet with the name "Template". The file stream
- // will be automatically closed.
- FesodSheet.write(fileName, ComplexHeadData.class).sheet("Template").doWrite(data());
- }
-
- /**
- * Repeated writes
- *
- * 1. Create the entity object corresponding to Excel. Refer to {@link ComplexHeadData}
- *
- * 2. Use {@link ExcelProperty} annotation to specify complex headers
- *
- * 3. Call write multiple times
- */
- @Test
- public void repeatedWrite() {
- // Method 1: Writing to the same sheet
- String fileName = TestFileUtil.getPath() + "repeatedWrite" + System.currentTimeMillis() + ".xlsx";
- // Specify the class to use for writing
- try (ExcelWriter excelWriter =
- FesodSheet.write(fileName, DemoData.class).build()) {
- // Note: Create the writeSheet only once if writing to the same sheet
- WriteSheet writeSheet = FesodSheet.writerSheet("Template").build();
- // Call write. Here I called it five times. In actual use, loop based on the total number of pages in the
- // database query.
- for (int i = 0; i < 5; i++) {
- // Paging query data from the database. Here you can query the data for each page.
- List data = data();
- excelWriter.write(data, writeSheet);
- }
- }
-
- // Method 2: Writing to different sheets with the same object
- fileName = TestFileUtil.getPath() + "repeatedWrite" + System.currentTimeMillis() + ".xlsx";
- // Specify file
- try (ExcelWriter excelWriter =
- FesodSheet.write(fileName, DemoData.class).build()) {
- // Call write. Here I called it five times. In actual use, loop based on the total number of pages in the
- // database query. Eventually it will be written to 5 sheets.
- for (int i = 0; i < 5; i++) {
- // Create writeSheet every time. Note that sheetNo must be specified and sheetName must be different.
- WriteSheet writeSheet =
- FesodSheet.writerSheet(i, "Template" + i).build();
- // Paging query data from the database. Here you can query the data for each page.
- List data = data();
- excelWriter.write(data, writeSheet);
- }
- }
-
- // Method 3: Writing to different sheets with different objects
- fileName = TestFileUtil.getPath() + "repeatedWrite" + System.currentTimeMillis() + ".xlsx";
- // Specify file
- try (ExcelWriter excelWriter = FesodSheet.write(fileName).build()) {
- // Call write. Here I called it five times. In actual use, loop based on the total number of pages in the
- // database query. Eventually it will be written to 5 sheets.
- for (int i = 0; i < 5; i++) {
- // Create writeSheet every time. Note that sheetNo must be specified and sheetName must be different.
- // Note that DemoData.class can change each time; I used the same class here for convenience.
- // In reality, it can change every time.
- WriteSheet writeSheet = FesodSheet.writerSheet(i, "Template" + i)
- .head(DemoData.class)
- .build();
- // Paging query data from the database. Here you can query the data for each page.
- List data = data();
- excelWriter.write(data, writeSheet);
- }
- }
- }
-
- /**
- * Date, number, or custom format conversion
- *
- * 1. Create the entity object corresponding to Excel. Refer to {@link ConverterData}
- *
- * 2. Use {@link ExcelProperty} with annotations {@link DateTimeFormat}, {@link NumberFormat}, or custom annotations
- *
- * 3. Write directly
- */
- @Test
- public void converterWrite() {
- String fileName = TestFileUtil.getPath() + "converterWrite" + System.currentTimeMillis() + ".xlsx";
- // Specify the class to use for writing, then write to the first sheet with the name "Template". The file stream
- // will be automatically closed.
- FesodSheet.write(fileName, ConverterData.class).sheet("Template").doWrite(data());
- }
-
- /**
- * Image export
- *
- * 1. Create the entity object corresponding to Excel. Refer to {@link ImageDemoData}
- *
- * 2. Write directly
- */
- @Test
- public void imageWrite() throws Exception {
- String fileName = TestFileUtil.getPath() + "imageWrite" + System.currentTimeMillis() + ".xlsx";
-
- // Note: All images will be loaded into memory. There is no good solution for now. For large numbers of images,
- // it is recommended to:
- // 1. Upload images to OSS or other storage sites: https://www.aliyun.com/product/oss, then verify the link
- // directly
- // 2. Use: https://github.com/coobird/thumbnailator or other tools to compress images
-
- String imagePath = TestFileUtil.getPath() + "converter" + File.separator + "img.jpg";
- try (InputStream inputStream = FileUtils.openInputStream(new File(imagePath))) {
- List list = ListUtils.newArrayList();
- ImageDemoData imageDemoData = new ImageDemoData();
- list.add(imageDemoData);
- // Put five types of images. In actual use, just choose one.
- imageDemoData.setByteArray(FileUtils.readFileToByteArray(new File(imagePath)));
- imageDemoData.setFile(new File(imagePath));
- imageDemoData.setString(imagePath);
- imageDemoData.setInputStream(inputStream);
- imageDemoData.setUrl(new URL("https://poi.apache.org/images/project-header.png"));
-
- // Demonstration
- // Need to add extra text
- // And need to add 2 images
- // The first image is on the left
- // The second is on the right and occupies the cell behind it
- WriteCellData writeCellData = new WriteCellData<>();
- imageDemoData.setWriteCellDataFile(writeCellData);
- // Set to EMPTY to indicate no other data is needed
- writeCellData.setType(CellDataTypeEnum.STRING);
- writeCellData.setStringValue("Extra text");
-
- // Can put multiple images
- List imageDataList = new ArrayList<>();
- ImageData imageData = new ImageData();
- imageDataList.add(imageData);
- writeCellData.setImageDataList(imageDataList);
- // Put binary image
- imageData.setImage(FileUtils.readFileToByteArray(new File(imagePath)));
- // Image type
- imageData.setImageType(ImageData.ImageType.PICTURE_TYPE_PNG);
- // Top, Right, Bottom, Left need padding
- // Similar to CSS margin
- // Tested: cannot set too large. If it exceeds the original cell size, opening it will prompt repair. No
- // good solution found yet.
- imageData.setTop(5);
- imageData.setRight(40);
- imageData.setBottom(5);
- imageData.setLeft(5);
-
- // Put second image
- imageData = new ImageData();
- imageDataList.add(imageData);
- writeCellData.setImageDataList(imageDataList);
- imageData.setImage(FileUtils.readFileToByteArray(new File(imagePath)));
- imageData.setImageType(ImageData.ImageType.PICTURE_TYPE_PNG);
- imageData.setTop(5);
- imageData.setRight(5);
- imageData.setBottom(5);
- imageData.setLeft(50);
- // Set image position. Assume the target is to cover the current cell and the cell to the right.
- // Start point relative to current cell is 0. Can be omitted.
- imageData.setRelativeFirstRowIndex(0);
- imageData.setRelativeFirstColumnIndex(0);
- imageData.setRelativeLastRowIndex(0);
- // First 3 can be omitted. The following one needs to be written, meaning the end needs to move one cell to
- // the right relative to the current cell.
- // This image will cover the current cell and the next one.
- imageData.setRelativeLastColumnIndex(1);
-
- // Write data
- FesodSheet.write(fileName, ImageDemoData.class).sheet().doWrite(list);
- // If image resource is inaccessible, XLSX format will error: SXSSFWorkbook - Failed to dispose sheet
- // Can consider declaring as XLS format
- // FesodSheet.write(fileName, ImageDemoData.class).excelType(ExcelTypeEnum.XLS).sheet().doWrite(list);
- }
- }
-
- /**
- * Hyperlinks, comments, formulas, single cell styling, multiple styles in a single cell
- *
- * 1. Create the entity object corresponding to Excel. Refer to {@link WriteCellDemoData}
- *
- * 2. Write directly
- */
- @Test
- public void writeCellDataWrite() {
- String fileName = TestFileUtil.getPath() + "writeCellDataWrite" + System.currentTimeMillis() + ".xlsx";
- WriteCellDemoData writeCellDemoData = new WriteCellDemoData();
-
- // Set hyperlink
- WriteCellData hyperlink = new WriteCellData<>("Official Website");
- writeCellDemoData.setHyperlink(hyperlink);
- HyperlinkData hyperlinkData = new HyperlinkData();
- hyperlink.setHyperlinkData(hyperlinkData);
- hyperlinkData.setAddress("https://github.com/fast-excel/fastexcel");
- hyperlinkData.setHyperlinkType(HyperlinkData.HyperlinkType.URL);
-
- // Set comment
- WriteCellData comment = new WriteCellData<>("Comment cell info");
- writeCellDemoData.setCommentData(comment);
- CommentData commentData = new CommentData();
- comment.setCommentData(commentData);
- commentData.setAuthor("Jiaju Zhuang");
- commentData.setRichTextStringData(new RichTextStringData("This is a comment"));
- // The default size of the comment is the size of the cell. Here we want to adjust it to the size of 4 cells, so
- // we occupy one extra cell to the right and one extra cell down.
- commentData.setRelativeLastColumnIndex(1);
- commentData.setRelativeLastRowIndex(1);
-
- // Set formula
- WriteCellData formula = new WriteCellData<>();
- writeCellDemoData.setFormulaData(formula);
- FormulaData formulaData = new FormulaData();
- formula.setFormulaData(formulaData);
- // Replace the first digit in 123456789 with 2
- // This is just an example. If it involves formulas, try to calculate them in memory if possible. Avoid using
- // formulas if possible.
- formulaData.setFormulaValue("REPLACE(123456789,1,1,2)");
-
- // Set style for a single cell. If there are many styles, you can use annotations.
- WriteCellData writeCellStyle = new WriteCellData<>("Cell Style");
- writeCellStyle.setType(CellDataTypeEnum.STRING);
- writeCellDemoData.setWriteCellStyle(writeCellStyle);
- WriteCellStyle writeCellStyleData = new WriteCellStyle();
- writeCellStyle.setWriteCellStyle(writeCellStyleData);
- // Need to specify FillPatternType as FillPatternType.SOLID_FOREGROUND, otherwise background color will not be
- // displayed.
- writeCellStyleData.setFillPatternType(FillPatternType.SOLID_FOREGROUND);
- // Green background
- writeCellStyleData.setFillForegroundColor(IndexedColors.GREEN.getIndex());
-
- // Set multiple styles in a single cell
- // Need to set inMemory=true, otherwise multiple styles in a single cell cannot be displayed. Use with caution.
- WriteCellData richTest = new WriteCellData<>();
- richTest.setType(CellDataTypeEnum.RICH_TEXT_STRING);
- writeCellDemoData.setRichText(richTest);
- RichTextStringData richTextStringData = new RichTextStringData();
- richTest.setRichTextStringDataValue(richTextStringData);
- richTextStringData.setTextString("Red Green Default");
- // First 3 characters are red
- WriteFont writeFont = new WriteFont();
- writeFont.setColor(IndexedColors.RED.getIndex());
- richTextStringData.applyFont(0, 3, writeFont);
- // Next 5 characters are green
- writeFont = new WriteFont();
- writeFont.setColor(IndexedColors.GREEN.getIndex());
- richTextStringData.applyFont(4, 9, writeFont);
-
- List data = new ArrayList<>();
- data.add(writeCellDemoData);
- FesodSheet.write(fileName, WriteCellDemoData.class)
- .inMemory(true)
- .sheet("Template")
- .doWrite(data);
- }
-
- /**
- * Write according to template
- *
- * 1. Create the entity object corresponding to Excel. Refer to {@link IndexData}
- *
- * 2. Use {@link ExcelProperty} annotation to specify columns to write
- *
- * 3. Use withTemplate to read template
- *
- * 4. Write directly
- */
- @Test
- public void templateWrite() {
- String templateFileName = TestFileUtil.getPath() + "demo" + File.separator + "demo.xlsx";
- String fileName = TestFileUtil.getPath() + "templateWrite" + System.currentTimeMillis() + ".xlsx";
- // Specify the class to use for writing, then write to the first sheet with the name "Template". The file stream
- // will be automatically closed.
- // Note: withTemplate will store the entire template file in memory, so try not to use it for appending files.
- // If the template file is too large, it will cause OOM.
- // If you want to append to a file (cannot be processed in one thread, refer to the repeated writing demo
- // recommended for one thread), it is recommended to store temporarily in the database or disk cache (ehcache)
- // and then write all at once.
- FesodSheet.write(fileName, DemoData.class)
- .withTemplate(templateFileName)
- .sheet()
- .doWrite(data());
- }
-
- /**
- * Column width and row height
- *
- * 1. Create the entity object corresponding to Excel. Refer to {@link WidthAndHeightData }
- *
- * 2. Use annotations {@link ColumnWidth}, {@link HeadRowHeight}, {@link ContentRowHeight} to specify width or height
- *
- * 3. Write directly
- */
- @Test
- public void widthAndHeightWrite() {
- String fileName = TestFileUtil.getPath() + "widthAndHeightWrite" + System.currentTimeMillis() + ".xlsx";
- // Specify the class to use for writing, then write to the first sheet with the name "Template". The file stream
- // will be automatically closed.
- FesodSheet.write(fileName, WidthAndHeightData.class).sheet("Template").doWrite(data());
- }
-
- /**
- * Custom style via annotations
- *
- * 1. Create the entity object corresponding to Excel. Refer to {@link DemoStyleData}
- *
- * 3. Write directly
- */
- @Test
- public void annotationStyleWrite() {
- String fileName = TestFileUtil.getPath() + "annotationStyleWrite" + System.currentTimeMillis() + ".xlsx";
- // Specify the class to use for writing, then write to the first sheet with the name "Template". The file stream
- // will be automatically closed.
- FesodSheet.write(fileName, DemoStyleData.class).sheet("Template").doWrite(data());
- }
-
- /**
- * Custom style via handlers
- *
- * 1. Create the entity object corresponding to Excel. Refer to {@link DemoData}
- *
- * 2. Create a style strategy and register it
- *
- * 3. Write directly
- */
- @Test
- public void handlerStyleWrite() {
- // Method 1: Use existing strategies (Recommended)
- // HorizontalCellStyleStrategy: styles are the same for each row or alternating rows
- // AbstractVerticalCellStyleStrategy: styles are the same for each column. Need to subclass and implement.
- String fileName = TestFileUtil.getPath() + "handlerStyleWrite" + System.currentTimeMillis() + ".xlsx";
- // Head strategy
- WriteCellStyle headWriteCellStyle = new WriteCellStyle();
- // Background red
- headWriteCellStyle.setFillForegroundColor(IndexedColors.RED.getIndex());
- WriteFont headWriteFont = new WriteFont();
- headWriteFont.setFontHeightInPoints((short) 20);
- headWriteCellStyle.setWriteFont(headWriteFont);
- // Content strategy
- WriteCellStyle contentWriteCellStyle = new WriteCellStyle();
- // Need to specify FillPatternType as SOLID_FOREGROUND. The head defaults to FillPatternType so it can be
- // omitted.
- contentWriteCellStyle.setFillPatternType(FillPatternType.SOLID_FOREGROUND);
- // Background green
- contentWriteCellStyle.setFillForegroundColor(IndexedColors.GREEN.getIndex());
- WriteFont contentWriteFont = new WriteFont();
- // Font size
- contentWriteFont.setFontHeightInPoints((short) 20);
- contentWriteCellStyle.setWriteFont(contentWriteFont);
- // This strategy separates head style and content style. You can implement other strategies yourself.
- HorizontalCellStyleStrategy horizontalCellStyleStrategy =
- new HorizontalCellStyleStrategy(headWriteCellStyle, contentWriteCellStyle);
-
- // Specify the class to use for writing, then write to the first sheet with the name "Template". The file stream
- // will be automatically closed.
- FesodSheet.write(fileName, DemoData.class)
- .registerWriteHandler(horizontalCellStyleStrategy)
- .sheet("Template")
- .doWrite(data());
-
- // Method 2: Write your own handler using Fesod API. Not recommended. Try to use existing strategies.
- fileName = TestFileUtil.getPath() + "handlerStyleWrite" + System.currentTimeMillis() + ".xlsx";
- FesodSheet.write(fileName, DemoData.class)
- .registerWriteHandler(new CellWriteHandler() {
- @Override
- public void afterCellDispose(CellWriteHandlerContext context) {
- // This event is called after data is set into the POI cell
- // Check if it's not a head. If it's fill, this will be null, so use not true.
- if (BooleanUtils.isNotTrue(context.getHead())) {
- // First cell
- // As long as it's not a head, there will be data. Of course in fill scenarios, use
- // context.getCellDataList(). Depending on the template, a cell may have multiple
- // WriteCellData.
- WriteCellData> cellData = context.getFirstCellData();
- // Need to get style from cellData
- // A very important reason is that WriteCellStyle is bound to dataFormatData. For example,
- // if you add DateTimeFormat,
- // the dataFormatData in writeCellStyle has been changed. If you new a WriteCellStyle
- // yourself, the annotation style may be lost.
- // getOrCreateStyle returns a style, creating one if it's null.
- WriteCellStyle writeCellStyle = cellData.getOrCreateStyle();
- writeCellStyle.setFillForegroundColor(IndexedColors.RED.getIndex());
- // Need to specify FillPatternType as SOLID_FOREGROUND
- writeCellStyle.setFillPatternType(FillPatternType.SOLID_FOREGROUND);
-
- // The style is set. There is a FillStyleCellWriteHandler later that will default set
- // WriteCellStyle to the cell, so you don't need to worry about it.
- }
- }
- })
- .sheet("Template")
- .doWrite(data());
-
- // Method 3: Use POI styles directly. Not recommended.
- // Pitfall 1: Style contains dataformat for formatting data, so setting it yourself may cause formatting
- // annotations to fail.
- // Pitfall 2: Don't keep creating styles. Remember to cache them. Creating more than 60,000 will crash.
- fileName = TestFileUtil.getPath() + "handlerStyleWrite" + System.currentTimeMillis() + ".xlsx";
- FesodSheet.write(fileName, DemoData.class)
- .registerWriteHandler(new CellWriteHandler() {
- @Override
- public void afterCellDispose(CellWriteHandlerContext context) {
- // This event is called after data is set into the POI cell
- // Check if it's not a head. If it's fill, this will be null, so use not true.
- if (BooleanUtils.isNotTrue(context.getHead())) {
- Cell cell = context.getCell();
- // Get POI workbook
- Workbook workbook = context.getWriteWorkbookHolder().getWorkbook();
- // Remember to cache reusable parts. A table can have at most 60,000 styles.
- // Try to pass the same cellStyle for different cells
- CellStyle cellStyle = workbook.createCellStyle();
- cellStyle.setFillForegroundColor(IndexedColors.RED.getIndex());
- // Need to specify FillPatternType as SOLID_FOREGROUND
- cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
- cell.setCellStyle(cellStyle);
-
- // Since dataformat is not specified here, the displayed data format may be incorrect.
-
- // Clear the style of WriteCellData. Otherwise, FillStyleCellWriteHandler will override your
- // settings.
- context.getFirstCellData().setWriteCellStyle(null);
- }
- }
- })
- .sheet("Template")
- .doWrite(data());
- }
-
- /**
- * Merge cells
- *
- * 1. Create the entity object corresponding to Excel. Refer to {@link DemoData} {@link DemoMergeData}
- *
- * 2. Create a merge strategy and register it
- *
- * 3. Write directly
- */
- @Test
- public void mergeWrite() {
- // Method 1: Annotation
- String fileName = TestFileUtil.getPath() + "mergeWrite" + System.currentTimeMillis() + ".xlsx";
- // Add ContentLoopMerge annotation in DemoStyleData
- // Specify the class to use for writing, then write to the first sheet with the name "Template". The file stream
- // will be automatically closed.
- FesodSheet.write(fileName, DemoMergeData.class).sheet("Template").doWrite(data());
-
- // Method 2: Custom merge strategy
- fileName = TestFileUtil.getPath() + "mergeWrite" + System.currentTimeMillis() + ".xlsx";
- // Merge every 2 rows. Set eachColumn to 3 (length of our data), so only the first column will merge. Other
- // merge strategies can be implemented.
- LoopMergeStrategy loopMergeStrategy = new LoopMergeStrategy(2, 0);
- // Specify the class to use for writing, then write to the first sheet with the name "Template". The file stream
- // will be automatically closed.
- FesodSheet.write(fileName, DemoData.class)
- .registerWriteHandler(loopMergeStrategy)
- .sheet("Template")
- .doWrite(data());
- }
-
- /**
- * Write using table
- *
- * 1. Create the entity object corresponding to Excel. Refer to {@link DemoData}
- *
- * 2. Then write to the table
- */
- @Test
- public void tableWrite() {
- String fileName = TestFileUtil.getPath() + "tableWrite" + System.currentTimeMillis() + ".xlsx";
- // Method 1: Writing multiple tables here. If there is only one, it can be done in one line.
- // Specify the class to use for writing
- try (ExcelWriter excelWriter =
- FesodSheet.write(fileName, DemoData.class).build()) {
- // Set sheet to not need head, otherwise it will output sheet head, looking like the first table has 2
- // heads.
- WriteSheet writeSheet =
- FesodSheet.writerSheet("Template").needHead(Boolean.FALSE).build();
- // Must specify need head here. Table inherits sheet configuration. If sheet is configured not to need it,
- // table defaults to not needing it.
- WriteTable writeTable0 =
- FesodSheet.writerTable(0).needHead(Boolean.TRUE).build();
- WriteTable writeTable1 =
- FesodSheet.writerTable(1).needHead(Boolean.TRUE).build();
- // First write will create head
- excelWriter.write(data(), writeSheet, writeTable0);
- // Second write will also create head, writing data after the first one.
- excelWriter.write(data(), writeSheet, writeTable1);
- }
- }
-
- /**
- * Dynamic header writing
- *
- * The idea is to first create a sheet with List head format, writing only the head, then write data via table without writing head.
- *
- *
- * 1. Create the entity object corresponding to Excel. Refer to {@link DemoData}
- *
- * 2. Then write to the table
- */
- @Test
- public void dynamicHeadWrite() {
- String fileName = TestFileUtil.getPath() + "dynamicHeadWrite" + System.currentTimeMillis() + ".xlsx";
- FesodSheet.write(fileName)
- // Put dynamic head here
- .head(head())
- .sheet("Template")
- // Of course data can also be passed as List>
- .doWrite(data());
- }
-
- /**
- * Auto column width (not very precise)
- *
- * This is not very easy to use currently. For example, numbers will cause line breaks. And the length is not exactly consistent with actual length. Use with caution if precise column width is needed. You can also re-implement referencing {@link LongestMatchColumnWidthStyleStrategy}.
- *
- * POI's built-in {@link SXSSFSheet#autoSizeColumn(int)} also doesn't support Chinese very well. No good algorithm found yet.
- *
- *
- * 1. Create the entity object corresponding to Excel. Refer to {@link LongestMatchColumnWidthData}
- *
- * 2. Register strategy {@link LongestMatchColumnWidthStyleStrategy}
- *
- * 3. Write directly
- */
- @Test
- public void longestMatchColumnWidthWrite() {
- String fileName =
- TestFileUtil.getPath() + "longestMatchColumnWidthWrite" + System.currentTimeMillis() + ".xlsx";
- // Specify the class to use for writing, then write to the first sheet with the name "Template". The file stream
- // will be automatically closed.
- FesodSheet.write(fileName, LongestMatchColumnWidthData.class)
- .registerWriteHandler(new LongestMatchColumnWidthStyleStrategy())
- .sheet("Template")
- .doWrite(dataLong());
- }
-
- /**
- * Custom handlers for dropdowns, hyperlinks, etc. (Refer to this for operations that don't fit above points but need to manipulate cells)
- *
- * Demo implements 2 points: 1. Hyperlink the head of the first row and first column to URL. 2. Add dropdown box for data in the first column, first and second rows, displaying "Test1", "Test2".
- *
- * 1. Create the entity object corresponding to Excel. Refer to {@link DemoData}
- *
- * 2. Register handlers {@link CustomCellWriteHandler} {@link CustomSheetWriteHandler}
- *
- * 2. Write directly
- */
- @Test
- public void customHandlerWrite() {
- String fileName = TestFileUtil.getPath() + "customHandlerWrite" + System.currentTimeMillis() + ".xlsx";
- // Specify the class to use for writing, then write to the first sheet with the name "Template". The file stream
- // will be automatically closed.
- FesodSheet.write(fileName, DemoData.class)
- .registerWriteHandler(new CustomSheetWriteHandler())
- .registerWriteHandler(new CustomCellWriteHandler())
- .sheet("Template")
- .doWrite(data());
- }
-
- /**
- * Insert comment
- *
- * 1. Create the entity object corresponding to Excel. Refer to {@link DemoData}
- *
- * 2. Register handler {@link CommentWriteHandler}
- *
- * 2. Write directly
- */
- @Test
- public void commentWrite() {
- String fileName = TestFileUtil.getPath() + "commentWrite" + System.currentTimeMillis() + ".xlsx";
- // Specify the class to use for writing, then write to the first sheet with the name "Template". The file stream
- // will be automatically closed.
- // Note that inMemory must be set to true to support comments. Currently there is no good way to handle comments
- // without being in memory.
- FesodSheet.write(fileName, DemoData.class)
- .inMemory(Boolean.TRUE)
- .registerWriteHandler(new CommentWriteHandler())
- .sheet("Template")
- .doWrite(data());
- }
-
- /**
- * Variable title handling (including title internationalization, etc.)
- *
- * Simply put, use List> for titles but still support annotations
- *
- * 1. Create the entity object corresponding to Excel. Refer to {@link ConverterData}
- *
- * 2. Write directly
- */
- @Test
- public void variableTitleWrite() {
- // Method 1
- String fileName = TestFileUtil.getPath() + "variableTitleWrite" + System.currentTimeMillis() + ".xlsx";
- // Specify the class to use for writing, then write to the first sheet with the name "Template". The file stream
- // will be automatically closed.
- FesodSheet.write(fileName, ConverterData.class)
- .head(variableTitleHead())
- .sheet("Template")
- .doWrite(data());
- }
-
- /**
- * Write without creating objects
- */
- @Test
- public void noModelWrite() {
- // Method 1
- String fileName = TestFileUtil.getPath() + "noModelWrite" + System.currentTimeMillis() + ".xlsx";
- // Specify the class to use for writing, then write to the first sheet with the name "Template". The file stream
- // will be automatically closed.
- FesodSheet.write(fileName).head(head()).sheet("Template").doWrite(dataList());
- }
-
- @Test
- public void sheetDisposeTest() {
- String fileName = TestFileUtil.getPath() + "simpleWrite" + System.currentTimeMillis() + ".xlsx";
- FesodSheet.write(fileName, DemoData.class)
- .sheet("Template")
- .registerWriteHandler(new SheetWriteHandler() {
- @Override
- public void afterSheetDispose(SheetWriteHandlerContext context) {
- Sheet sheet = context.getWriteSheetHolder().getSheet();
- // Merge region cells
- sheet.addMergedRegionUnsafe(new CellRangeAddress(1, 10, 2, 2));
- }
- })
- .doWrite(this::data);
- System.out.println(fileName);
- }
-
- private List dataLong() {
- List list = ListUtils.newArrayList();
- for (int i = 0; i < 10; i++) {
- LongestMatchColumnWidthData data = new LongestMatchColumnWidthData();
- data.setString("Testing very long string Testing very long string Testing very long string" + i);
- data.setDate(new Date());
- data.setDoubleData(1000000000000.0);
- list.add(data);
- }
- return list;
- }
-
- private List> variableTitleHead() {
- List> list = ListUtils.newArrayList();
- List head0 = ListUtils.newArrayList();
- head0.add("string" + System.currentTimeMillis());
- List head1 = ListUtils.newArrayList();
- head1.add("number" + System.currentTimeMillis());
- List head2 = ListUtils.newArrayList();
- head2.add("date" + System.currentTimeMillis());
- list.add(head0);
- list.add(head1);
- list.add(head2);
- return list;
- }
-
- private List> head() {
- List> list = ListUtils.newArrayList();
- List head0 = ListUtils.newArrayList();
- head0.add("String" + System.currentTimeMillis());
- List head1 = ListUtils.newArrayList();
- head1.add("Double" + System.currentTimeMillis());
- List head2 = ListUtils.newArrayList();
- head2.add("Date" + System.currentTimeMillis());
- list.add(head0);
- list.add(head1);
- list.add(head2);
- return list;
- }
-
- private List> dataList() {
- List> list = ListUtils.newArrayList();
- for (int i = 0; i < 10; i++) {
- List data = ListUtils.newArrayList();
- data.add("String" + i);
- data.add(0.56);
- data.add(new Date());
- list.add(data);
- }
- return list;
- }
-
- private List data() {
- List list = ListUtils.newArrayList();
- for (int i = 0; i < 10; i++) {
- DemoData data = new DemoData();
- data.setString("STRING" + i);
- data.setDate(new Date());
- data.setDoubleData(0.56);
- list.add(data);
- }
- return list;
- }
-
- private List dataHex() {
- List list = ListUtils.newArrayList();
- for (int i = 0; i < 10; i++) {
- DemoData data = new DemoData();
- data.setString("_xB9f0_");
- data.setDate(new Date());
- data.setDoubleData(0.56);
- list.add(data);
- }
- return list;
- }
-}
diff --git a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/write/WriteWithColorTest.java b/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/write/WriteWithColorTest.java
deleted file mode 100644
index 463ca905b..000000000
--- a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/write/WriteWithColorTest.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * 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.demo.write;
-
-import java.util.LinkedList;
-import java.util.List;
-import org.apache.fesod.sheet.FesodSheet;
-import org.apache.fesod.sheet.util.TestFileUtil;
-import org.junit.jupiter.api.Test;
-
-/**
- * Class for testing colors
- *
- */
-public class WriteWithColorTest {
-
- @Test
- public void write() {
- String fileName = TestFileUtil.getPath() + "simpleWrite" + System.currentTimeMillis() + ".xlsx";
- FesodSheet.write(fileName, ColorDemoData.class).sheet("模板").doWrite(this::data);
- System.out.println(fileName);
- }
-
- private List data() {
- List list = new LinkedList<>();
- for (int i = 0; i < 10; i++) {
- list.add(new ColorDemoData("name" + i, i, "男"));
- }
- return list;
- }
-}
diff --git a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/examples/ExampleTestBase.java b/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/examples/ExampleTestBase.java
new file mode 100644
index 000000000..479ebe7e2
--- /dev/null
+++ b/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/examples/ExampleTestBase.java
@@ -0,0 +1,100 @@
+/*
+ * 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.examples;
+
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.nio.file.Path;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.ss.usermodel.WorkbookFactory;
+
+/**
+ * Base class for Fesod example integration tests.
+ *
+ * Provides common utilities for verifying Excel file output, following the patterns established
+ * by Apache Flink's {@code ExampleOutputTestBase} and {@code AbstractTestBase}.
+ *
+ *
Key utilities:
+ *
+ * {@link #assertValidExcelFile(File)} — verifies a file is a readable Excel workbook
+ * {@link #assertValidExcelFile(File, int)} — additionally verifies minimum row count
+ * {@link #getTempOutputPath(Path, String)} — generates a temp file path within a directory
+ *
+ */
+public abstract class ExampleTestBase {
+
+ /**
+ * Assert that the given file exists, is non-empty, and is a valid Excel workbook that
+ * Apache POI can open.
+ *
+ * @param file the Excel file to validate
+ */
+ protected static void assertValidExcelFile(File file) {
+ assertNotNull(file, "File reference must not be null");
+ assertTrue(file.exists(), "File should exist: " + file.getAbsolutePath());
+ assertTrue(file.length() > 0, "File should not be empty: " + file.getAbsolutePath());
+
+ try (FileInputStream fis = new FileInputStream(file);
+ Workbook workbook = WorkbookFactory.create(fis)) {
+ assertNotNull(workbook, "Workbook should be readable");
+ assertTrue(workbook.getNumberOfSheets() > 0, "Workbook should have at least one sheet");
+ } catch (IOException e) {
+ fail("File should be a valid Excel workbook: " + file.getAbsolutePath() + ", error: " + e.getMessage());
+ }
+ }
+
+ /**
+ * Assert that the given file is a valid Excel workbook with at least the specified number of
+ * data rows (excluding header).
+ *
+ * @param file the Excel file to validate
+ * @param minDataRows the minimum number of data rows expected (excluding header row)
+ */
+ protected static void assertValidExcelFile(File file, int minDataRows) {
+ assertValidExcelFile(file);
+
+ try (FileInputStream fis = new FileInputStream(file);
+ Workbook workbook = WorkbookFactory.create(fis)) {
+ int totalRows = workbook.getSheetAt(0).getPhysicalNumberOfRows();
+ // totalRows includes header row, so data rows = totalRows - 1
+ assertTrue(
+ totalRows > minDataRows,
+ "Expected at least " + minDataRows + " data rows (plus header), but found " + totalRows
+ + " total rows in: " + file.getAbsolutePath());
+ } catch (IOException e) {
+ fail("Failed to read workbook for row count verification: " + e.getMessage());
+ }
+ }
+
+ /**
+ * Generate a temp output file path within the given directory.
+ *
+ * @param tempDir the temporary directory (typically from {@code @TempDir})
+ * @param fileName the desired filename
+ * @return the absolute path as a String
+ */
+ protected static String getTempOutputPath(Path tempDir, String fileName) {
+ return tempDir.resolve(fileName).toAbsolutePath().toString();
+ }
+}
diff --git a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/examples/advanced/CustomConverterExampleITCase.java b/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/examples/advanced/CustomConverterExampleITCase.java
new file mode 100644
index 000000000..1d4304699
--- /dev/null
+++ b/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/examples/advanced/CustomConverterExampleITCase.java
@@ -0,0 +1,39 @@
+/*
+ * 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.examples.advanced;
+
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import org.apache.fesod.sheet.examples.ExampleTestBase;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Test for {@link CustomConverterExample}.
+ *
+ * Verifies the custom-converter round-trip: writes an Excel file with a
+ * {@code CustomStringStringConverter} that transforms string values, then reads them back
+ * using the same converter.
+ */
+class CustomConverterExampleITCase extends ExampleTestBase {
+
+ @Test
+ void testCustomConverterRoundTrip() {
+ assertDoesNotThrow(() -> CustomConverterExample.main(new String[] {}));
+ }
+}
diff --git a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/examples/advanced/LargeFileWriteExampleITCase.java b/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/examples/advanced/LargeFileWriteExampleITCase.java
new file mode 100644
index 000000000..bc2e74376
--- /dev/null
+++ b/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/examples/advanced/LargeFileWriteExampleITCase.java
@@ -0,0 +1,40 @@
+/*
+ * 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.examples.advanced;
+
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import org.apache.fesod.sheet.examples.ExampleTestBase;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Test for {@link LargeFileWriteExample}.
+ *
+ *
Verifies the large-file write example which writes 100,000 rows in batches using
+ * {@code SXSSFWorkbook} with compressed temporary files to reduce disk usage.
+ *
+ *
Note: This test may take several seconds due to the volume of data.
+ */
+class LargeFileWriteExampleITCase extends ExampleTestBase {
+
+ @Test
+ void testCompressedTemporaryFile() {
+ assertDoesNotThrow(LargeFileWriteExample::compressedTemporaryFile);
+ }
+}
diff --git a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/examples/advanced/PasswordProtectionExampleITCase.java b/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/examples/advanced/PasswordProtectionExampleITCase.java
new file mode 100644
index 000000000..1f02c52eb
--- /dev/null
+++ b/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/examples/advanced/PasswordProtectionExampleITCase.java
@@ -0,0 +1,75 @@
+/*
+ * 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.examples.advanced;
+
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import java.io.File;
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import org.apache.fesod.sheet.FesodSheet;
+import org.apache.fesod.sheet.examples.ExampleTestBase;
+import org.apache.fesod.sheet.examples.write.data.DemoData;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+/**
+ * Test for {@link PasswordProtectionExample}.
+ *
+ *
Verifies the full password-protection round-trip: writes a password-protected Excel file,
+ * then reads it back with the same password. Also validates the protected file is a readable
+ * workbook via a controlled write to {@code @TempDir}.
+ */
+class PasswordProtectionExampleITCase extends ExampleTestBase {
+
+ @Test
+ void testPasswordRoundTrip() {
+ assertDoesNotThrow(() -> PasswordProtectionExample.main(new String[] {}));
+ }
+
+ @Test
+ void testPasswordProtectedFileIsValid(@TempDir Path tempDir) {
+ String fileName = getTempOutputPath(tempDir, "password.xlsx");
+ String password = "test123";
+
+ List data = new ArrayList<>();
+ for (int i = 0; i < 5; i++) {
+ DemoData d = new DemoData();
+ d.setString("String" + i);
+ d.setDate(new Date());
+ d.setDoubleData(0.56);
+ data.add(d);
+ }
+
+ FesodSheet.write(fileName)
+ .password(password)
+ .head(DemoData.class)
+ .sheet("Test")
+ .doWrite(data);
+
+ // Password-protected files cannot be opened without the password by POI WorkbookFactory,
+ // so we only verify the file exists and has a non-trivial size.
+ File file = new File(fileName);
+ assertTrue(file.exists(), "Password-protected file should exist");
+ assertTrue(file.length() > 0, "Password-protected file should not be empty");
+ }
+}
diff --git a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/examples/fill/FillBasicExampleITCase.java b/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/examples/fill/FillBasicExampleITCase.java
new file mode 100644
index 000000000..f279d36bb
--- /dev/null
+++ b/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/examples/fill/FillBasicExampleITCase.java
@@ -0,0 +1,38 @@
+/*
+ * 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.examples.fill;
+
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import org.apache.fesod.sheet.examples.ExampleTestBase;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Test for {@link FillBasicExample}.
+ *
+ * Verifies the simple-fill example which fills data into an Excel template ({@code simple.xlsx})
+ * using both object-based and map-based approaches.
+ */
+class FillBasicExampleITCase extends ExampleTestBase {
+
+ @Test
+ void testSimpleFill() {
+ assertDoesNotThrow(FillBasicExample::simpleFill);
+ }
+}
diff --git a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/temp/simple/WriteHandler.java b/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/examples/fill/FillComplexExampleITCase.java
similarity index 59%
rename from fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/temp/simple/WriteHandler.java
rename to fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/examples/fill/FillComplexExampleITCase.java
index df5f52081..77c965dbd 100644
--- a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/temp/simple/WriteHandler.java
+++ b/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/examples/fill/FillComplexExampleITCase.java
@@ -17,22 +17,22 @@
* under the License.
*/
-package org.apache.fesod.sheet.temp.simple;
+package org.apache.fesod.sheet.examples.fill;
-import lombok.extern.slf4j.Slf4j;
-import org.apache.fesod.sheet.write.handler.SheetWriteHandler;
-import org.apache.fesod.sheet.write.metadata.holder.WriteSheetHolder;
-import org.apache.fesod.sheet.write.metadata.holder.WriteWorkbookHolder;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import org.apache.fesod.sheet.examples.ExampleTestBase;
+import org.junit.jupiter.api.Test;
/**
+ * Test for {@link FillComplexExample}.
*
+ *
Verifies the list-fill example which fills a list of {@code FillData} rows into
+ * a template ({@code list.xlsx}). Tests both single-pass and multi-pass fill methods.
*/
-@Slf4j
-public class WriteHandler implements SheetWriteHandler {
+class FillComplexExampleITCase extends ExampleTestBase {
- @Override
- public void afterSheetCreate(WriteWorkbookHolder writeWorkbookHolder, WriteSheetHolder writeSheetHolder) {
- log.info("锁住");
- writeSheetHolder.getSheet().protectSheet("edit");
+ @Test
+ void testListFill() {
+ assertDoesNotThrow(FillComplexExample::listFill);
}
}
diff --git a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/examples/quickstart/SimpleReadExampleITCase.java b/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/examples/quickstart/SimpleReadExampleITCase.java
new file mode 100644
index 000000000..61b3dbe17
--- /dev/null
+++ b/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/examples/quickstart/SimpleReadExampleITCase.java
@@ -0,0 +1,43 @@
+/*
+ * 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.examples.quickstart;
+
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import org.apache.fesod.sheet.examples.ExampleTestBase;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Test for {@link SimpleReadExample}.
+ *
+ *
Verifies that the quickstart read example can successfully read data from the bundled
+ * {@code demo.xlsx} resource without throwing any exceptions.
+ */
+class SimpleReadExampleITCase extends ExampleTestBase {
+
+ @Test
+ void testSimpleRead() {
+ assertDoesNotThrow(SimpleReadExample::simpleRead);
+ }
+
+ @Test
+ void testMain() {
+ assertDoesNotThrow(() -> SimpleReadExample.main(new String[] {}));
+ }
+}
diff --git a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/read/DemoCompatibleHeaderData.java b/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/examples/quickstart/SimpleWriteExampleITCase.java
similarity index 55%
rename from fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/read/DemoCompatibleHeaderData.java
rename to fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/examples/quickstart/SimpleWriteExampleITCase.java
index a1a0e3beb..c0f4374c5 100644
--- a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/read/DemoCompatibleHeaderData.java
+++ b/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/examples/quickstart/SimpleWriteExampleITCase.java
@@ -17,24 +17,27 @@
* under the License.
*/
-package org.apache.fesod.sheet.demo.read;
+package org.apache.fesod.sheet.examples.quickstart;
-import java.util.Date;
-import lombok.Data;
-import org.apache.fesod.sheet.annotation.ExcelProperty;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import org.apache.fesod.sheet.examples.ExampleTestBase;
+import org.junit.jupiter.api.Test;
/**
- * Compatible header data class.
+ * Test for {@link SimpleWriteExample}.
+ *
+ *
Verifies that the quickstart write example can produce an Excel file. The example writes
+ * 10 rows of {@code DemoData} to a temp file via {@code ExampleFileUtil.getTempPath()}.
*/
-@Data
-public class DemoCompatibleHeaderData {
-
- @ExcelProperty("String")
- private String string;
+class SimpleWriteExampleITCase extends ExampleTestBase {
- @ExcelProperty("Date")
- private Date date;
+ @Test
+ void testSimpleWrite() {
+ assertDoesNotThrow(SimpleWriteExample::simpleWrite);
+ }
- @ExcelProperty("DoubleData")
- private Double doubleData;
+ @Test
+ void testMain() {
+ assertDoesNotThrow(() -> SimpleWriteExample.main(new String[] {}));
+ }
}
diff --git a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/examples/read/BasicReadExampleITCase.java b/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/examples/read/BasicReadExampleITCase.java
new file mode 100644
index 000000000..6e09edc08
--- /dev/null
+++ b/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/examples/read/BasicReadExampleITCase.java
@@ -0,0 +1,38 @@
+/*
+ * 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.examples.read;
+
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import org.apache.fesod.sheet.examples.ExampleTestBase;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Test for {@link BasicReadExample}.
+ *
+ *
Verifies the basic read example which reads {@code demo.xlsx} using a typed
+ * {@code DemoDataListener} to process each row.
+ */
+class BasicReadExampleITCase extends ExampleTestBase {
+
+ @Test
+ void testBasicRead() {
+ assertDoesNotThrow(BasicReadExample::basicRead);
+ }
+}
diff --git a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/temp/read/TestListener.java b/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/examples/read/ConverterReadExampleITCase.java
similarity index 59%
rename from fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/temp/read/TestListener.java
rename to fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/examples/read/ConverterReadExampleITCase.java
index 7d478a232..42fcc9eb7 100644
--- a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/temp/read/TestListener.java
+++ b/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/examples/read/ConverterReadExampleITCase.java
@@ -17,27 +17,22 @@
* under the License.
*/
-package org.apache.fesod.sheet.temp.read;
+package org.apache.fesod.sheet.examples.read;
-import com.alibaba.fastjson2.JSON;
-import lombok.extern.slf4j.Slf4j;
-import org.apache.fesod.sheet.context.AnalysisContext;
-import org.apache.fesod.sheet.event.AnalysisEventListener;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import org.apache.fesod.sheet.examples.ExampleTestBase;
+import org.junit.jupiter.api.Test;
/**
- * TODO
+ * Test for {@link ConverterReadExample}.
*
- *
- * @date 2020/4/9 16:33
- **/
-@Slf4j
-public class TestListener extends AnalysisEventListener {
+ *
Verifies that the converter read example can read {@code demo.xlsx} with a custom
+ * {@code CustomStringStringConverter} applied during the read process.
+ */
+class ConverterReadExampleITCase extends ExampleTestBase {
- @Override
- public void invoke(Object o, AnalysisContext analysisContext) {
- log.info("解析一条:{}", JSON.toJSONString(o));
+ @Test
+ void testConverterRead() {
+ assertDoesNotThrow(ConverterReadExample::converterRead);
}
-
- @Override
- public void doAfterAllAnalysed(AnalysisContext analysisContext) {}
}
diff --git a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/examples/read/ExceptionHandlingExampleITCase.java b/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/examples/read/ExceptionHandlingExampleITCase.java
new file mode 100644
index 000000000..9cdc41b79
--- /dev/null
+++ b/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/examples/read/ExceptionHandlingExampleITCase.java
@@ -0,0 +1,38 @@
+/*
+ * 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.examples.read;
+
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import org.apache.fesod.sheet.examples.ExampleTestBase;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Test for {@link ExceptionHandlingExample}.
+ *
+ *
Verifies that the exception handling read example processes all rows from {@code demo.xlsx},
+ * demonstrating proper error handling within the listener callback.
+ */
+class ExceptionHandlingExampleITCase extends ExampleTestBase {
+
+ @Test
+ void testExceptionRead() {
+ assertDoesNotThrow(ExceptionHandlingExample::exceptionRead);
+ }
+}
diff --git a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/read/DemoExtraData.java b/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/examples/read/IndexOrNameReadExampleITCase.java
similarity index 61%
rename from fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/read/DemoExtraData.java
rename to fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/examples/read/IndexOrNameReadExampleITCase.java
index c5ef63e65..d3bc3e95a 100644
--- a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/read/DemoExtraData.java
+++ b/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/examples/read/IndexOrNameReadExampleITCase.java
@@ -17,21 +17,21 @@
* under the License.
*/
-package org.apache.fesod.sheet.demo.read;
+package org.apache.fesod.sheet.examples.read;
-import lombok.EqualsAndHashCode;
-import lombok.Getter;
-import lombok.Setter;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import org.apache.fesod.sheet.examples.ExampleTestBase;
+import org.junit.jupiter.api.Test;
/**
+ * Test for {@link IndexOrNameReadExample}.
*
+ *
Verifies reading Excel columns by index or name annotation from {@code demo.xlsx}.
*/
-@Getter
-@Setter
-@EqualsAndHashCode
-public class DemoExtraData {
+class IndexOrNameReadExampleITCase extends ExampleTestBase {
- private String row1;
-
- private String row2;
+ @Test
+ void testIndexOrNameRead() {
+ assertDoesNotThrow(IndexOrNameReadExample::indexOrNameRead);
+ }
}
diff --git a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/examples/read/MultiSheetReadExampleITCase.java b/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/examples/read/MultiSheetReadExampleITCase.java
new file mode 100644
index 000000000..bb575204b
--- /dev/null
+++ b/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/examples/read/MultiSheetReadExampleITCase.java
@@ -0,0 +1,38 @@
+/*
+ * 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.examples.read;
+
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import org.apache.fesod.sheet.examples.ExampleTestBase;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Test for {@link MultiSheetReadExample}.
+ *
+ *
Verifies that the multi-sheet read example correctly reads the same file multiple times
+ * using different listeners, demonstrating sheet-level repeated read capability.
+ */
+class MultiSheetReadExampleITCase extends ExampleTestBase {
+
+ @Test
+ void testMultiSheetRead() {
+ assertDoesNotThrow(MultiSheetReadExample::repeatedRead);
+ }
+}
diff --git a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/examples/read/NoModelReadExampleITCase.java b/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/examples/read/NoModelReadExampleITCase.java
new file mode 100644
index 000000000..51d7b04a5
--- /dev/null
+++ b/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/examples/read/NoModelReadExampleITCase.java
@@ -0,0 +1,38 @@
+/*
+ * 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.examples.read;
+
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import org.apache.fesod.sheet.examples.ExampleTestBase;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Test for {@link NoModelReadExample}.
+ *
+ *
Verifies that the no-model read example can read {@code demo.xlsx} without a pre-defined
+ * data class, using {@code Map} to receive each row's data.
+ */
+class NoModelReadExampleITCase extends ExampleTestBase {
+
+ @Test
+ void testNoModelRead() {
+ assertDoesNotThrow(NoModelReadExample::noModelRead);
+ }
+}
diff --git a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/read/DemoDAO.java b/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/examples/web/FesodWebApplicationITCase.java
similarity index 63%
rename from fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/read/DemoDAO.java
rename to fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/examples/web/FesodWebApplicationITCase.java
index 92e22ea35..e34e14139 100644
--- a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/demo/read/DemoDAO.java
+++ b/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/examples/web/FesodWebApplicationITCase.java
@@ -17,18 +17,19 @@
* under the License.
*/
-package org.apache.fesod.sheet.demo.read;
+package org.apache.fesod.sheet.examples.web;
-import java.util.List;
+import org.junit.jupiter.api.Test;
+import org.springframework.boot.test.context.SpringBootTest;
/**
- * 假设这个是你的DAO存储。当然还要这个类让spring管理,当然你不用需要存储,也不需要这个类。
- *
- *
- **/
-public class DemoDAO {
+ * Integration test that verifies FesodWebApplication starts successfully.
+ */
+@SpringBootTest(classes = FesodWebApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
+class FesodWebApplicationITCase {
- public void save(List list) {
- // 如果是mybatis,尽量别直接调用多次insert,自己写一个mapper里面新增一个方法batchInsert,所有数据一次性插入
+ @Test
+ void contextLoads() {
+ // If the application context fails to start, this test will fail.
}
}
diff --git a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/examples/write/BasicWriteExampleITCase.java b/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/examples/write/BasicWriteExampleITCase.java
new file mode 100644
index 000000000..6d2ecdf4e
--- /dev/null
+++ b/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/examples/write/BasicWriteExampleITCase.java
@@ -0,0 +1,62 @@
+/*
+ * 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.examples.write;
+
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import java.io.File;
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import org.apache.fesod.sheet.FesodSheet;
+import org.apache.fesod.sheet.examples.ExampleTestBase;
+import org.apache.fesod.sheet.examples.write.data.DemoData;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+/**
+ * Test for {@link BasicWriteExample}.
+ *
+ * Verifies: (1) the example completes without exception, and (2) a separate controlled write
+ * to a {@code @TempDir} produces a valid Excel workbook with the expected number of data rows.
+ */
+class BasicWriteExampleITCase extends ExampleTestBase {
+
+ @Test
+ void testBasicWrite() {
+ assertDoesNotThrow(BasicWriteExample::basicWrite);
+ }
+
+ @Test
+ void testWriteProducesValidExcel(@TempDir Path tempDir) {
+ String fileName = getTempOutputPath(tempDir, "basicWrite.xlsx");
+ List data = new ArrayList<>();
+ for (int i = 0; i < 10; i++) {
+ DemoData d = new DemoData();
+ d.setString("String" + i);
+ d.setDate(new Date());
+ d.setDoubleData(0.56);
+ data.add(d);
+ }
+ FesodSheet.write(fileName, DemoData.class).sheet("Template").doWrite(data);
+
+ assertValidExcelFile(new File(fileName), 10);
+ }
+}
diff --git a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/examples/write/MergeWriteExampleITCase.java b/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/examples/write/MergeWriteExampleITCase.java
new file mode 100644
index 000000000..94103ea75
--- /dev/null
+++ b/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/examples/write/MergeWriteExampleITCase.java
@@ -0,0 +1,38 @@
+/*
+ * 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.examples.write;
+
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import org.apache.fesod.sheet.examples.ExampleTestBase;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Test for {@link MergeWriteExample}.
+ *
+ * Verifies both merge strategies: (1) annotation-based merge via {@code @ContentLoopMerge}
+ * and (2) programmatic merge via {@code LoopMergeStrategy}. Each strategy writes a separate file.
+ */
+class MergeWriteExampleITCase extends ExampleTestBase {
+
+ @Test
+ void testMergeWrite() {
+ assertDoesNotThrow(MergeWriteExample::mergeWrite);
+ }
+}
diff --git a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/examples/write/StyleWriteExampleITCase.java b/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/examples/write/StyleWriteExampleITCase.java
new file mode 100644
index 000000000..12d97d987
--- /dev/null
+++ b/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/examples/write/StyleWriteExampleITCase.java
@@ -0,0 +1,38 @@
+/*
+ * 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.examples.write;
+
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import org.apache.fesod.sheet.examples.ExampleTestBase;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Test for {@link StyleWriteExample}.
+ *
+ *
Verifies that the style-write example can produce an Excel file with annotation-based
+ * cell styles ({@code @ContentStyle}, {@code @HeadStyle}) applied to a {@code DemoStyleData} model.
+ */
+class StyleWriteExampleITCase extends ExampleTestBase {
+
+ @Test
+ void testStyleWrite() {
+ assertDoesNotThrow(StyleWriteExample::styleWrite);
+ }
+}
diff --git a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/temp/CamlData.java b/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/temp/CamlData.java
deleted file mode 100644
index a67d55f82..000000000
--- a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/temp/CamlData.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * 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.temp;
-
-import lombok.EqualsAndHashCode;
-import lombok.Getter;
-import lombok.Setter;
-
-/**
- *
- */
-@Getter
-@Setter
-@EqualsAndHashCode
-public class CamlData {
- private String string1;
- private String String2;
- private String sTring3;
- private String STring4;
- private String STRING5;
- private String STRing6;
-}
diff --git a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/temp/DemoData3.java b/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/temp/DemoData3.java
deleted file mode 100644
index 22209f62f..000000000
--- a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/temp/DemoData3.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * 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.temp;
-
-import java.time.LocalDateTime;
-import lombok.EqualsAndHashCode;
-import lombok.Getter;
-import lombok.Setter;
-import org.apache.fesod.sheet.annotation.ExcelProperty;
-
-/**
- * 基础数据类
- *
- *
- **/
-@Getter
-@Setter
-@EqualsAndHashCode
-public class DemoData3 {
- @ExcelProperty("日期时间标题")
- private LocalDateTime localDateTime;
-}
diff --git a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/temp/FillTempTest.java b/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/temp/FillTempTest.java
deleted file mode 100644
index 0148e5737..000000000
--- a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/temp/FillTempTest.java
+++ /dev/null
@@ -1,141 +0,0 @@
-/*
- * 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.temp;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import org.apache.fesod.sheet.ExcelWriter;
-import org.apache.fesod.sheet.FastExcel;
-import org.apache.fesod.sheet.demo.fill.FillData;
-import org.apache.fesod.sheet.temp.fill.FillData2;
-import org.apache.fesod.sheet.util.TestFileUtil;
-import org.apache.fesod.sheet.write.merge.OnceAbsoluteMergeStrategy;
-import org.apache.fesod.sheet.write.metadata.WriteSheet;
-import org.junit.jupiter.api.Test;
-
-/**
- * 写的填充写法
- */
-public class FillTempTest {
-
- /**
- * 复杂的填充
- */
- @Test
- public void complexFill() {
- // 模板注意 用{} 来表示你要用的变量 如果本来就有"{","}" 特殊字符 用"\{","\}"代替
- // {} 代表普通变量 {.} 代表是list的变量
- OnceAbsoluteMergeStrategy onceAbsoluteMergeStrategy = new OnceAbsoluteMergeStrategy(2, 2, 0, 1);
-
- String fileName = TestFileUtil.getPath() + "complexFill" + System.currentTimeMillis() + ".xlsx";
- ExcelWriter excelWriter = FastExcel.write(fileName)
- .registerWriteHandler(onceAbsoluteMergeStrategy)
- .withTemplate("src/test/resources/demo/fill/simple.xlsx")
- .build();
- WriteSheet writeSheet0 = FastExcel.writerSheet(0).build();
- WriteSheet writeSheet1 = FastExcel.writerSheet(1).build();
-
- excelWriter.fill(teamp(), writeSheet0);
- excelWriter.fill(teamp(), writeSheet1);
-
- Map map = new HashMap();
- map.put("date", "2019年10月9日13:28:28");
- map.put("total", 1000);
- excelWriter.fill(map, writeSheet0);
-
- excelWriter.finish();
- }
-
- /**
- * 数据量大的复杂填充
- *
- * 这里的解决方案是 确保模板list为最后一行,然后再拼接table.还有03版没救,只能刚正面加内存。
- */
- @Test
- public void complexFillWithTable() {
- // 模板注意 用{} 来表示你要用的变量 如果本来就有"{","}" 特殊字符 用"\{","\}"代替
- // {} 代表普通变量 {.} 代表是list的变量
- // 这里模板 删除了list以后的数据,也就是统计的这一行
- String templateFileName = "src/test/resources/demo/fill/complexFillWithTable.xlsx";
-
- String fileName = TestFileUtil.getPath() + "complexFillWithTable" + System.currentTimeMillis() + ".xlsx";
- ExcelWriter excelWriter =
- FastExcel.write(fileName).withTemplate(templateFileName).build();
- WriteSheet writeSheet = FastExcel.writerSheet().build();
- // 直接写入数据
- excelWriter.fill(data(), writeSheet);
- excelWriter.fill(data2(), writeSheet);
-
- // 写入list之前的数据
- Map map = new HashMap();
- map.put("date", "2019年10月9日13:28:28");
- excelWriter.fill(map, writeSheet);
-
- // list 后面还有个统计 想办法手动写入
- // 这里偷懒直接用list 也可以用对象
- List> totalListList = new ArrayList>();
- List totalList = new ArrayList();
- totalListList.add(totalList);
- totalList.add(null);
- totalList.add(null);
- totalList.add(null);
- // 第四列
- totalList.add("统计:1000");
- // 这里是write 别和fill 搞错了
- excelWriter.write(totalListList, writeSheet);
- excelWriter.finish();
- // 总体上写法比较复杂 但是也没有想到好的版本 异步的去写入excel 不支持行的删除和移动,也不支持备注这种的写入,所以也排除了可以
- // 新建一个 然后一点点复制过来的方案,最后导致list需要新增行的时候,后面的列的数据没法后移,后续会继续想想解决方案
- }
-
- private List data2() {
- List list = new ArrayList();
- for (int i = 0; i < 10; i++) {
- FillData2 fillData = new FillData2();
- list.add(fillData);
- fillData.setTest("ttttttt" + i);
- }
- return list;
- }
-
- private List teamp() {
- List list = new ArrayList();
- for (int i = 0; i < 10; i++) {
- TempFillData fillData = new TempFillData();
- list.add(fillData);
- fillData.setName("张三");
- fillData.setNumber(5.2);
- }
- return list;
- }
-
- private List data() {
- List list = new ArrayList();
- for (int i = 0; i < 10; i++) {
- FillData fillData = new FillData();
- list.add(fillData);
- fillData.setName("张三");
- fillData.setNumber(5.2);
- }
- return list;
- }
-}
diff --git a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/temp/Lock2Test.java b/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/temp/Lock2Test.java
deleted file mode 100644
index 20f69f63f..000000000
--- a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/temp/Lock2Test.java
+++ /dev/null
@@ -1,501 +0,0 @@
-/*
- * 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.temp;
-
-import com.alibaba.fastjson2.JSON;
-import java.io.File;
-import java.math.BigDecimal;
-import java.math.MathContext;
-import java.math.RoundingMode;
-import java.nio.file.Path;
-import java.text.DecimalFormat;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.time.LocalDateTime;
-import java.time.format.DateTimeFormatter;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.collections4.CollectionUtils;
-import org.apache.fesod.common.util.PositionUtils;
-import org.apache.fesod.sheet.FastExcel;
-import org.apache.fesod.sheet.demo.write.DemoData;
-import org.apache.fesod.sheet.metadata.data.ReadCellData;
-import org.apache.fesod.sheet.util.TestFileUtil;
-import org.apache.fesod.sheet.write.metadata.style.WriteCellStyle;
-import org.apache.fesod.sheet.write.metadata.style.WriteFont;
-import org.apache.fesod.sheet.write.style.HorizontalCellStyleStrategy;
-import org.apache.poi.ss.usermodel.DateUtil;
-import org.apache.poi.ss.usermodel.FillPatternType;
-import org.apache.poi.ss.usermodel.IndexedColors;
-import org.apache.poi.ss.util.CellReference;
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.io.TempDir;
-
-/**
- * 临时测试
- *
- *
- **/
-@Slf4j
-public class Lock2Test {
-
- @Test
- public void test() throws Exception {
- List list = FastExcel.read("src/test/resources/converter/converter07.xlsx")
- // .useDefaultListener(false)
- .sheet(0)
- .headRowNumber(0)
- .doReadSync();
- log.info("数据:{}", list.size());
- for (Object data : list) {
- log.info("返回数据:{}", CollectionUtils.size(data));
- log.info("返回数据:{}", JSON.toJSONString(data));
- }
- }
-
- @Test
- public void test33() throws Exception {
- File file = new File("src/test/resources/temp/lock_data.xlsx");
-
- FastExcel.read(file, LockData.class, new LockDataListener())
- .sheet(0)
- .headRowNumber(0)
- .doRead();
- }
-
- @Test
- public void write() throws Exception {
- String fileName = TestFileUtil.getPath() + "styleWrite" + System.currentTimeMillis() + ".xlsx";
- // 头的策略
- WriteCellStyle headWriteCellStyle = new WriteCellStyle();
- // 背景设置为红色
- headWriteCellStyle.setFillForegroundColor(IndexedColors.RED.getIndex());
- WriteFont headWriteFont = new WriteFont();
- headWriteFont.setFontHeightInPoints((short) 20);
- headWriteCellStyle.setWriteFont(headWriteFont);
- // 内容的策略
- WriteCellStyle contentWriteCellStyle = new WriteCellStyle();
- // 这里需要指定 FillPatternType 为FillPatternType.SOLID_FOREGROUND 不然无法显示背景颜色.头默认了 FillPatternType所以可以不指定
- contentWriteCellStyle.setFillPatternType(FillPatternType.SOLID_FOREGROUND);
- // 背景绿色
- contentWriteCellStyle.setFillForegroundColor(IndexedColors.GREEN.getIndex());
- WriteFont contentWriteFont = new WriteFont();
- // 字体大小
- contentWriteFont.setFontHeightInPoints((short) 20);
- contentWriteCellStyle.setWriteFont(contentWriteFont);
- // 这个策略是 头是头的样式 内容是内容的样式 其他的策略可以自己实现
- HorizontalCellStyleStrategy horizontalCellStyleStrategy =
- new HorizontalCellStyleStrategy(headWriteCellStyle, contentWriteCellStyle);
-
- // 这里 需要指定写用哪个class去写,然后写到第一个sheet,名字为模板 然后文件流会自动关闭
- FastExcel.write(fileName, DemoData.class)
- .registerWriteHandler(horizontalCellStyleStrategy)
- .sheet("模板")
- .doWrite(data());
- }
-
- @Test
- public void simpleWrite() {
- String fileName = TestFileUtil.getPath() + System.currentTimeMillis() + ".xlsx";
- System.out.println(fileName);
- FastExcel.write(fileName).head(head()).sheet("模板").doWrite(dataList());
- }
-
- private List> head() {
- List> list = new ArrayList>();
- List head0 = new ArrayList();
- head0.add("表头");
-
- list.add(head0);
- return list;
- }
-
- private List> dataList() {
- List> list = new ArrayList>();
- List data = new ArrayList();
- data.add("字符串");
- data.add(new Date());
- data.add(0.56);
- list.add(data);
- return list;
- }
-
- @Test
- public void testc() throws Exception {
- log.info("reslut:{}", JSON.toJSONString(new CellReference("B3")));
- }
-
- @Test
- public void simpleRead() {
- // 写法1:
- String fileName = "src/test/resources/temp/lock_data.xlsx";
- // 这里 需要指定读用哪个class去读,然后读取第一个sheet 文件流会自动关闭
- FastExcel.read(fileName, LockData.class, new LockDataListener())
- .useDefaultListener(false)
- .sheet()
- .doRead();
- }
-
- @Test
- public void test2(@TempDir Path tempDir) throws Exception {
- File file = tempDir.resolve(System.currentTimeMillis() + ".xlsx").toFile();
- FastExcel.write().file(file).sheet().doWrite(dataList());
- List list = FastExcel.read(file).sheet().headRowNumber(0).doReadSync();
- log.info("数据:{}", list.size());
- for (Object data : list) {
- log.info("返回数据:{}", JSON.toJSONString(data));
- }
- log.info("文件状态:{}", file.exists());
- file.delete();
- }
-
- @Test
- public void test335() throws Exception {
-
- log.info("reslut:{}", PositionUtils.getCol("A10", null));
- log.info("reslut:{}", PositionUtils.getRow("A10"));
- log.info("reslut:{}", PositionUtils.getCol("AB10", null));
- log.info("reslut:{}", PositionUtils.getRow("AB10"));
-
- // log.info("reslut:{}", PositionUtils2.getCol("A10",null));
- // log.info("reslut:{}", PositionUtils2.getRow("A10"));
- // log.info("reslut:{}", PositionUtils2.getCol("AB10",null));
- // log.info("reslut:{}", PositionUtils2.getRow("AB10"));
- }
-
- @Test
- public void numberforamt() throws Exception {
- SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
-
- // log.info("date:{}",
- // NumberDataFormatterUtils.format(BigDecimal.valueOf(44727.99998842592), (short)200, "yyyy-MM-dd HH:mm:ss",
- // null,
- // null, null));
- //
- // log.info("date:{}",
- // NumberDataFormatterUtils.format(BigDecimal.valueOf(44728.99998842592), (short)200, "yyyy-MM-dd HH:mm:ss",
- // null,
- // null, null));
- //
- // log.info("date:{}",
- // NumberDataFormatterUtils.format(BigDecimal.valueOf(44729.99998836806), (short)200, "yyyy-MM-dd HH:mm:ss",
- // null,
- // null, null));
- //
- // log.info("date:{}",
- // NumberDataFormatterUtils.format(BigDecimal.valueOf(44727.99998842592).setScale(10, RoundingMode
- // .HALF_UP), (short)200, "yyyy-MM-dd HH:mm:ss",
- // null,
- // null, null));
- //
- // log.info("date:{}",
- // NumberDataFormatterUtils.format(BigDecimal.valueOf(44728.99998842592).setScale(10, RoundingMode
- // .HALF_UP), (short)200, "yyyy-MM-dd HH:mm:ss",
- // null,
- // null, null));
-
- // 44729.9999883681
- // 44729.999988368058
- // log.info("date:{}",
- // NumberDataFormatterUtils.format(BigDecimal.valueOf(44729.999988368058).setScale(10, RoundingMode
- // .HALF_UP), (short)200, "yyyy-MM-dd HH:mm:ss",
- // null,
- // null, null));
- // log.info("date:{}",BigDecimal.valueOf(44729.999988368058).setScale(10, RoundingMode.HALF_UP).doubleValue
- // ());
-
- // 2022/6/17 23:59:59
- // 期望 44729.99998842592
- // log.info("data:{}", DateUtil.getJavaDate(44729.9999883681, true));
- log.info(
- "data4:{}",
- DateUtil.getJavaDate(
- BigDecimal.valueOf(44729.999988368058)
- .setScale(4, RoundingMode.HALF_UP)
- .doubleValue(),
- false));
- log.info(
- "data5:{}",
- DateUtil.getJavaDate(
- BigDecimal.valueOf(44729.999988368058)
- .setScale(5, RoundingMode.HALF_UP)
- .doubleValue(),
- false));
- log.info(
- "data6:{}",
- DateUtil.getJavaDate(
- BigDecimal.valueOf(44729.999988368058)
- .setScale(6, RoundingMode.HALF_UP)
- .doubleValue(),
- false));
- log.info(
- "data7:{}",
- DateUtil.getJavaDate(
- BigDecimal.valueOf(44729.999988368058)
- .setScale(7, RoundingMode.HALF_UP)
- .doubleValue(),
- false));
- log.info(
- "data8:{}",
- DateUtil.getJavaDate(
- BigDecimal.valueOf(44729.999988368058)
- .setScale(8, RoundingMode.HALF_UP)
- .doubleValue(),
- false));
-
- log.info("data:{}", format.format(DateUtil.getJavaDate(44729.999988368058, false)));
- log.info("data:{}", format.format(DateUtil.getJavaDate(44729.9999883681, false)));
-
- log.info("data:{}", DateUtil.getJavaDate(Double.parseDouble("44729.999988368058"), false));
- log.info("data:{}", DateUtil.getJavaDate(Double.parseDouble("44729.9999883681"), false));
-
- // 44729.999976851854
- // 44729.999988368058
- Assertions.assertThrows(ParseException.class, () -> DateUtil.getExcelDate(format.parse("2022-06-17 23:59:58")));
- // 44729.99998842592
- Assertions.assertThrows(ParseException.class, () -> DateUtil.getExcelDate(format.parse("2022-06-17 23:59:59")));
-
- log.info(
- "data:{}",
- DateUtil.getJavaDate(
- BigDecimal.valueOf(44729.999976851854)
- .setScale(10, RoundingMode.HALF_UP)
- .doubleValue(),
- false));
- log.info(
- "data:{}",
- DateUtil.getJavaDate(
- BigDecimal.valueOf(44729.99998842592)
- .setScale(10, RoundingMode.HALF_UP)
- .doubleValue(),
- false));
-
- log.info(
- "data:{}",
- DateUtil.getJavaDate(
- BigDecimal.valueOf(44729.999976851854)
- .setScale(5, RoundingMode.HALF_UP)
- .doubleValue(),
- false));
- log.info(
- "data:{}",
- DateUtil.getJavaDate(
- BigDecimal.valueOf(44729.99998842592)
- .setScale(5, RoundingMode.HALF_UP)
- .doubleValue(),
- false));
- }
-
- @Test
- public void testDate() throws Exception {
- SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- log.info("TT:{}", format.format(new Date(100L)));
- log.info("TT:{}", new Date().getTime());
- }
-
- @Test
- public void testDateAll() throws Exception {
- SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- SimpleDateFormat format2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
-
- long dateTime = 0L;
- while (true) {
- Date date = new Date(dateTime);
- double excelDate = DateUtil.getExcelDate(date);
- // odd assertion comment at 2025-03
- // Assertions.assertEquals("测试基本转换错误" + dateTime, format.format(date),
- // format.format(DateUtil.getJavaDate(excelDate, false)));
- // Assertions.assertEquals("测试精度5转换错误" + dateTime, format.format(date),
- // format.format(DateUtil.getJavaDate(BigDecimal.valueOf(excelDate)
- // .setScale(10, RoundingMode.HALF_UP).doubleValue(), false)));
- log.info(
- "date:{}",
- format2.format(DateUtil.getJavaDate(BigDecimal.valueOf(excelDate)
- .setScale(10, RoundingMode.HALF_UP)
- .doubleValue())));
- dateTime += 100000000000L;
- // 30天输出
- if (dateTime % (24 * 60 * 60 * 1000) == 0) {
- log.info("{}成功", format.format(date));
- }
- if (dateTime > 1673957544750L) {
- log.info("结束啦");
- break;
- }
- }
- log.info("结束啦");
- }
-
- @Test
- public void numberforamt3() throws Exception {
- SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
-
- List> list = FastExcel.read("src/test/resources/temp/number_format.xlsx")
- .useDefaultListener(false)
- .sheet(0)
- .headRowNumber(0)
- .doReadSync();
- log.info("数据:{}", list.size());
- for (Map readCellDataMap : list) {
- ReadCellData data = readCellDataMap.get(0);
- log.info(
- "data:{}",
- format.format(DateUtil.getJavaDate(
- data.getNumberValue()
- .setScale(10, RoundingMode.HALF_UP)
- .doubleValue(),
- false)));
- }
- //
- // log.info("data:{}", format.format(DateUtil.getJavaDate(44727.999988425923, false)));
- // log.info("data:{}", format.format(DateUtil.getJavaDate(44729.999988368058, false)));
-
- }
-
- @Test
- public void numberforamt4() throws Exception {
- String fileName = TestFileUtil.getPath() + "simpleWrite" + System.currentTimeMillis() + ".xlsx";
- // 这里 需要指定写用哪个class去写,然后写到第一个sheet,名字为模板 然后文件流会自动关闭
- // 如果这里想使用03 则 传入excelType参数即可
- FastExcel.write(fileName, DemoData.class).sheet("模板").doWrite(() -> {
- // 分页查询数据
- return data2();
- });
- }
-
- @Test
- public void numberforamt77() throws Exception {
- String fileName = TestFileUtil.getPath() + "simpleWrite" + System.currentTimeMillis() + ".xlsx";
- // 这里 需要指定写用哪个class去写,然后写到第一个sheet,名字为模板 然后文件流会自动关闭
- // 如果这里想使用03 则 传入excelType参数即可
- FastExcel.write(fileName, DemoData3.class).sheet("模板").doWrite(() -> {
- List list = new ArrayList<>();
- DemoData3 demoData3 = new DemoData3();
- demoData3.setLocalDateTime(LocalDateTime.of(2023, 1, 1, 0, 0, 0, 400000000));
- list.add(demoData3);
- demoData3 = new DemoData3();
- demoData3.setLocalDateTime(LocalDateTime.of(2023, 1, 1, 0, 0, 0, 499000000));
- list.add(demoData3);
- demoData3 = new DemoData3();
- demoData3.setLocalDateTime(LocalDateTime.of(2023, 1, 1, 0, 0, 0, 500000000));
- list.add(demoData3);
- demoData3 = new DemoData3();
- demoData3.setLocalDateTime(LocalDateTime.of(2023, 1, 1, 0, 0, 0, 501000000));
- list.add(demoData3);
- demoData3 = new DemoData3();
- demoData3.setLocalDateTime(LocalDateTime.of(2023, 1, 1, 0, 0, 0, 995000000));
- list.add(demoData3);
- return list;
- });
- }
-
- @Test
- public void numberforamt99() throws Exception {
- LocalDateTime localDateTime = LocalDateTime.of(2023, 1, 1, 0, 0, 0, 995000000);
- log.info("date:{}", localDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS")));
- }
-
- @Test
- public void numberforamt5() throws Exception {
- String fileName = TestFileUtil.getPath() + "simpleWrite" + System.currentTimeMillis() + ".xlsx";
- // 这里 需要指定写用哪个class去写,然后写到第一个sheet,名字为模板 然后文件流会自动关闭
- // 如果这里想使用03 则 传入excelType参数即可
- FastExcel.write(fileName, DemoData.class).sheet("模板").doWrite(() -> {
- // 分页查询数据
- return data3();
- });
- }
-
- @Test
- public void numberforamt6() throws Exception {
- DecimalFormat decimalFormat = new DecimalFormat("#.#");
- BigDecimal bigDecimal = new BigDecimal(3101011021236149800L);
- log.info("b:{}", bigDecimal);
- log.info("b:{}", bigDecimal.setScale(-4, RoundingMode.HALF_UP));
- log.info("b:{}", decimalFormat.format(bigDecimal.setScale(-4, RoundingMode.HALF_UP)));
- }
-
- @Test
- public void numberforamt7() throws Exception {
- DecimalFormat decimalFormat = new DecimalFormat("#.#");
- BigDecimal bigDecimal = new BigDecimal(3.1010110212361498E+18).round(new MathContext(15, RoundingMode.HALF_UP));
- // bigDecimal.
-
- // bigDecimal
- log.info("b:{}", bigDecimal);
- log.info("b:{}", bigDecimal.setScale(-4, RoundingMode.HALF_UP));
- log.info("b:{}", decimalFormat.format(bigDecimal.setScale(-4, RoundingMode.HALF_UP)));
- log.info("b:{}", decimalFormat.format(bigDecimal));
- }
-
- private List data3() {
- SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
-
- List list = new ArrayList<>();
- for (int i = 0; i < 10; i++) {
- DemoData2 data = new DemoData2();
- data.setString("字符串" + i);
- data.setDoubleData(0.56);
- data.setBigDecimal(BigDecimal.valueOf(3101011021236149800L));
- list.add(data);
- }
- return list;
- }
-
- private List data() {
- SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
-
- List list = new ArrayList();
- for (int i = 0; i < 10; i++) {
- DemoData data = new DemoData();
- data.setString("字符串" + i);
- try {
- data.setDate(format.parse("2032-01-18 09:00:01.995"));
- } catch (ParseException e) {
- throw new RuntimeException(e);
- }
- data.setDoubleData(0.56);
- list.add(data);
- }
- return list;
- }
-
- private List data2() {
- SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.");
-
- List list = new ArrayList();
- for (int i = 0; i < 10; i++) {
- DemoData data = new DemoData();
- data.setString("字符串" + i);
- try {
- data.setDate(format.parse("2032-01-18 09:00:00."));
- } catch (ParseException e) {
- throw new RuntimeException(e);
- }
- data.setDoubleData(0.56);
- list.add(data);
- }
- return list;
- }
-}
diff --git a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/temp/LockData.java b/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/temp/LockData.java
deleted file mode 100644
index 09cd1588d..000000000
--- a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/temp/LockData.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * 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.temp;
-
-import lombok.EqualsAndHashCode;
-import lombok.Getter;
-import lombok.Setter;
-import org.apache.fesod.sheet.annotation.format.NumberFormat;
-
-/**
- * 基础数据类.这里的排序和excel里面的排序一致
- *
- *
- **/
-@Getter
-@Setter
-@EqualsAndHashCode
-public class LockData {
- @NumberFormat("#.##%")
- private Double string0;
-
- private String string1;
- private String string2;
- private String string3;
- private String string4;
- private String string5;
- private String string6;
- private String string7;
- private String string8;
-}
diff --git a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/temp/LockDataListener.java b/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/temp/LockDataListener.java
deleted file mode 100644
index 4fb9d688f..000000000
--- a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/temp/LockDataListener.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * 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.temp;
-
-import com.alibaba.fastjson2.JSON;
-import java.util.ArrayList;
-import java.util.List;
-import lombok.extern.slf4j.Slf4j;
-import org.apache.fesod.sheet.context.AnalysisContext;
-import org.apache.fesod.sheet.event.AnalysisEventListener;
-
-/**
- * 模板的读取类
- *
- *
- */
-@Slf4j
-public class LockDataListener extends AnalysisEventListener {
- /**
- * 每隔5条存储数据库,实际使用中可以100条,然后清理list ,方便内存回收
- */
- private static final int BATCH_COUNT = 5;
-
- List list = new ArrayList();
-
- @Override
- public void invoke(LockData data, AnalysisContext context) {
- log.info("解析到一条数据:{}", JSON.toJSONString(data));
- list.add(data);
- if (list.size() >= BATCH_COUNT) {
- saveData();
- list.clear();
- }
- }
-
- @Override
- public void doAfterAllAnalysed(AnalysisContext context) {
- saveData();
- log.info("所有数据解析完成!");
- }
-
- /**
- * 加上存储数据库
- */
- private void saveData() {
- log.info("{}条数据,开始存储数据库!", list.size());
- log.info("存储数据库成功!");
- }
-}
diff --git a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/temp/LockTest.java b/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/temp/LockTest.java
deleted file mode 100644
index 4b451e40f..000000000
--- a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/temp/LockTest.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * 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.temp;
-
-import com.alibaba.fastjson2.JSON;
-import java.io.FileInputStream;
-import java.util.List;
-import java.util.Map;
-import lombok.extern.slf4j.Slf4j;
-import org.apache.fesod.sheet.FastExcel;
-import org.junit.jupiter.api.Test;
-
-/**
- * 临时测试
- *
- *
- **/
-@Slf4j
-public class LockTest {
-
- @Test
- public void test() throws Exception {
- List list = FastExcel.read(new FileInputStream("src/test/resources/simple/simple07.xlsx"))
- .useDefaultListener(false)
- .doReadAllSync();
- for (Object data : list) {
- log.info("返回数据:{}", JSON.toJSONString(data));
- }
- }
-
- @Test
- public void test2() throws Exception {
- List list = FastExcel.read(new FileInputStream("src/test/resources/simple/simple07.xlsx"))
- .sheet()
- .headRowNumber(0)
- .doReadSync();
- for (Object data : list) {
- log.info("返回数据:{}", ((Map) data).size());
- log.info("返回数据:{}", JSON.toJSONString(data));
- }
- }
-}
diff --git a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/temp/StyleData.java b/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/temp/StyleData.java
deleted file mode 100644
index a3a38d2df..000000000
--- a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/temp/StyleData.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * 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.temp;
-
-import java.util.List;
-import lombok.EqualsAndHashCode;
-import lombok.Getter;
-import lombok.Setter;
-
-/**
- *
- **/
-@Getter
-@Setter
-@EqualsAndHashCode
-public class StyleData {
- private byte[] byteValue;
- private Byte[] byteValue2;
- private byte byteValue1;
- private Byte byteValue4;
- private byte byteValue3;
- private String[] ss;
- private List s1s;
-}
diff --git a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/temp/StyleTest.java b/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/temp/StyleTest.java
deleted file mode 100644
index d2f58321f..000000000
--- a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/temp/StyleTest.java
+++ /dev/null
@@ -1,131 +0,0 @@
-/*
- * 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.temp;
-
-import java.io.InputStream;
-import java.lang.reflect.Field;
-import java.nio.file.Files;
-import java.nio.file.Paths;
-import java.util.Date;
-import lombok.extern.slf4j.Slf4j;
-import org.apache.poi.ss.usermodel.BuiltinFormats;
-import org.apache.poi.ss.usermodel.Cell;
-import org.apache.poi.ss.usermodel.DateUtil;
-import org.apache.poi.ss.usermodel.ExcelStyleDateFormatter;
-import org.apache.poi.ss.usermodel.Row;
-import org.apache.poi.ss.usermodel.Sheet;
-import org.apache.poi.ss.usermodel.Workbook;
-import org.apache.poi.ss.usermodel.WorkbookFactory;
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.Test;
-
-/**
- * 临时测试
- *
- *
- **/
-@Slf4j
-public class StyleTest {
-
- @Test
- public void poi07Test() throws Exception {
- InputStream is = Files.newInputStream(Paths.get("src/test/resources/style/styleTest.xlsx"));
- Workbook workbook = WorkbookFactory.create(is); // 这种方式 Excel 2003/2007/2010 都是可以处理的
- Sheet sheet = workbook.getSheetAt(0);
- Row hssfRow = sheet.getRow(0);
- Assertions.assertEquals(1.0, hssfRow.getCell(0).getNumericCellValue());
- Assertions.assertEquals(1.0, hssfRow.getCell(1).getNumericCellValue());
- Assertions.assertEquals(1.0, hssfRow.getCell(2).getNumericCellValue());
- Assertions.assertEquals(1.0, hssfRow.getCell(3).getNumericCellValue());
- Assertions.assertEquals(14, hssfRow.getCell(0).getCellStyle().getDataFormat());
- Assertions.assertEquals(0, hssfRow.getCell(1).getCellStyle().getDataFormat());
- Assertions.assertEquals(10, hssfRow.getCell(2).getCellStyle().getDataFormat());
- Assertions.assertEquals(49, hssfRow.getCell(3).getCellStyle().getDataFormat());
- Assertions.assertEquals("m/d/yy", hssfRow.getCell(0).getCellStyle().getDataFormatString());
- Assertions.assertEquals("General", hssfRow.getCell(1).getCellStyle().getDataFormatString());
- Assertions.assertEquals("0.00%", hssfRow.getCell(2).getCellStyle().getDataFormatString());
- Assertions.assertEquals("@", hssfRow.getCell(3).getCellStyle().getDataFormatString());
- Assertions.assertTrue(isDate(hssfRow.getCell(0)));
- Assertions.assertFalse(isDate(hssfRow.getCell(1)));
- Assertions.assertFalse(isDate(hssfRow.getCell(2)));
- Assertions.assertFalse(isDate(hssfRow.getCell(3)));
- }
-
- @Test
- public void poi03Test() throws Exception {
- InputStream is = Files.newInputStream(Paths.get("src/test/resources/style/styleTest.xls"));
- Workbook workbook = WorkbookFactory.create(is); // 这种方式 Excel 2003/2007/2010 都是可以处理的
- Sheet sheet = workbook.getSheetAt(0);
- Row hssfRow = sheet.getRow(0);
- Assertions.assertEquals(1.0, hssfRow.getCell(0).getNumericCellValue());
- Assertions.assertEquals(1.0, hssfRow.getCell(1).getNumericCellValue());
- Assertions.assertEquals(1.0, hssfRow.getCell(2).getNumericCellValue());
- Assertions.assertEquals(1.0, hssfRow.getCell(3).getNumericCellValue());
- Assertions.assertEquals(14, hssfRow.getCell(0).getCellStyle().getDataFormat());
- Assertions.assertEquals(0, hssfRow.getCell(1).getCellStyle().getDataFormat());
- Assertions.assertEquals(10, hssfRow.getCell(2).getCellStyle().getDataFormat());
- Assertions.assertEquals(49, hssfRow.getCell(3).getCellStyle().getDataFormat());
- Assertions.assertEquals("m/d/yy", hssfRow.getCell(0).getCellStyle().getDataFormatString());
- Assertions.assertEquals("General", hssfRow.getCell(1).getCellStyle().getDataFormatString());
- Assertions.assertEquals("0.00%", hssfRow.getCell(2).getCellStyle().getDataFormatString());
- Assertions.assertEquals("@", hssfRow.getCell(3).getCellStyle().getDataFormatString());
- Assertions.assertTrue(isDate(hssfRow.getCell(0)));
- Assertions.assertFalse(isDate(hssfRow.getCell(1)));
- Assertions.assertFalse(isDate(hssfRow.getCell(2)));
- Assertions.assertFalse(isDate(hssfRow.getCell(3)));
- }
-
- @Test
- public void testFormatter() throws Exception {
- ExcelStyleDateFormatter ff = new ExcelStyleDateFormatter("yyyy年m月d日");
-
- System.out.println(ff.format(new Date()));
- }
-
- @Test
- public void testFormatter2() throws Exception {
- StyleData styleData = new StyleData();
- Field field = styleData.getClass().getDeclaredField("byteValue");
- log.info("field:{}", field.getType().getName());
- field = styleData.getClass().getDeclaredField("byteValue2");
- log.info("field:{}", field.getType().getName());
- field = styleData.getClass().getDeclaredField("byteValue4");
- log.info("field:{}", field.getType());
- field = styleData.getClass().getDeclaredField("byteValue3");
- log.info("field:{}", field.getType());
- }
-
- @Test
- public void testFormatter3() throws Exception {
- log.info("field:{}", Byte.class == Byte.class);
- }
-
- private boolean isDate(Cell cell) {
- return DateUtil.isADateFormat(
- cell.getCellStyle().getDataFormat(), cell.getCellStyle().getDataFormatString());
- }
-
- @Test
- public void testBuiltinFormats() throws Exception {
- System.out.println(BuiltinFormats.getBuiltinFormat(48));
- System.out.println(BuiltinFormats.getBuiltinFormat(57));
- System.out.println(BuiltinFormats.getBuiltinFormat(28));
- }
-}
diff --git a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/temp/TempFillData.java b/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/temp/TempFillData.java
deleted file mode 100644
index 4d230a447..000000000
--- a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/temp/TempFillData.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * 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.temp;
-
-import lombok.EqualsAndHashCode;
-import lombok.Getter;
-import lombok.Setter;
-import org.apache.fesod.sheet.annotation.write.style.ContentRowHeight;
-
-/**
- *
- */
-@Getter
-@Setter
-@EqualsAndHashCode
-@ContentRowHeight(30)
-public class TempFillData {
- private String name;
- private double number;
-}
diff --git a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/temp/WriteLargeTest.java b/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/temp/WriteLargeTest.java
deleted file mode 100644
index 33f6f38a7..000000000
--- a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/temp/WriteLargeTest.java
+++ /dev/null
@@ -1,208 +0,0 @@
-/*
- * 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.temp;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import lombok.extern.slf4j.Slf4j;
-import org.apache.fesod.sheet.ExcelWriter;
-import org.apache.fesod.sheet.FastExcel;
-import org.apache.fesod.sheet.read.listener.PageReadListener;
-import org.apache.fesod.sheet.temp.large.LargeData;
-import org.apache.fesod.sheet.util.TestFileUtil;
-import org.apache.fesod.sheet.write.metadata.WriteSheet;
-import org.apache.fesod.sheet.write.metadata.style.WriteCellStyle;
-import org.apache.fesod.sheet.write.metadata.style.WriteFont;
-import org.apache.fesod.sheet.write.style.HorizontalCellStyleStrategy;
-import org.apache.poi.hssf.eventusermodel.HSSFEventFactory;
-import org.apache.poi.hssf.eventusermodel.HSSFListener;
-import org.apache.poi.hssf.eventusermodel.HSSFRequest;
-import org.apache.poi.hssf.record.BOFRecord;
-import org.apache.poi.hssf.record.BoundSheetRecord;
-import org.apache.poi.hssf.record.Record;
-import org.apache.poi.hssf.record.SSTRecord;
-import org.apache.poi.hssf.usermodel.HSSFCell;
-import org.apache.poi.hssf.usermodel.HSSFRow;
-import org.apache.poi.hssf.usermodel.HSSFSheet;
-import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.apache.poi.poifs.filesystem.POIFSFileSystem;
-import org.apache.poi.ss.usermodel.FillPatternType;
-import org.apache.poi.ss.usermodel.IndexedColors;
-import org.junit.jupiter.api.Test;
-
-/**
- *
- */
-@Slf4j
-public class WriteLargeTest {
-
- @Test
- public void test() throws Exception {
- // 方法2 如果写到不同的sheet 同一个对象
- String fileName = TestFileUtil.getPath() + "large" + System.currentTimeMillis() + ".xlsx";
- // 头的策略
- WriteCellStyle headWriteCellStyle = new WriteCellStyle();
- // 背景设置为红色
- headWriteCellStyle.setFillForegroundColor(IndexedColors.RED.getIndex());
- WriteFont headWriteFont = new WriteFont();
- headWriteFont.setFontHeightInPoints((short) 20);
- headWriteCellStyle.setWriteFont(headWriteFont);
- // 内容的策略
- WriteCellStyle contentWriteCellStyle = new WriteCellStyle();
- // 这里需要指定 FillPatternType 为FillPatternType.SOLID_FOREGROUND 不然无法显示背景颜色.头默认了 FillPatternType所以可以不指定
- contentWriteCellStyle.setFillPatternType(FillPatternType.SOLID_FOREGROUND);
- // 背景绿色
- contentWriteCellStyle.setFillForegroundColor(IndexedColors.GREEN.getIndex());
- WriteFont contentWriteFont = new WriteFont();
- // 字体大小
- contentWriteFont.setFontHeightInPoints((short) 20);
- contentWriteCellStyle.setWriteFont(contentWriteFont);
- // 这个策略是 头是头的样式 内容是内容的样式 其他的策略可以自己实现
- HorizontalCellStyleStrategy horizontalCellStyleStrategy =
- new HorizontalCellStyleStrategy(headWriteCellStyle, contentWriteCellStyle);
-
- ExcelWriter excelWriter = FastExcel.write(fileName, LargeData.class)
- .registerWriteHandler(horizontalCellStyleStrategy)
- .build();
- WriteSheet writeSheet = FastExcel.writerSheet().build();
- for (int j = 0; j < 100; j++) {
- excelWriter.write(data(), writeSheet);
- log.info("{} fill success.", j);
- }
- excelWriter.finish();
- }
-
- @Test
- public void read() throws Exception {
- log.info("start");
- String fileName = "src/test/resources/poi/last_row_number_xssf_date_test.xls";
- // 这里 需要指定读用哪个class去读,然后读取第一个sheet 文件流会自动关闭
- // 这里默认每次会读取100条数据 然后返回过来 直接调用使用数据就行
- // 具体需要返回多少行可以在`PageReadListener`的构造函数设置
- FastExcel.read(fileName, new PageReadListener>>(dataList -> {
- log.info("SIZEL:{}", dataList.size());
- }))
- .sheet()
- .doRead();
-
- log.info("test");
- }
-
- @Test
- public void read2() throws Exception {
- // 使用输入的文件创建一个新的文件输入流
- // FileInputStream fin = new FileInputStream("/Users/zhuangjiaju/Downloads/1e9e0578a9634abbbbd9b67f338f142a
- // .xls");
- // 创建一个新的org.apache.poi.poifs.filesystem.Filesystem
- POIFSFileSystem poifs =
- new POIFSFileSystem(new File("src/test/resources/poi/last_row_number_xssf_date_test.xls"));
- // 在InputStream中获取Workbook流
- InputStream din = poifs.createDocumentInputStream("Workbook");
- // 构造出HSSFRequest对象
- HSSFRequest req = new HSSFRequest();
- // 注册全部的监听器
- req.addListenerForAllRecords(new EventExample());
- // 创建事件工厂
- HSSFEventFactory factory = new HSSFEventFactory();
- // 根据文档输入流处理我们监听的事件
- factory.processEvents(req, din);
- // 关闭文件输入流
- // fin.close();
- // 关闭文档输入流
- din.close();
- System.out.println("读取结束");
- }
-
- @Test
- public void read3() throws Exception {
- HSSFWorkbook hwb =
- new HSSFWorkbook(new FileInputStream("src/test/resources/poi/last_row_number_xssf_date_test.xls"));
- HSSFSheet sheet = hwb.getSheetAt(0);
- HSSFRow row = null;
- HSSFCell cell = null;
- for (int i = sheet.getFirstRowNum(); i <= sheet.getPhysicalNumberOfRows(); i++) {
- row = sheet.getRow(i);
- if (row != null) {
- log.info("r:{}", row.getRowNum());
- }
- }
-
- log.info("end");
- }
-
- public static class EventExample implements HSSFListener {
- private SSTRecord sstrec;
-
- /**
- * 此方法监听传入记录并根据需要处理它们
- *
- * @param record 读取时找到的记录
- */
- public void processRecord(Record record) {
- switch (record.getSid()) {
- // BOFRecord可以表示工作表或工作簿的开头
- case BOFRecord.sid:
- BOFRecord bof = (BOFRecord) record;
- if (bof.getType() == BOFRecord.TYPE_WORKBOOK) {
- System.out.println("监听到工作表");
- } else if (bof.getType() == BOFRecord.TYPE_WORKSHEET) {
- System.out.println("监听到工作簿");
- }
- break;
- case BoundSheetRecord.sid:
- BoundSheetRecord bsr = (BoundSheetRecord) record;
- System.out.println("工作簿名称: " + bsr.getSheetname());
- break;
- }
- }
- }
-
- @Test
- public void test2() throws Exception {
- // 方法2 如果写到不同的sheet 同一个对象
- String fileName = TestFileUtil.getPath() + "large" + System.currentTimeMillis() + ".xlsx";
-
- ExcelWriter excelWriter = FastExcel.write(fileName, LargeData.class).build();
- WriteSheet writeSheet = FastExcel.writerSheet().build();
- for (int j = 0; j < 100; j++) {
- excelWriter.write(data(), writeSheet);
- log.info("{} fill success.", j);
- }
- excelWriter.finish();
- }
-
- private List> data() {
- List> list = new ArrayList<>();
-
- for (int j = 0; j < 10000; j++) {
- List oneRow = new ArrayList<>();
- for (int i = 0; i < 150; i++) {
- oneRow.add("这是测试字段" + i);
- }
- list.add(oneRow);
- }
-
- return list;
- }
-}
diff --git a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/temp/WriteV33Test.java b/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/temp/WriteV33Test.java
deleted file mode 100644
index e5f38f141..000000000
--- a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/temp/WriteV33Test.java
+++ /dev/null
@@ -1,159 +0,0 @@
-/*
- * 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.temp;
-
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import org.apache.fesod.common.util.BooleanUtils;
-import org.apache.fesod.sheet.FastExcel;
-import org.apache.fesod.sheet.demo.write.DemoData;
-import org.apache.fesod.sheet.util.TestFileUtil;
-import org.apache.fesod.sheet.write.handler.CellWriteHandler;
-import org.apache.fesod.sheet.write.handler.context.CellWriteHandlerContext;
-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.Workbook;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.io.TempDir;
-
-/**
- * 临时测试
- *
- *
- **/
-public class WriteV33Test {
-
- @Test
- public void handlerStyleWrite() {
- // 方法1 使用已有的策略 推荐
- // HorizontalCellStyleStrategy 每一行的样式都一样 或者隔行一样
- // AbstractVerticalCellStyleStrategy 每一列的样式都一样 需要自己回调每一页
- String fileName = TestFileUtil.getPath() + "handlerStyleWrite" + System.currentTimeMillis() + ".xlsx";
- //// 头的策略
- // WriteCellStyle headWriteCellStyle = new WriteCellStyle();
- //// 背景设置为红色
- // headWriteCellStyle.setFillForegroundColor(IndexedColors.RED.getIndex());
- // WriteFont headWriteFont = new WriteFont();
- // headWriteFont.setFontHeightInPoints((short)20);
- // headWriteCellStyle.setWriteFont(headWriteFont);
- //// 内容的策略
- // WriteCellStyle contentWriteCellStyle = new WriteCellStyle();
- //// 这里需要指定 FillPatternType 为FillPatternType.SOLID_FOREGROUND 不然无法显示背景颜色.头默认了 FillPatternType所以可以不指定
- // contentWriteCellStyle.setFillPatternType(FillPatternType.SOLID_FOREGROUND);
- //// 背景绿色
- // contentWriteCellStyle.setFillForegroundColor(IndexedColors.GREEN.getIndex());
- // WriteFont contentWriteFont = new WriteFont();
- //// 字体大小
- // contentWriteFont.setFontHeightInPoints((short)20);
- // contentWriteCellStyle.setWriteFont(contentWriteFont);
- //// 这个策略是 头是头的样式 内容是内容的样式 其他的策略可以自己实现
- // HorizontalCellStyleStrategy horizontalCellStyleStrategy =
- // new HorizontalCellStyleStrategy(headWriteCellStyle, contentWriteCellStyle);
- //
- //// 这里 需要指定写用哪个class去写,然后写到第一个sheet,名字为模板 然后文件流会自动关闭
- // FastExcel.write(fileName, DemoData.class)
- // .registerWriteHandler(horizontalCellStyleStrategy)
- // .sheet("模板")
- // .doWrite(data());
- //
- // 方法2: 使用FastExcel的方式完全自己写 不太推荐 尽量使用已有策略
- // fileName = TestFileUtil.getPath() + "handlerStyleWrite" + System.currentTimeMillis() + ".xlsx";
- // FastExcel.write(fileName, DemoData.class)
- // .registerWriteHandler(new CellWriteHandler() {
- // @Override
- // public void afterCellDispose(CellWriteHandlerContext context) {
- // // 当前事件会在 数据设置到poi的cell里面才会回调
- // // 判断不是头的情况 如果是fill 的情况 这里会==null 所以用not true
- // if (BooleanUtils.isNotTrue(context.getHead())) {
- // // 第一个单元格
- // // 只要不是头 一定会有数据 当然fill的情况 可能要context.getCellDataList() ,这个需要看模板,因为一个单元格会有多个 WriteCellData
- // WriteCellData> cellData = context.getFirstCellData();
- // // 这里需要去cellData 获取样式
- // // 很重要的一个原因是 WriteCellStyle 和 dataFormatData绑定的 简单的说 比如你加了 DateTimeFormat
- // // ,已经将writeCellStyle里面的dataFormatData 改了 如果你自己new了一个WriteCellStyle,可能注解的样式就失效了
- // // 然后 getOrCreateStyle 用于返回一个样式,如果为空,则创建一个后返回
- // WriteCellStyle writeCellStyle = cellData.getOrCreateStyle();
- // writeCellStyle.setFillForegroundColor(IndexedColors.RED.getIndex());
- // // 这里需要指定 FillPatternType 为FillPatternType.SOLID_FOREGROUND
- // writeCellStyle.setFillPatternType(FillPatternType.SOLID_FOREGROUND);
- //
- // // 这样样式就设置好了 后面有个FillStyleCellWriteHandler 默认会将 WriteCellStyle 设置到 cell里面去 所以可以不用管了
- // }
- // }
- // }).sheet("模板")
- // .doWrite(data());
-
- // 方法3: 使用poi的样式完全自己写 不推荐
- // 坑1:style里面有dataformat 用来格式化数据的 所以自己设置可能导致格式化注解不生效
- // 坑2:不要一直去创建style 记得缓存起来 最多创建6W个就挂了
- fileName = TestFileUtil.getPath() + "handlerStyleWrite" + System.currentTimeMillis() + ".xlsx";
- FastExcel.write(fileName, DemoData.class)
- .registerWriteHandler(new CellWriteHandler() {
- @Override
- public void afterCellDispose(CellWriteHandlerContext context) {
- // 当前事件会在 数据设置到poi的cell里面才会回调
- // 判断不是头的情况 如果是fill 的情况 这里会==null 所以用not true
- if (BooleanUtils.isNotTrue(context.getHead())) {
- Cell cell = context.getCell();
- // 拿到poi的workbook
- Workbook workbook = context.getWriteWorkbookHolder().getWorkbook();
- // 这里千万记住 想办法能复用的地方把他缓存起来 一个表格最多创建6W个样式
- // 不同单元格尽量传同一个 cellStyle
- CellStyle cellStyle = workbook.createCellStyle();
- cellStyle.setFillForegroundColor(IndexedColors.RED.getIndex());
- // 这里需要指定 FillPatternType 为FillPatternType.SOLID_FOREGROUND
- cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
- cell.setCellStyle(cellStyle);
-
- // 由于这里没有指定datafrmat 所以格式化出来的数据需要
-
- // 这里要把 WriteCellData的样式清空, 不然后面还有一个拦截器 FillStyleCellWriteHandler 默认会将 WriteCellStyle 设置到
- // cell里面去 会导致自己设置的不一样
- context.getFirstCellData().setWriteCellStyle(null);
- }
- }
- })
- .sheet("模板")
- .doWrite(data());
- }
-
- private List data() {
- List list = new ArrayList<>();
- for (int i = 0; i < 10; i++) {
- DemoData data = new DemoData();
- data.setString("字符串" + i);
- data.setDate(new Date());
- data.setDoubleData(0.56);
- list.add(data);
- }
- return list;
- }
-
- @Test
- public void test4(@TempDir Path tempDir) throws Exception {
- Path path = Files.createTempFile(tempDir, System.currentTimeMillis() + "", ".jpg");
- System.out.println(path);
- }
-}
diff --git a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/temp/WriteV34Test.java b/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/temp/WriteV34Test.java
deleted file mode 100644
index c812f6bff..000000000
--- a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/temp/WriteV34Test.java
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * 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.temp;
-
-import java.util.ArrayList;
-import java.util.List;
-import org.apache.fesod.sheet.FastExcel;
-import org.apache.fesod.sheet.demo.read.DemoData;
-import org.apache.fesod.sheet.util.TestFileUtil;
-import org.apache.fesod.sheet.write.metadata.style.WriteCellStyle;
-import org.apache.fesod.sheet.write.metadata.style.WriteFont;
-import org.apache.fesod.sheet.write.style.HorizontalCellStyleStrategy;
-import org.apache.poi.ss.usermodel.FillPatternType;
-import org.apache.poi.ss.usermodel.IndexedColors;
-import org.junit.jupiter.api.Test;
-
-/**
- * 临时测试
- *
- *
- **/
-public class WriteV34Test {
-
- @Test
- public void test() throws Exception {
- String fileName = TestFileUtil.getPath() + "handlerStyleWrite" + System.currentTimeMillis() + ".xlsx";
- // 头的策略
- WriteCellStyle headWriteCellStyle = new WriteCellStyle();
- // 背景设置为红色
- headWriteCellStyle.setFillForegroundColor(IndexedColors.RED.getIndex());
- WriteFont headWriteFont = new WriteFont();
- headWriteFont.setFontHeightInPoints((short) 20);
- headWriteCellStyle.setWriteFont(headWriteFont);
- // 内容的策略
- WriteCellStyle contentWriteCellStyle = new WriteCellStyle();
- // 这里需要指定 FillPatternType 为FillPatternType.SOLID_FOREGROUND 不然无法显示背景颜色.头默认了 FillPatternType所以可以不指定
- contentWriteCellStyle.setFillPatternType(FillPatternType.SOLID_FOREGROUND);
- // 背景绿色
- contentWriteCellStyle.setFillForegroundColor(IndexedColors.GREEN.getIndex());
- WriteFont contentWriteFont = new WriteFont();
- // 字体大小
- contentWriteFont.setFontHeightInPoints((short) 20);
- contentWriteCellStyle.setWriteFont(contentWriteFont);
- // 这个策略是 头是头的样式 内容是内容的样式 其他的策略可以自己实现
- HorizontalCellStyleStrategy horizontalCellStyleStrategy =
- new HorizontalCellStyleStrategy(headWriteCellStyle, contentWriteCellStyle);
-
- // 这里 需要指定写用哪个class去写,然后写到第一个sheet,名字为模板 然后文件流会自动关闭
- FastExcel.write(fileName, DemoData.class)
- .head(head())
- .registerWriteHandler(horizontalCellStyleStrategy)
- .sheet("模板")
- .doWrite(data(1));
- }
-
- private List> head() {
- List> list = new ArrayList>();
- List head0 = new ArrayList();
- head0.add("字符串" + System.currentTimeMillis());
- head0.add("再找找");
- List head1 = new ArrayList();
- head1.add("数字" + System.currentTimeMillis());
- List head2 = new ArrayList();
- head2.add("日期" + System.currentTimeMillis());
- list.add(head0);
- list.add(head1);
- list.add(head2);
- return list;
- }
-
- private List data(int no) {
- List list = new ArrayList();
- for (int i = 0; i < 10; i++) {
- DemoData data = new DemoData();
- data.setString("字符串" + no + "---" + i);
- list.add(data);
- }
- return list;
- }
-}
diff --git a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/temp/Xls03Test.java b/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/temp/Xls03Test.java
deleted file mode 100644
index 25a8fc055..000000000
--- a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/temp/Xls03Test.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * 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.temp;
-
-import com.alibaba.fastjson2.JSON;
-import java.nio.file.Path;
-import java.util.List;
-import lombok.extern.slf4j.Slf4j;
-import org.apache.fesod.shaded.cglib.beans.BeanMap;
-import org.apache.fesod.shaded.cglib.core.DebuggingClassWriter;
-import org.apache.fesod.sheet.FastExcel;
-import org.apache.fesod.sheet.util.BeanMapUtils;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.io.TempDir;
-
-/**
- * 临时测试
- *
- *
- **/
-@Slf4j
-public class Xls03Test {
-
- @TempDir
- Path tempDir;
-
- @Test
- public void test() {
- List list = FastExcel.read("src/test/resources/compatibility/t07.xlsx")
- .sheet()
- .doReadSync();
- for (Object data : list) {
- log.info("返回数据:{}", JSON.toJSONString(data));
- }
- }
-
- @Test
- public void test2() {
- System.getProperties().put("sun.misc.ProxyGenerator.saveGeneratedFiles", "true");
- System.setProperty(DebuggingClassWriter.DEBUG_LOCATION_PROPERTY, tempDir.toString());
-
- CamlData camlData = new CamlData();
- // camlData.setTest("test2");
- // camlData.setAEst("test3");
- // camlData.setTEST("test4");
-
- BeanMap beanMap = BeanMapUtils.create(camlData);
-
- log.info("test:{}", beanMap.get("test"));
- log.info("test:{}", beanMap.get("Test"));
- log.info("test:{}", beanMap.get("TEst"));
- log.info("test:{}", beanMap.get("TEST"));
- }
-}
diff --git a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/temp/bug/DataType.java b/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/temp/bug/DataType.java
deleted file mode 100644
index bdb95c926..000000000
--- a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/temp/bug/DataType.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * 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.temp.bug;
-
-import lombok.EqualsAndHashCode;
-import lombok.Getter;
-import lombok.Setter;
-import org.apache.fesod.sheet.annotation.ExcelProperty;
-
-/**
- */
-@Getter
-@Setter
-@EqualsAndHashCode
-public class DataType {
- /**
- * 任务id
- */
- @ExcelProperty("任务ID")
- private Integer id;
-
- @ExcelProperty("多余字段1")
- private String firstSurplus;
-
- @ExcelProperty("多余字段2")
- private String secSurplus;
-
- @ExcelProperty("多余字段3")
- private String thirdSurplus;
-
- @ExcelProperty(value = "备注1")
- private String firstRemark;
-
- @ExcelProperty(value = "备注2")
- private String secRemark;
-}
diff --git a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/temp/bug/ExcelCreat.java b/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/temp/bug/ExcelCreat.java
deleted file mode 100644
index d24bc4c41..000000000
--- a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/temp/bug/ExcelCreat.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * 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.temp.bug;
-
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.util.Collections;
-import java.util.List;
-import org.apache.fesod.sheet.ExcelWriter;
-import org.apache.fesod.sheet.FastExcel;
-import org.apache.fesod.sheet.write.metadata.WriteSheet;
-
-/**
- */
-public class ExcelCreat {
-
- public static void main(String[] args) throws FileNotFoundException {
- List data = getData();
- ExcelWriter excelWriter = null;
- excelWriter = FastExcel.write(new FileOutputStream("all.xlsx")).build();
- WriteSheet writeSheet =
- FastExcel.writerSheet(1, "test").head(HeadType.class).build();
- excelWriter.write(data, writeSheet);
- excelWriter.finish();
- }
-
- private static List getData() {
- DataType vo = new DataType();
- vo.setId(738);
- vo.setFirstRemark("1222");
- vo.setSecRemark("22222");
- return Collections.singletonList(vo);
- }
-}
diff --git a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/temp/bug/HeadType.java b/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/temp/bug/HeadType.java
deleted file mode 100644
index 7fee53f1d..000000000
--- a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/temp/bug/HeadType.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * 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.temp.bug;
-
-import lombok.EqualsAndHashCode;
-import lombok.Getter;
-import lombok.Setter;
-import org.apache.fesod.sheet.annotation.ExcelProperty;
-
-/**
- */
-@Getter
-@Setter
-@EqualsAndHashCode
-public class HeadType {
-
- /**
- * 任务id
- */
- @ExcelProperty("任务ID")
- private Integer id;
-
- @ExcelProperty(value = "备注1")
- private String firstRemark;
-
- @ExcelProperty(value = "备注2")
- private String secRemark;
-}
diff --git a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/temp/cache/CacheTest.java b/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/temp/cache/CacheTest.java
deleted file mode 100644
index 91d9e9a7a..000000000
--- a/fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/temp/cache/CacheTest.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * 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.temp.cache;
-
-import com.alibaba.fastjson2.JSON;
-import java.io.File;
-import java.util.HashMap;
-import java.util.UUID;
-import lombok.extern.slf4j.Slf4j;
-import org.apache.fesod.sheet.util.FileUtils;
-import org.ehcache.Cache;
-import org.ehcache.PersistentCacheManager;
-import org.ehcache.config.builders.CacheConfigurationBuilder;
-import org.ehcache.config.builders.CacheManagerBuilder;
-import org.ehcache.config.builders.ResourcePoolsBuilder;
-import org.ehcache.config.units.MemoryUnit;
-import org.junit.jupiter.api.Test;
-
-/**
- *
- **/
-@Slf4j
-public class CacheTest {
-
- @Test
- public void cache() throws Exception {
-
- File readTempFile = FileUtils.createCacheTmpFile();
-
- File cacheFile = new File(readTempFile.getPath(), UUID.randomUUID().toString());
- PersistentCacheManager persistentCacheManager = CacheManagerBuilder.newCacheManagerBuilder()
- .with(CacheManagerBuilder.persistence(cacheFile))
- .withCache(
- "cache",
- CacheConfigurationBuilder.newCacheConfigurationBuilder(
- Integer.class,
- HashMap.class,
- ResourcePoolsBuilder.newResourcePoolsBuilder().disk(10, MemoryUnit.GB)))
- .build(true);
- Cache cache = persistentCacheManager.getCache("cache", Integer.class, HashMap.class);
-
- HashMap