Repository: wangguanquan/eec
Pull request #62 (2019-06-25 10:09:18)

Fix#61


Patch:
diff --git a/src/main/java/org/ttzero/excel/entity/ListSheet.java b/src/main/java/org/ttzero/excel/entity/ListSheet.java
index e4734696..0aebb190 100644
--- a/src/main/java/org/ttzero/excel/entity/ListSheet.java
+++ b/src/main/java/org/ttzero/excel/entity/ListSheet.java
@@ -208,7 +208,8 @@ public class ListSheet<T> extends Sheet {
             }
         }
         if (shouldClose && data != null) {
-            data.clear();
+            // Some Collection not support #remove
+//            data.clear();
             data = null;
         }
         super.close();


Test patch:
diff --git a/src/test/java/org/ttzero/excel/entity/ListMapSheetTest.java b/src/test/java/org/ttzero/excel/entity/ListMapSheetTest.java
index 6174864a..ce036e4c 100644
--- a/src/test/java/org/ttzero/excel/entity/ListMapSheetTest.java
+++ b/src/test/java/org/ttzero/excel/entity/ListMapSheetTest.java
@@ -27,6 +27,8 @@ import java.time.LocalDate;
 import java.time.LocalDateTime;
 import java.time.LocalTime;
 import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
@@ -217,6 +219,31 @@ public class ListMapSheetTest extends WorkbookTest {
             .writeTo(defaultTestPath);
     }
 
+    @Test public void testArray() throws IOException {
+        Map<String, Object> data1 = new HashMap<>();
+        data1.put("id", 1);
+        data1.put("name", "abc");
+
+        Map<String, Object> data2 = new HashMap<>();
+        data2.put("id", 2);
+        data2.put("name", "xyz");
+        new Workbook()
+            .watch(Print::println)
+            .addSheet(new ListMapSheet().setData(Arrays.asList(data1, data2)))
+            .writeTo(defaultTestPath);
+    }
+
+    @Test public void testSingleList() throws IOException {
+        Map<String, Object> data = new HashMap<>();
+        data.put("id", 1);
+        data.put("name", "abc");
+
+        new Workbook()
+            .watch(Print::println)
+            .addSheet(new ListMapSheet().setData(Collections.singletonList(data)))
+            .writeTo(defaultTestPath);
+    }
+
     static List<Map<String, ?>> createTestData() {
         int size = random.nextInt(100) + 1;
         return createTestData(size);
diff --git a/src/test/java/org/ttzero/excel/entity/ListObjectSheetTest.java b/src/test/java/org/ttzero/excel/entity/ListObjectSheetTest.java
index 678ee5f4..b9a29cf7 100644
--- a/src/test/java/org/ttzero/excel/entity/ListObjectSheetTest.java
+++ b/src/test/java/org/ttzero/excel/entity/ListObjectSheetTest.java
@@ -35,6 +35,8 @@ import java.time.LocalDate;
 import java.time.LocalDateTime;
 import java.time.LocalTime;
 import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
 import java.util.Date;
 import java.util.List;
 
@@ -283,6 +285,22 @@ public class ListObjectSheetTest extends WorkbookTest{
             .writeTo(defaultTestPath);
     }
 
+    @Test public void testArray() throws IOException {
+        new Workbook()
+            .watch(Print::println)
+            .addSheet(new ListSheet<>()
+                .setData(Arrays.asList(new Item(1, "abc"), new Item(2, "xyz"))))
+            .writeTo(defaultTestPath);
+    }
+
+    @Test public void testSingleList() throws IOException {
+        new Workbook()
+            .watch(Print::println)
+            .addSheet(new ListSheet<>()
+                .setData(Collections.singletonList(new Item(1, "abc"))))
+            .writeTo(defaultTestPath);
+    }
+
     private StyleProcessor sp = (o, style, sst) -> {
         if ((int)o < 60) {
             style = Styles.clearFill(style)