Repository: wangguanquan/eec
Pull request #186 (2021-06-09 06:32:50)

Fix#185


Patch:
diff --git a/pom.xml b/pom.xml
index 0c169467..62fe83b1 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,7 +5,7 @@
 
   <groupId>org.ttzero</groupId>
   <artifactId>eec</artifactId>
-  <version>0.4.12.1</version>
+  <version>0.4.13-SNAPSHOT</version>
   <name>Excel Write/Read Framework</name>
   <packaging>jar</packaging>
   <url>https://www.ttzero.org</url>
diff --git a/src/main/java/org/ttzero/excel/entity/ListSheet.java b/src/main/java/org/ttzero/excel/entity/ListSheet.java
index ec26c7cc..c349ce1d 100644
--- a/src/main/java/org/ttzero/excel/entity/ListSheet.java
+++ b/src/main/java/org/ttzero/excel/entity/ListSheet.java
@@ -402,6 +402,7 @@ public class ListSheet<T> extends Sheet {
                         methods[i] = method;
                         column.clazz = method.getReturnType();
                         column.key = gs;
+                        column.styles = workbook.getStyles();
                         if (isEmpty(column.name)) {
                             column.name = gs;
                         }
@@ -423,6 +424,7 @@ public class ListSheet<T> extends Sheet {
                 if (column != null) {
                     list.add(column);
                     column.key = gs;
+                    column.styles = workbook.getStyles();
                     if (isEmpty(column.name)) {
                         column.name = gs;
                     }
@@ -466,6 +468,7 @@ public class ListSheet<T> extends Sheet {
                         list.add(column);
                         column.clazz = method.getReturnType();
                         column.key = method.getName();
+                        column.styles = workbook.getStyles();
                         if (isEmpty(column.name)) {
                             column.name = method.getName();
                         }
@@ -495,9 +498,8 @@ public class ListSheet<T> extends Sheet {
                 style = buildHeadStyle(headerStyle.fontColor(), headerStyle.fillFgColor());
             }
             for (i = 0; i < columns.length; i++) {
-                columns[i].styles = workbook.getStyles();
-                if (style > 0 && columns[i].headerStyle == 0)
-                    columns[i].headerStyle = style;
+                if (style > 0 && columns[i].headerStyleIndex == -1)
+                    columns[i].setHeaderStyle(style);
             }
 
             // Clean
diff --git a/src/main/java/org/ttzero/excel/entity/Sheet.java b/src/main/java/org/ttzero/excel/entity/Sheet.java
index 98857575..a64ab53f 100644
--- a/src/main/java/org/ttzero/excel/entity/Sheet.java
+++ b/src/main/java/org/ttzero/excel/entity/Sheet.java
@@ -126,7 +126,16 @@ public abstract class Sheet implements Cloneable, Storable {
      */
     protected boolean hidden;
 
+    /**
+     * The header style index
+     */
+    protected int headStyleIndex = -1;
+
+    /**
+     * The header style value
+     */
     protected int headStyle;
+
     /**
      * Automatic interlacing color
      */
@@ -249,13 +258,21 @@ public abstract class Sheet implements Cloneable, Storable {
          */
         public StyleProcessor styleProcessor;
         /**
-         * The style of cell, -1 if not be setting
+         * The style of cell
+         */
+        public int cellStyle;
+        /**
+         * The style of header
+         */
+        public int headerStyle;
+        /**
+         * The style index of cell, -1 if not be setting
          */
-        public int cellStyle = -1;
+        public int cellStyleIndex = -1;
         /**
-         * The style of header, -1 if not be setting
+         * The style index of header, -1 if not be setting
          */
-        public int headerStyle = -1;
+        public int headerStyleIndex = -1;
         /**
          * The cell width
          */
@@ -558,6 +575,7 @@ public abstract class Sheet implements Cloneable, Storable {
          */
         public Column setCellStyle(int cellStyle) {
             this.cellStyle = cellStyle;
+            this.cellStyleIndex = styles.of(cellStyle);
             return this;
         }
 
@@ -569,6 +587,7 @@ public abstract class Sheet implements Cloneable, Storable {
          */
         public Column setHeaderStyle(int headerStyle) {
             this.headerStyle = headerStyle;
+            this.headerStyleIndex = styles.of(headerStyle);
             return this;
         }
 
@@ -832,10 +851,11 @@ public abstract class Sheet implements Cloneable, Storable {
          * @return the styles value
          */
         public int getCellStyle() {
-            if (cellStyle != -1) {
+            if (cellStyleIndex != -1) {
                 return cellStyle;
             }
-            return cellStyle = getCellStyle(clazz);
+            setCellStyle(getCellStyle(clazz));
+            return cellStyle;
         }
 
         /**
@@ -1271,13 +1291,13 @@ public abstract class Sheet implements Cloneable, Storable {
      */
     public Sheet setHeadStyle(NumFmt numFmt, Font font, Fill fill, Border border, int vertical, int horizontal) {
         Styles styles = workbook.getStyles();
-        headStyle = styles.of(
-            (numFmt != null ? styles.addNumFmt(numFmt) : 0)
-                | (font != null ? styles.addFont(font) : 0)
-                | (fill != null ? styles.addFill(fill) : 0)
-                | (border != null ? styles.addBorder(border) : 0)
-                | vertical
-                | horizontal);
+        headStyle = (numFmt != null ? styles.addNumFmt(numFmt) : 0)
+            | (font != null ? styles.addFont(font) : 0)
+            | (fill != null ? styles.addFill(fill) : 0)
+            | (border != null ? styles.addBorder(border) : 0)
+            | vertical
+            | horizontal;
+        headStyleIndex = styles.of(headStyle);
         return this;
     }
 
@@ -1289,37 +1309,79 @@ public abstract class Sheet implements Cloneable, Storable {
      */
     public Sheet setHeadStyle(int style) {
         headStyle = style;
+        headStyleIndex = workbook.getStyles().of(style);
         return this;
     }
 
+    /**
+     * Setting the header cell styles
+     *
+     * @param styleIndex the styles index
+     * @return the {@link Sheet}
+     */
+    public Sheet setHeadStyleIndex(int styleIndex) {
+        headStyleIndex = styleIndex;
+        headStyle = workbook.getStyles().getStyleByIndex(styleIndex);
+        return this;
+    }
+
+    /**
+     * Returns the header style value
+     *
+     * @return 0 if not set
+     */
+    public int getHeadStyle() {
+        return headStyle;
+    }
+
+    /**
+     * Returns the header style index
+     *
+     * @return -1 if not set
+     */
+    public int getHeadStyleIndex() {
+        return headStyleIndex;
+    }
+
     /**
      * Custom header style according to parameters
      *
      * @param fontColor the font color
      * @param fillBgColor the fill background color
-     * @return style index
+     * @return style value
      */
     public int buildHeadStyle(String fontColor, String fillBgColor) {
         Styles styles = workbook.getStyles();
         Font font = new Font(workbook.getI18N().getOrElse("local-font-family", "Arial")
                 , 12, Font.Style.BOLD, Styles.toColor(fontColor));
-        return styles.of(styles.addFont(font)
+        return styles.addFont(font)
                 | styles.addFill(Fill.parse(fillBgColor))
                 | styles.addBorder(Border.parse("thin black"))
                 | Verticals.CENTER
-                | Horizontals.CENTER);
-
+                | Horizontals.CENTER;
     }
 
     /**
      * Build default header style
      *
-     * @return style index
+     * @return style value
      */
     public int defaultHeadStyle() {
         return headStyle != 0 ? headStyle : (headStyle = this.buildHeadStyle("#ffffff", "#666699"));
     }
 
+    /**
+     * Build default header style
+     *
+     * @return style index
+     */
+    public int defaultHeadStyleIndex() {
+        if (headStyleIndex == -1) {
+            setHeadStyle(this.buildHeadStyle("#ffffff", "#666699"));
+        }
+        return headStyleIndex;
+    }
+
     protected static boolean nonOrIntDefault(int style) {
         return style == -1
             || style == Styles.defaultIntBorderStyle()
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 b59ce1a1..98dc94e4 100644
--- a/src/main/java/org/ttzero/excel/entity/e7/XMLWorksheetWriter.java
+++ b/src/main/java/org/ttzero/excel/entity/e7/XMLWorksheetWriter.java
@@ -390,15 +390,15 @@ public class XMLWorksheetWriter implements IWorksheetWriter {
         bw.writeInt(columns.length);
         bw.write("\">");
 
-        int c = 0, defaultStyle = sheet.defaultHeadStyle();
+        int c = 0, defaultStyleIndex = sheet.defaultHeadStyleIndex();
 
         if (sheet.isAutoSize()) {
             for (Sheet.Column hc : columns) {
-                writeStringAutoSize(isNotEmpty(hc.getName()) ? hc.getName() : hc.key, row, c++, hc.headerStyle == -1 ? defaultStyle : hc.headerStyle);
+                writeStringAutoSize(isNotEmpty(hc.getName()) ? hc.getName() : hc.key, row, c++, hc.headerStyleIndex == -1 ? defaultStyleIndex : hc.headerStyleIndex);
             }
         } else {
             for (Sheet.Column hc : columns) {
-                writeString(isNotEmpty(hc.getName()) ? hc.getName() : hc.key, row, c++, hc.headerStyle == -1 ? defaultStyle : hc.headerStyle);
+                writeString(isNotEmpty(hc.getName()) ? hc.getName() : hc.key, row, c++, hc.headerStyleIndex == -1 ? defaultStyleIndex : hc.headerStyleIndex);
             }
         }
 
diff --git a/src/main/java/org/ttzero/excel/entity/style/Styles.java b/src/main/java/org/ttzero/excel/entity/style/Styles.java
index 6e56cd76..3d57ee73 100644
--- a/src/main/java/org/ttzero/excel/entity/style/Styles.java
+++ b/src/main/java/org/ttzero/excel/entity/style/Styles.java
@@ -30,7 +30,6 @@ import org.dom4j.io.SAXReader;
 
 import java.awt.Color;
 import java.io.IOException;
-import java.io.InputStream;
 import java.lang.reflect.Field;
 import java.nio.file.Files;
 import java.nio.file.Path;
@@ -43,6 +42,7 @@ import java.util.List;
 import java.util.Locale;
 import java.util.Map;
 import java.util.Set;
+import java.util.concurrent.atomic.AtomicInteger;
 
 import static org.ttzero.excel.util.StringUtil.isEmpty;
 import static org.ttzero.excel.util.StringUtil.isNotEmpty;
@@ -71,6 +71,7 @@ import static org.ttzero.excel.util.StringUtil.isNotEmpty;
 public class Styles implements Storable {
 
     private final Map<Integer, Integer> map;
+    private final AtomicInteger counter;
     private Document document;
 
     private List<Font> fonts;
@@ -86,6 +87,7 @@ public class Styles implements Storable {
 
     private Styles() {
         map = new HashMap<>();
+        counter = new AtomicInteger();
     }
 
     /**
@@ -96,14 +98,32 @@ public class Styles implements Storable {
      * @return the style index
      */
     public int of(int s) {
-        int n = map.getOrDefault(s, 0);
-        if (n == 0) {
-            n = addStyle(s);
+        int n = map.getOrDefault(s, -1);
+        if (n == -1) {
+            n = counter.getAndIncrement();
             map.put(s, n);
         }
         return n;
     }
 
+    /**
+     * Search the style value by style index
+     *
+     * @param styleIndex the style index
+     * @return -1 if not found
+     */
+    public int getStyleByIndex(int styleIndex) {
+        if (styleIndex >= counter.get()) {
+            return -1;
+        }
+        for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
+            if (entry.getValue() == styleIndex) {
+                return entry.getKey();
+            }
+        }
+        return -1;
+    }
+
     /**
      * Returns the number of styles
      *
@@ -167,8 +187,6 @@ public class Styles implements Storable {
         self.document = factory.createDocument(rootElement);
 
         self.numFmts = new ArrayList<>();
-//        self.addNumFmt(new NumFmt("yyyy\\-mm\\-dd"));
-//        self.addNumFmt(new NumFmt("yyyy\\-mm\\-dd\\ hh:mm:ss"));
 
         self.fonts = new ArrayList<>();
         Font font1 = new Font(i18N.get("en-font-family"), 11, Color.black);  // en
@@ -298,10 +316,6 @@ public class Styles implements Storable {
                     }
                     numFmt.setId(id);
                     numFmts.add(numFmt);
-
-                    Element element = document.getRootElement().element("numFmts");
-                    element.attribute("count").setValue(String.valueOf(numFmts.size()));
-                    numFmt.toDom4j(element);
                 } else {
                     numFmt.setId(numFmts.get(i).getId());
                 }
@@ -324,10 +338,6 @@ public class Styles implements Storable {
         if (i <= -1) {
             fonts.add(font);
             i = fonts.size() - 1;
-
-            Element element = document.getRootElement().element("fonts");
-            element.attribute("count").setValue(String.valueOf(fonts.size()));
-            font.toDom4j(element);
         }
         return i << INDEX_FONT;
     }
@@ -343,9 +353,6 @@ public class Styles implements Storable {
         if (i <= -1) {
             fills.add(fill);
             i = fills.size() - 1;
-            Element element = document.getRootElement().element("fills");
-            element.attribute("count").setValue(String.valueOf(fills.size()));
-            fill.toDom4j(element);
         }
         return i << INDEX_FILL;
     }
@@ -361,9 +368,6 @@ public class Styles implements Storable {
         if (i <= -1) {
             borders.add(border);
             i = borders.size() - 1;
-            Element element = document.getRootElement().element("borders");
-            element.attribute("count").setValue(String.valueOf(borders.size()));
-            border.toDom4j(element);
         }
         return i << INDEX_BORDER;
     }
@@ -407,83 +411,84 @@ public class Styles implements Storable {
     };
 
     /**
-     * add style in document
+     * Write style to disk
      *
-     * @param s style
-     * @return style index in styles array.
+     * @param styleFile the storage path
+     * @throws IOException if I/O error occur
      */
-    private synchronized int addStyle(int s) {
-        int[] styles = unpack(s);
+    @Override
+    public void writeTo(Path styleFile) throws IOException {
         Element root = document.getRootElement();
-        Element cellXfs = root.element("cellXfs");
-        int count;
-        if (cellXfs == null) {
-            cellXfs = root.addElement("cellXfs").addAttribute("count", "0");
-            count = 0;
-        } else {
-            count = Integer.parseInt(cellXfs.attributeValue("count"));
-        }
 
-        int n = cellXfs.elements().size();
-        Element newXf = cellXfs.addElement("xf");
-        newXf.addAttribute(attrNames[0], String.valueOf(styles[0]))
-            .addAttribute(attrNames[1], String.valueOf(styles[1]))
-            .addAttribute(attrNames[2], String.valueOf(styles[2]))
-            .addAttribute(attrNames[3], String.valueOf(styles[3]))
-            .addAttribute("xfId", "0")
-        ;
-        int start = 7;
-        if (styles[0] > 0) {
-            newXf.addAttribute(attrNames[start], "1");
-        }
-        if (styles[1] > 0) {
-            newXf.addAttribute(attrNames[start + 1], "1");
-        }
-        if (styles[2] > 0) {
-            newXf.addAttribute(attrNames[start + 2], "1");
-        }
-        if (styles[3] > 0) {
-            newXf.addAttribute(attrNames[start + 3], "1");
+        // Number format
+        if (!numFmts.isEmpty()) {
+            Element element = document.getRootElement().element("numFmts");
+            element.attribute("count").setValue(String.valueOf(numFmts.size()));
+            for (NumFmt numFmt : numFmts) numFmt.toDom4j(element);
         }
-        if ((styles[4] | styles[5] | styles[6]) > 0) {
-            newXf.addAttribute(attrNames[start + 4], "1");
+
+        // Font
+        if (!fonts.isEmpty()) {
+            Element element = document.getRootElement().element("fonts");
+            element.attribute("count").setValue(String.valueOf(fonts.size()));
+            for (Font font : fonts) font.toDom4j(element);
         }
 
-        Element subEle = newXf.addElement("alignment").addAttribute(attrNames[4], Verticals.of(styles[4]));
-        if (styles[5] > 0) {
-            subEle.addAttribute(attrNames[5], Horizontals.of(styles[5]));
+        // Fill
+        if (!fills.isEmpty()) {
+            Element element = document.getRootElement().element("fills");
+            element.attribute("count").setValue(String.valueOf(fills.size()));
+            for (Fill fill : fills) fill.toDom4j(element);
         }
-        if (styles[6] > 0) {
-            subEle.addAttribute(attrNames[6], "1");
+
+        // Border
+        if (!borders.isEmpty()) {
+            Element element = document.getRootElement().element("borders");
+            element.attribute("count").setValue(String.valueOf(borders.size()));
+            for (Border border : borders) border.toDom4j(element);
         }
-        cellXfs.addAttribute("count", String.valueOf(count + 1));
-        return n;
-    }
 
-    /**
-     * Write style to disk
-     *
-     * @param styleFile the storage path
-     * @throws IOException if I/O error occur
-     */
-    @Override
-    public void writeTo(Path styleFile) throws IOException {
-        if (document != null) { // Not null
-            FileUtil.writeToDiskNoFormat(document, styleFile);
-        } else {
-            try (InputStream temp = getClass().getClassLoader().getResourceAsStream("template/styles.xml")) {
-                if (temp != null) Files.copy(temp, styleFile);
+        Element cellXfs = root.element("cellXfs").addAttribute("count", String.valueOf(map.size()));
+
+        List<Map.Entry<Integer, Integer>> list = new ArrayList<>(map.entrySet());
+        list.sort(Comparator.comparingInt(Map.Entry::getValue));
+        list.forEach(e -> {
+            int[] styles = unpack(e.getKey());
+
+            Element newXf = cellXfs.addElement("xf");
+            newXf.addAttribute(attrNames[0], String.valueOf(styles[0]))
+                .addAttribute(attrNames[1], String.valueOf(styles[1]))
+                .addAttribute(attrNames[2], String.valueOf(styles[2]))
+                .addAttribute(attrNames[3], String.valueOf(styles[3]))
+                .addAttribute("xfId", "0")
+            ;
+            int start = 7;
+            if (styles[0] > 0) {
+                newXf.addAttribute(attrNames[start], "1");
+            }
+            if (styles[1] > 0) {
+                newXf.addAttribute(attrNames[start + 1], "1");
+            }
+            if (styles[2] > 0) {
+                newXf.addAttribute(attrNames[start + 2], "1");
+            }
+            if (styles[3] > 0) {
+                newXf.addAttribute(attrNames[start + 3], "1");
+            }
+            if ((styles[4] | styles[5] | styles[6]) > 0) {
+                newXf.addAttribute(attrNames[start + 4], "1");
             }
-        }
-    }
 
-    int indexOf(int[] array, int v) {
-        for (int i = 0; i < array.length; i++) {
-            if (array[i] == v) {
-                return i;
+            Element subEle = newXf.addElement("alignment").addAttribute(attrNames[4], Verticals.of(styles[4]));
+            if (styles[5] > 0) {
+                subEle.addAttribute(attrNames[5], Horizontals.of(styles[5]));
             }
-        }
-        return -1;
+            if (styles[6] > 0) {
+                subEle.addAttribute(attrNames[6], "1");
+            }
+        });
+
+        FileUtil.writeToDiskNoFormat(document, styleFile);
     }
 
     ////////////////////////clear style///////////////////////////////
@@ -540,14 +545,6 @@ public class Styles implements Storable {
         return (1 << INDEX_NUMBER_FORMAT) | (1 << INDEX_BORDER) | (Horizontals.RIGHT << INDEX_HORIZONTAL);
     }
 
-//    public static int defaultDateBorderStyle() {
-//        return (176 << INDEX_NUMBER_FORMAT) | (1 << INDEX_BORDER) | (Horizontals.CENTER << INDEX_HORIZONTAL);
-//    }
-//
-//    public static int defaultTimestampBorderStyle() {
-//        return (177 << INDEX_NUMBER_FORMAT) | (1 << INDEX_BORDER) | (Horizontals.CENTER << INDEX_HORIZONTAL);
-//    }
-
     public static int defaultDoubleBorderStyle() {
         return (2 << INDEX_NUMBER_FORMAT) | (1 << INDEX_FONT) | (1 << INDEX_BORDER) | (Horizontals.RIGHT << INDEX_HORIZONTAL);
     }
@@ -565,14 +562,6 @@ public class Styles implements Storable {
         return (1 << INDEX_NUMBER_FORMAT) | (Horizontals.RIGHT << INDEX_HORIZONTAL);
     }
 
-//    public static int defaultDateStyle() {
-//        return (176 << INDEX_NUMBER_FORMAT) | (Horizontals.CENTER << INDEX_HORIZONTAL);
-//    }
-//
-//    public static int defaultTimestampStyle() {
-//        return (177 << INDEX_NUMBER_FORMAT) | (Horizontals.CENTER << INDEX_HORIZONTAL);
-//    }
-
     public static int defaultDoubleStyle() {
         return (2 << INDEX_NUMBER_FORMAT) | (1 << INDEX_FONT) | (Horizontals.RIGHT << INDEX_HORIZONTAL);
     }
diff --git a/src/main/resources/template/styles.xml b/src/main/resources/template/styles.xml
deleted file mode 100644
index 26dee52b..00000000
--- a/src/main/resources/template/styles.xml
+++ /dev/null
@@ -1,190 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
-<styleSheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
-    <numFmts count="12">
-        <numFmt formatCode="0_);[Red]\(0\)" numFmtId="176"/>
-        <numFmt formatCode="0.00_);[Red]\(0.00\)" numFmtId="177"/>
-        <numFmt formatCode="#,##0.00_);[Red](#,##0.00)" numFmtId="178"/>
-        <numFmt formatCode="0.000" numFmtId="179"/>
-        <numFmt formatCode="0.000_);[Red]\(0.000\)" numFmtId="180"/>
-        <numFmt formatCode="0.00%_);[Red]\(0.00%\)" numFmtId="181"/>
-        <numFmt formatCode="¥0" numFmtId="182"/>
-        <numFmt formatCode="¥0.00" numFmtId="183"/>
-        <numFmt formatCode="¥0_);[Red]\(¥0\)" numFmtId="184"/>
-        <numFmt formatCode="¥0.00_);[Red]\(¥0.00\)" numFmtId="185"/>
-        <numFmt formatCode="yyyy\-mm\-dd" numFmtId="186"/>
-        <numFmt formatCode="yyyy\-mm\-dd\ hh:mm:ss" numFmtId="187"/>
-        <numFmt formatCode="0%_);[Red]\(0%\)" numFmtId="188"/>
-    </numFmts>
-    <fonts count="8">
-        <font>
-            <sz val="11"/>
-            <color indexed="8"/>
-            <name val="宋体"/>
-            <family val="2"/>
-            <scheme val="minor"/>
-        </font>
-        <font>
-            <sz val="11"/>
-            <name val="宋体"/>
-            <family val="3"/>
-            <charset val="134"/>
-            <scheme val="minor"/>
-        </font>
-        <font>
-            <b/>
-            <sz val="11"/>
-            <color indexed="9"/>
-            <name val="Arial"/>
-            <family val="2"/>
-            <charset val="134"/>
-        </font>
-        <font>
-            <sz val="11"/>
-            <color indexed="8"/>
-            <name val="Consolas"/>
-            <family val="3"/>
-        </font>
-        <font>
-            <sz val="11"/>
-            <color indexed="8"/>
-            <name val="Arial"/>
-            <family val="2"/>
-            <charset val="134"/>
-        </font>
-        <font>
-            <sz val="11"/>
-            <color rgb="FFFF0000"/>
-            <name val="Consolas"/>
-            <family val="3"/>
-        </font>
-        <font>
-            <b/>
-            <sz val="11"/>
-            <color rgb="FFFF0000"/>
-            <name val="Consolas"/>
-            <family val="3"/>
-        </font>
-        <font>
-            <i/>
-            <sz val="11"/>
-            <color indexed="8"/>
-            <name val="Consolas"/>
-            <family val="3"/>
-        </font>
-    </fonts>
-    <fills count="5">
-        <fill>
-            <patternFill patternType="none"/>
-        </fill>
-        <fill>
-            <patternFill patternType="gray125"/>
-        </fill>
-        <fill>
-            <patternFill patternType="solid">
-                <fgColor rgb="FF666699"/>
-            </patternFill>
-        </fill>
-        <fill>
-            <patternFill patternType="solid">
-                <fgColor rgb="FFFF0000"/>
-                <bgColor indexed="64"/>
-            </patternFill>
-        </fill>
-        <fill>
-            <patternFill patternType="solid">
-                <fgColor rgb="FFFFFF00"/>
-                <bgColor indexed="64"/>
-            </patternFill>
-        </fill>
-    </fills>
-    <borders count="2">
-        <border>
-            <left/>
-            <right/>
-            <top/>
-            <bottom/>
-            <diagonal/>
-        </border>
-        <border>
-            <left style="thin">
-                <color indexed="64"/>
-            </left>
-            <right style="thin">
-                <color indexed="64"/>
-            </right>
-            <top style="thin">
-                <color indexed="64"/>
-            </top>
-            <bottom style="thin">
-                <color indexed="64"/>
-            </bottom>
-            <diagonal/>
-        </border>
-    </borders>
-    <cellStyleXfs count="1">
-        <xf borderId="0" fillId="0" fontId="0" numFmtId="0">
-            <alignment vertical="center"/>
-        </xf>
-    </cellStyleXfs>
-    <cellXfs count="18">
-        <xf numFmtId="0" borderId="0" fillId="0" fontId="0" xfId="0">
-            <alignment vertical="center"/>
-        </xf>
-        <xf numFmtId="0" borderId="0" fillId="0" fontId="0" xfId="0" applyAlignment="1">
-            <alignment vertical="center"/>
-        </xf>
-        <xf numFmtId="0" borderId="1" fillId="2" fontId="2" xfId="0" applyAlignment="1" applyBorder="1" applyFill="1" applyFont="1">
-            <alignment vertical="center" horizontal="center"/>
-        </xf>
-        <xf numFmtId="0" borderId="1" fillId="0" fontId="3" xfId="0" applyAlignment="1" applyBorder="1" applyFont="1">
-            <alignment vertical="center" horizontal="centerContinuous"/>
-        </xf>
-        <xf numFmtId="176" borderId="1" fillId="0" fontId="3" xfId="0" applyAlignment="1" applyBorder="1" applyFont="1" applyNumberFormat="1">
-            <alignment vertical="center" horizontal="right"/>
-        </xf>
-        <xf numFmtId="177" borderId="1" fillId="0" fontId="3" xfId="0" applyAlignment="1" applyBorder="1" applyFont="1" applyNumberFormat="1">
-            <alignment vertical="center" horizontal="right"/>
-        </xf>
-        <xf numFmtId="187" borderId="1" fillId="0" fontId="3" xfId="0" applyAlignment="1" applyBorder="1" applyFont="1" applyNumberFormat="1">
-            <alignment vertical="center" horizontal="centerContinuous"/>
-        </xf>
-        <xf numFmtId="181" borderId="1" fillId="0" fontId="3" xfId="0" applyAlignment="1" applyBorder="1" applyFont="1" applyNumberFormat="1">
-            <alignment vertical="center" horizontal="right"/>
-        </xf>
-        <xf numFmtId="186" borderId="1" fillId="0" fontId="3" xfId="0" applyAlignment="1" applyBorder="1" applyFont="1" applyNumberFormat="1">
-            <alignment vertical="center" horizontal="centerContinuous"/>
-        </xf>
-        <xf numFmtId="0" borderId="1" fillId="0" fontId="4" xfId="0" applyAlignment="1" applyBorder="1" applyFont="1">
-            <alignment vertical="center" horizontal="left"/>
-        </xf>
-        <xf numFmtId="0" borderId="1" fillId="0" fontId="3" xfId="0" applyAlignment="1" applyBorder="1" applyFont="1">
-            <alignment vertical="center" horizontal="left"/>
-        </xf>
-        <xf numFmtId="0" borderId="1" fillId="0" fontId="4" xfId="0" applyAlignment="1" applyBorder="1" applyFont="1">
-            <alignment vertical="center" horizontal="center"/>
-        </xf>
-        <xf numFmtId="176" borderId="1" fillId="3" fontId="3" xfId="0" applyAlignment="1" applyBorder="1" applyFill="1" applyFont="1" applyNumberFormat="1">
-            <alignment vertical="center" horizontal="right"/>
-        </xf>
-        <xf numFmtId="177" borderId="1" fillId="3" fontId="3" xfId="0" applyAlignment="1" applyBorder="1" applyFill="1" applyFont="1" applyNumberFormat="1">
-            <alignment vertical="center" horizontal="right"/>
-        </xf>
-        <xf numFmtId="177" borderId="1" fillId="4" fontId="3" xfId="0" applyAlignment="1" applyBorder="1" applyFill="1" applyFont="1" applyNumberFormat="1">
-            <alignment vertical="center" horizontal="right"/>
-        </xf>
-        <xf numFmtId="177" borderId="1" fillId="0" fontId="5" xfId="0" applyAlignment="1" applyBorder="1" applyFont="1" applyNumberFormat="1">
-            <alignment vertical="center" horizontal="right"/>
-        </xf>
-        <xf numFmtId="176" borderId="1" fillId="0" fontId="6" xfId="0" applyAlignment="1" applyBorder="1" applyFont="1" applyNumberFormat="1">
-            <alignment vertical="center" horizontal="right"/>
-        </xf>
-        <xf numFmtId="176" borderId="1" fillId="0" fontId="7" xfId="0" applyAlignment="1" applyBorder="1" applyFont="1" applyNumberFormat="1">
-            <alignment vertical="center" horizontal="right"/>
-        </xf>
-    </cellXfs>
-    <cellStyles count="1">
-        <cellStyle builtinId="0" name="常规" xfId="0"/>
-    </cellStyles>
-    <dxfs count="0"/>
-    <tableStyles count="0" defaultPivotStyle="PivotStyleLight16" defaultTableStyle="TableStyleMedium9"/>
-</styleSheet>
\ No newline at end of file


Test patch:
diff --git a/src/test/java/org/ttzero/excel/entity/ListObjectSheetTest.java b/src/test/java/org/ttzero/excel/entity/ListObjectSheetTest.java
index 41144f19..3bc9fa86 100644
--- a/src/test/java/org/ttzero/excel/entity/ListObjectSheetTest.java
+++ b/src/test/java/org/ttzero/excel/entity/ListObjectSheetTest.java
@@ -21,6 +21,7 @@ import org.ttzero.excel.Print;
 import org.ttzero.excel.annotation.ExcelColumn;
 import org.ttzero.excel.annotation.IgnoreExport;
 import org.ttzero.excel.entity.style.Fill;
+import org.ttzero.excel.entity.style.Font;
 import org.ttzero.excel.entity.style.PatternType;
 import org.ttzero.excel.entity.style.Styles;
 import org.ttzero.excel.manager.docProps.Core;
@@ -597,6 +598,18 @@ public class ListObjectSheetTest extends WorkbookTest {
                                 , new Item(2, "fdsafdsafdsafdsafdsafdsafdsafdsfadsafdsafdsafdsafdsafdsafds"))))
                 .writeTo(defaultTestPath);
     }
+
+    @Test public void testClearHeadStyle() throws IOException {
+        Workbook workbook = new Workbook("clear style").addSheet(new ListSheet<>(Item.randomTestData()));
+
+        Sheet sheet = workbook.getSheetAt(0);
+        sheet.cancelOddStyle();  // Clear odd style
+        int headStyle = sheet.defaultHeadStyle();
+        sheet.setHeadStyle(Styles.clearFill(headStyle) & Styles.clearFont(headStyle));
+        sheet.setHeadStyle(sheet.getHeadStyle() | workbook.getStyles().addFont(new Font("宋体", 11, Font.Style.BOLD, Color.BLACK)));
+
+        workbook.writeTo(defaultTestPath);
+    }
     
     public static class Item {
         @ExcelColumn