@@ -57,11 +57,14 @@ public class TableBuilder<T> extends SheetBuilderHelper {
5757
5858 private int thisCol = -1 ;
5959
60+ private int lastCol ;
61+
6062 protected TableBuilder (SheetBuilder parent , Class <T > type ) {
6163 super (parent , parent .sheet );
6264 this .parent = parent ;
6365 this .type = type ;
6466 this .properties = getProperties (type );
67+ this .lastCol = properties .size () - 1 ;
6568 }
6669
6770 /**
@@ -141,7 +144,6 @@ public TableBuilder<T> createRow(T object) {
141144 lastRow = thisRow ;
142145 List <Cell > cells = resolveCells (object );
143146 int maxRow = 0 ;
144- int maxCol = 0 ;
145147 for (Cell cell : cells ) {
146148 int firstRow = cell .getFirstRow ();
147149 int lastRow = cell .getLastRow ();
@@ -155,10 +157,9 @@ public TableBuilder<T> createRow(T object) {
155157 .addMergedRegion ();
156158 }
157159 maxRow = Math .max (lastRow , maxRow );
158- maxCol = Math .max (lastCol , maxCol );
159160 }
160161 // 填充未定义的单元
161- parent .matchingRegion (thisRow , maxRow , 0 , maxCol ).fillUndefinedCells ();
162+ parent .matchingRegion (thisRow , maxRow , 0 , lastCol ).fillUndefinedCells ();
162163 return this ;
163164 }
164165
@@ -194,6 +195,7 @@ public TableBuilder<T> createHeader(String... names) {
194195 }
195196 thisRow = parent .sheet .getLastRowNum () + 1 ;
196197 lastRow = thisRow ;
198+ lastCol = properties .size () - 1 ;
197199 List <Column > headers = resolveHeaders (null , type );
198200 for (Column header : headers ) {
199201 createHeader (header );
0 commit comments