1717import com .alibaba .excel .annotation .ExcelProperty ;
1818import com .alibaba .excel .annotation .format .DateTimeFormat ;
1919import com .alibaba .excel .annotation .format .NumberFormat ;
20- import com .alibaba .excel .annotation .write .style .ColumnWidth ;
2120import com .alibaba .excel .converters .AutoConverter ;
2221import com .alibaba .excel .converters .Converter ;
2322import com .alibaba .excel .enums .HeadKindEnum ;
2423import com .alibaba .excel .exception .ExcelCommonException ;
2524import com .alibaba .excel .exception .ExcelGenerateException ;
2625import com .alibaba .excel .metadata .Head ;
26+ import com .alibaba .excel .metadata .Holder ;
2727import com .alibaba .excel .util .StringUtils ;
28+ import com .alibaba .excel .write .metadata .holder .AbstractWriteHolder ;
2829
2930/**
3031 * Define the header attribute of excel
@@ -46,7 +47,6 @@ public class ExcelHeadProperty {
4647 * The number of rows in the line with the most rows
4748 */
4849 private int headRowNumber ;
49-
5050 /**
5151 * Configuration header information
5252 */
@@ -64,7 +64,7 @@ public class ExcelHeadProperty {
6464 */
6565 private Map <String , Field > ignoreMap ;
6666
67- public ExcelHeadProperty (Class headClazz , List <List <String >> head , Boolean convertAllFiled ) {
67+ public ExcelHeadProperty (Holder holder , Class headClazz , List <List <String >> head , Boolean convertAllFiled ) {
6868 this .headClazz = headClazz ;
6969 headMap = new TreeMap <Integer , Head >();
7070 contentPropertyMap = new TreeMap <Integer , ExcelContentProperty >();
@@ -73,14 +73,21 @@ public ExcelHeadProperty(Class headClazz, List<List<String>> head, Boolean conve
7373 headKind = HeadKindEnum .NONE ;
7474 headRowNumber = 0 ;
7575 if (head != null && !head .isEmpty ()) {
76+ int headIndex = 0 ;
7677 for (int i = 0 ; i < head .size (); i ++) {
77- headMap .put (i , new Head (i , null , head .get (i ), Boolean .FALSE , Boolean .TRUE ));
78- contentPropertyMap .put (i , null );
78+ if (holder instanceof AbstractWriteHolder ) {
79+ if (((AbstractWriteHolder )holder ).ignore (null , i )) {
80+ continue ;
81+ }
82+ }
83+ headMap .put (headIndex , new Head (headIndex , null , head .get (i ), Boolean .FALSE , Boolean .TRUE ));
84+ contentPropertyMap .put (headIndex , null );
85+ headIndex ++;
7986 }
8087 headKind = HeadKindEnum .STRING ;
8188 } else {
8289 // convert headClazz to head
83- initColumnProperties (convertAllFiled );
90+ initColumnProperties (holder , convertAllFiled );
8491 }
8592 initHeadRowNumber ();
8693 if (LOGGER .isDebugEnabled ()) {
@@ -108,7 +115,7 @@ private void initHeadRowNumber() {
108115 }
109116 }
110117
111- private void initColumnProperties (Boolean convertAllFiled ) {
118+ private void initColumnProperties (Holder holder , Boolean convertAllFiled ) {
112119 if (headClazz == null ) {
113120 return ;
114121 }
@@ -161,20 +168,36 @@ private void initColumnProperties(Boolean convertAllFiled) {
161168 int index = 0 ;
162169 for (Field field : defaultFieldList ) {
163170 while (customFiledMap .containsKey (index )) {
164- initOneColumnProperty (index , customFiledMap .get (index ), Boolean .TRUE );
165171 customFiledMap .remove (index );
172+ if (!initOneColumnProperty (holder , index , customFiledMap .get (index ), Boolean .TRUE )) {
173+ index ++;
174+ }
175+ }
176+ if (!initOneColumnProperty (holder , index , field , Boolean .FALSE )) {
166177 index ++;
167178 }
168- initOneColumnProperty (index , field , Boolean .FALSE );
169- index ++;
170179 }
171180 for (Map .Entry <Integer , Field > entry : customFiledMap .entrySet ()) {
172- initOneColumnProperty (entry .getKey (), entry .getValue (), Boolean .TRUE );
181+ initOneColumnProperty (holder , entry .getKey (), entry .getValue (), Boolean .TRUE );
173182 }
174183 headKind = HeadKindEnum .CLASS ;
175184 }
176185
177- private void initOneColumnProperty (int index , Field field , Boolean forceIndex ) {
186+ /**
187+ * Initialization column property
188+ *
189+ * @param holder
190+ * @param index
191+ * @param field
192+ * @param forceIndex
193+ * @return Ignore current field
194+ */
195+ private boolean initOneColumnProperty (Holder holder , int index , Field field , Boolean forceIndex ) {
196+ if (holder instanceof AbstractWriteHolder ) {
197+ if (((AbstractWriteHolder )holder ).ignore (field .getName (), index )) {
198+ return true ;
199+ }
200+ }
178201 ExcelProperty excelProperty = field .getAnnotation (ExcelProperty .class );
179202 List <String > tmpHeadList = new ArrayList <String >();
180203 boolean notForceName = excelProperty == null || excelProperty .value ().length <= 0
@@ -206,6 +229,7 @@ private void initOneColumnProperty(int index, Field field, Boolean forceIndex) {
206229 headMap .put (index , head );
207230 contentPropertyMap .put (index , excelContentProperty );
208231 fieldNameContentPropertyMap .put (field .getName (), excelContentProperty );
232+ return false ;
209233 }
210234
211235 public Class getHeadClazz () {
0 commit comments