@@ -434,7 +434,7 @@ func (t *Table) getBorderLeft(hint renderHint) string {
434434 } else if hint .isSeparatorRow {
435435 if t .autoIndex && hint .isHeaderOrFooterSeparator () {
436436 border = t .style .Box .Left
437- } else if ! t .autoIndex && t .shouldMergeCellsVertically (0 , hint ) {
437+ } else if ! t .autoIndex && t .shouldMergeCellsVerticallyAbove (0 , hint ) {
438438 border = t .style .Box .Left
439439 } else {
440440 border = t .style .Box .LeftSeparator
@@ -454,7 +454,7 @@ func (t *Table) getBorderRight(hint renderHint) string {
454454 } else if hint .isBorderBottom {
455455 border = t .style .Box .BottomRight
456456 } else if hint .isSeparatorRow {
457- if t .shouldMergeCellsVertically (t .numColumns - 1 , hint ) {
457+ if t .shouldMergeCellsVerticallyAbove (t .numColumns - 1 , hint ) {
458458 border = t .style .Box .Right
459459 } else {
460460 border = t .style .Box .RightSeparator
@@ -525,12 +525,12 @@ func (t *Table) getColumnSeparator(row rowStr, colIdx int, hint renderHint) stri
525525}
526526
527527func (t * Table ) getColumnSeparatorNonBorder (mergeCellsAbove bool , mergeCellsBelow bool , colIdx int , hint renderHint ) string {
528- mergeNextCol := t .shouldMergeCellsVertically (colIdx , hint )
528+ mergeNextCol := t .shouldMergeCellsVerticallyAbove (colIdx , hint )
529529 if hint .isAutoIndexColumn {
530530 return t .getColumnSeparatorNonBorderAutoIndex (mergeNextCol , hint )
531531 }
532532
533- mergeCurrCol := t .shouldMergeCellsVertically (colIdx - 1 , hint )
533+ mergeCurrCol := t .shouldMergeCellsVerticallyAbove (colIdx - 1 , hint )
534534 return t .getColumnSeparatorNonBorderNonAutoIndex (mergeCellsAbove , mergeCellsBelow , mergeCurrCol , mergeNextCol )
535535}
536536
@@ -839,7 +839,7 @@ func (t *Table) shouldMergeCellsHorizontallyBelow(row rowStr, colIdx int, hint r
839839 return false
840840}
841841
842- func (t * Table ) shouldMergeCellsVertically (colIdx int , hint renderHint ) bool {
842+ func (t * Table ) shouldMergeCellsVerticallyAbove (colIdx int , hint renderHint ) bool {
843843 if ! t .firstRowOfPage && t .columnConfigMap [colIdx ].AutoMerge && colIdx < t .numColumns {
844844 if hint .isSeparatorRow {
845845 rowPrev := t .getRow (hint .rowNumber - 1 , hint )
@@ -858,6 +858,23 @@ func (t *Table) shouldMergeCellsVertically(colIdx int, hint renderHint) bool {
858858 return false
859859}
860860
861+ func (t * Table ) shouldMergeCellsVerticallyBelow (colIdx int , hint renderHint ) int {
862+ numRowsToMerge := 0
863+ if t .columnConfigMap [colIdx ].AutoMerge && colIdx < t .numColumns {
864+ numRowsToMerge = 1
865+ rowCurr := t .getRow (hint .rowNumber - 1 , hint )
866+ for rowIdx := hint .rowNumber ; rowIdx < len (t .rows ); rowIdx ++ {
867+ rowNext := t .getRow (rowIdx , hint )
868+ if colIdx < len (rowCurr ) && colIdx < len (rowNext ) && rowNext [colIdx ] == rowCurr [colIdx ] {
869+ numRowsToMerge ++
870+ } else {
871+ break
872+ }
873+ }
874+ }
875+ return numRowsToMerge
876+ }
877+
861878func (t * Table ) shouldSeparateRows (rowIdx int , numRows int ) bool {
862879 // not asked to separate rows and no manually added separator
863880 if ! t .style .Options .SeparateRows && ! t .separators [rowIdx ] {
0 commit comments