Repository: wangguanquan/eec
Pull request #276 (2022-08-02 11:45:35)

#275 Support hidden gird lines


Patch:
diff --git a/README.md b/README.md
index 4e4b0d1c..73663116 100644
--- a/README.md
+++ b/README.md
@@ -7,11 +7,11 @@ EEC的设计初衷是为了解决Apache POI速度慢，高内存且API臃肿的
 
 EEC最大特点是`高速`和`低内存`，如果在项目中做数据导入导出功能，选用EEC将为你带来极大的便利，同时它的`可扩展`能力也不弱。
 
-使用`inlineStr`模式的情况下EEC的读写内存可以控制在*10MB*以下，`SharedString`模式也可以控制在*16MB*以下。[这里](https://www.ttzero.org/excel/2020/03/05/eec-vs-easyexcel-2.html) 有关于EEC的压力测试，最低可以在*6MB*的情况下完成1,000,000行x29列数据的读写。
+使用`inlineStr`模式的情况下EEC的读写内存可以控制在*10MB*以下，`SharedString`模式也可以控制在*16MB*以下。[这里](https://www.ttzero.org/excel/2020/03/05/eec-vs-easyexcel-2.html) 有关于EEC的压力测试，最低可以在*6MB*的情况下完成100w行x29列数据的读写。
 
 EEC采用单线程、高IO设计，所以多核心、高内存并不能显著提高速度，高主频和一块好SSD能显著提升速度。
 
-EEC在JVM参数`-Xmx6m -Xms1m`下读写`1,000,000行x29列`内存使用截图
+EEC在JVM参数`-Xmx6m -Xms1m`下读写`100w行x29列`内存使用截图
 
 写文件
 
@@ -75,16 +75,16 @@ pom.xml添加
 对象数组导出时可以在对象上使用注解`@ExcelColumn("column name")`来设置excel头部信息，未添加ExcelColumn注解标记的属性将不会被导出，也可以通过调用`forceExport`方法来强制导出。
 
 ```java
-    private int id; // not export
+private int id; // not export
 
-    @ExcelColumn("渠道ID")
-    private int channelId;
+@ExcelColumn("渠道ID")
+private int channelId;
 
-    @ExcelColumn
-    private String account;
+@ExcelColumn
+private String account;
 
-    @ExcelColumn("注册时间")
-    private Timestamp registered;
+@ExcelColumn("注册时间")
+private Timestamp registered;
 ```
 
 默认情况下导出的列顺序与字段在对象中的定义顺序一致，也可以设置`colIndex`或者在`addSheet`时重置列头顺序。
@@ -233,7 +233,7 @@ reader.sheets()
     .collect(Collectors.toList());
 ```
 
-以上代码相当于`select * from 用户注册 where platform = 'iOS'`
+以上代码相当于SQL `select * from '用户注册' where platform = 'iOS'`
 
 ### xls格式支持
 
diff --git a/src/main/java/org/ttzero/excel/annotation/ExcelColumns.java b/src/main/java/org/ttzero/excel/annotation/ExcelColumns.java
index f6cf6dae..6534ae7c 100644
--- a/src/main/java/org/ttzero/excel/annotation/ExcelColumns.java
+++ b/src/main/java/org/ttzero/excel/annotation/ExcelColumns.java
@@ -35,6 +35,8 @@ import java.lang.annotation.Target;
 public @interface ExcelColumns {
     /**
      * Repeat ExcelColumn
+     *
+     * @return header {@link ExcelColumn} array
      */
     ExcelColumn[] value();
 }
diff --git a/src/main/java/org/ttzero/excel/annotation/HeaderStyle.java b/src/main/java/org/ttzero/excel/annotation/HeaderStyle.java
index 562b897a..8f38d71b 100644
--- a/src/main/java/org/ttzero/excel/annotation/HeaderStyle.java
+++ b/src/main/java/org/ttzero/excel/annotation/HeaderStyle.java
@@ -51,5 +51,4 @@ public @interface HeaderStyle {
      * @return color
      */
     String fillFgColor() default "#666699";
-
 }
diff --git a/src/main/java/org/ttzero/excel/entity/Column.java b/src/main/java/org/ttzero/excel/entity/Column.java
index 5cc290e0..b2d5bdcd 100644
--- a/src/main/java/org/ttzero/excel/entity/Column.java
+++ b/src/main/java/org/ttzero/excel/entity/Column.java
@@ -663,6 +663,17 @@ public class Column {
         return this;
     }
 
+    /**
+     * Setting a cell format of number or date type
+     *
+     * @param numFmt {@link NumFmt}
+     * @return the {@link Column}
+     */
+    public Column setNumFmt(NumFmt numFmt) {
+        this.numFmt = numFmt;
+        return this;
+    }
+
     /**
      * Returns the column {@link NumFmt}
      *
diff --git a/src/main/java/org/ttzero/excel/entity/Sheet.java b/src/main/java/org/ttzero/excel/entity/Sheet.java
index 9cbee1c8..900e21b1 100644
--- a/src/main/java/org/ttzero/excel/entity/Sheet.java
+++ b/src/main/java/org/ttzero/excel/entity/Sheet.java
@@ -181,6 +181,11 @@ public abstract class Sheet implements Cloneable, Storable {
      */
     protected int extPropMark;
 
+    /**
+     * Show grid lines
+     */
+    protected Boolean showGridLines;
+
     public int getId() {
         return id;
     }
@@ -204,6 +209,8 @@ public abstract class Sheet implements Cloneable, Storable {
 
     /**
      * Returns {@link IWorksheetWriter}
+     *
+     * @return custom IWorksheetWriter
      */
     public IWorksheetWriter getSheetWriter() {
         return sheetWriter;
@@ -552,6 +559,35 @@ public abstract class Sheet implements Cloneable, Storable {
         return comments;
     }
 
+    /**
+     * Returns show grid lines flag
+     *
+     * @return true if {@code showGridLines} is null or {@code true}
+     */
+    public boolean isShowGridLines() {
+        return showGridLines == null || showGridLines;
+    }
+
+    /**
+     * Setting show grid lines flag
+     *
+     * @return current {@link Sheet}
+     */
+    public Sheet showGridLines() {
+        this.showGridLines = true;
+        return this;
+    }
+
+    /**
+     * Setting show grid lines flag
+     *
+     * @return current {@link Sheet}
+     */
+    public Sheet hideGridLines() {
+        this.showGridLines = false;
+        return this;
+    }
+
     /**
      * Returns the header column info
      * <p>
diff --git a/src/main/java/org/ttzero/excel/entity/e7/XMLWorksheetWriter.java b/src/main/java/org/ttzero/excel/entity/e7/XMLWorksheetWriter.java
index 35abad51..bb881f23 100644
--- a/src/main/java/org/ttzero/excel/entity/e7/XMLWorksheetWriter.java
+++ b/src/main/java/org/ttzero/excel/entity/e7/XMLWorksheetWriter.java
@@ -972,9 +972,10 @@ public class XMLWorksheetWriter implements IWorksheetWriter {
         bw.write("<sheetViews>");
 
         bw.write("<sheetView workbookViewId=\"0\"");
-        if (sheet.getId() == 1) { // Default select the first worksheet
-            bw.write(" tabSelected=\"1\"");
-        }
+        // Default show grid lines
+        if (!sheet.isShowGridLines()) bw.write(" showGridLines=\"0\"");
+        // Default select the first worksheet
+        if (sheet.getId() == 1) bw.write(" tabSelected=\"1\"");
 
         // Freeze Panes
         Object o = sheet.getExtPropValue(Const.ExtendPropertyKey.FREEZE);


Test patch:
diff --git a/src/test/java/org/ttzero/excel/entity/GridLinesTest.java b/src/test/java/org/ttzero/excel/entity/GridLinesTest.java
new file mode 100644
index 00000000..3c71713e
--- /dev/null
+++ b/src/test/java/org/ttzero/excel/entity/GridLinesTest.java
@@ -0,0 +1,104 @@
+/*
+ * Copyright (c) 2017-2022, guanquan.wang@yandex.com All Rights Reserved.
+ *
+ * Licensed 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.ttzero.excel.entity;
+
+import org.junit.Test;
+import org.ttzero.excel.entity.e7.XMLWorksheetWriter;
+
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Timestamp;
+import java.util.List;
+import java.util.function.Supplier;
+
+import static org.ttzero.excel.entity.ListMapSheetTest.createTestData;
+
+/**
+ * @author guanquan.wang at 2022-08-02 19:17
+ */
+public class GridLinesTest extends SQLWorkbookTest {
+    @Test public void testListSheet() throws IOException {
+        new Workbook("ListSheet ignore grid lines")
+            .addSheet(new ListSheet<>(ListObjectSheetTest.Item.randomTestData()).hideGridLines())
+            .writeTo(defaultTestPath);
+    }
+
+    @Test public void testListSheetPaging() throws IOException {
+        new Workbook("ListSheet Paging ignore grid lines")
+            .setAutoSize(true)
+            .addSheet(new ListSheet<>(ListObjectSheetTest.Item.randomTestData()).hideGridLines()
+                .setSheetWriter(new XMLWorksheetWriter() {
+                @Override
+                public int getRowLimit() {
+                    return 10;
+                }
+            }))
+            .writeTo(defaultTestPath);
+    }
+
+    @Test public void testListMapSheet() throws IOException {
+        new Workbook("ListMapSheet ignore grid lines")
+            .addSheet(new ListMapSheet(createTestData()).hideGridLines())
+            .writeTo(defaultTestPath);
+    }
+
+    @Test public void testStatementSheet() throws SQLException, IOException {
+        try (Connection con = getConnection()) {
+            new Workbook("StatementSheet ignore grid lines")
+                .addSheet(new StatementSheet(con, "select id, name, age, create_date, update_date from student order by age"
+                    , new Column("学号", int.class)
+                    , new Column("性名", String.class)
+                    , new Column("年龄", int.class)
+                    , new Column("创建时间", Timestamp.class).setColIndex(0)
+                    , new Column("更新", Timestamp.class)
+                ).hideGridLines()).writeTo(defaultTestPath);
+        }
+    }
+
+    @Test public void testResultSetSheet() throws SQLException, IOException {
+        try (
+            Connection con = getConnection();
+            PreparedStatement ps = con.prepareStatement("select id, name, age, create_date, update_date from student limit 10");
+            ResultSet rs = ps.executeQuery()
+        ) {
+            new Workbook("ResultSetSheet ignore grid lines")
+                .setConnection(con)
+                .addSheet(new ResultSetSheet(rs
+                    , new Column("学号", int.class)
+                    , new Column("性名", String.class)
+                    , new Column("年龄", Integer.class)
+                    , new Column("创建时间", Timestamp.class)
+                    , new Column("更新", Timestamp.class)
+                ).hideGridLines()).writeTo(defaultTestPath);
+        }
+    }
+
+    public static class HideGridLineAllType extends ListObjectSheetTest.AllType {
+        public static List<ListObjectSheetTest.AllType> randomTestData() {
+            return randomTestData(HideGridLineAllType::new);
+        }
+
+        public static List<ListObjectSheetTest.AllType> randomTestData(Supplier<ListObjectSheetTest.AllType> sup) {
+            int size = random.nextInt(100) + 1;
+            return randomTestData(size, sup);
+        }
+    }
+}