jedib0t / go-pretty

Table-writer and more in golang!
MIT License
3.06k stars 120 forks source link

Paging is set when row/column cell merge is set at the same time, missing some cell data #315

Closed xjxl520303 closed 7 months ago

xjxl520303 commented 8 months ago

Describe the bug

When I set row auto merge and the column 2 auto merge, then set pagination, I found some separated page item missing the data same as last page's last row or column or multiple r/c.

To Reproduce

here is the code

package main

import (
    "fmt"
    "os"

    "github.com/jedib0t/go-pretty/v6/table"
    "github.com/xuri/excelize/v2"
)

func main() {
    f, err := excelize.OpenFile("E:\\ExcelDemo\\titanic.xlsx")
    if err != nil {
        fmt.Println(err)
        return
    }
    defer func() {
        if err := f.Close(); err != nil {
            fmt.Println(err)
        }
    }()
    rows, err := f.GetRows("titanic")
    if err != nil {
        fmt.Println(err)
        return
    }

    rowConfigAutoMerge := table.RowConfig{AutoMerge: true}
    t := table.NewWriter()
    t.SetOutputMirror(os.Stdout)

    tableHeader := make(table.Row, 0)
    for _, cell := range rows[0] {
        tableHeader = append(tableHeader, cell)
    }
    t.AppendHeader(tableHeader, rowConfigAutoMerge)

    for _, row := range rows[1:10] {
        innerRow := make(table.Row, 0)
        for _, cell := range row {
            innerRow = append(innerRow, cell)
        }
        t.AppendRow(innerRow, rowConfigAutoMerge)
        t.AppendSeparator()
    }
    t.SetColumnConfigs([]table.ColumnConfig{
        {Number: 2, AutoMerge: true},
    })
    t.SetPageSize(3)
    t.Render()
}

Screenshots

  1. original excel data screenshot.

image

  1. without pagination result screenshot.

image

  1. unexpected result screenshot.

image

Software (please complete the following information):

jedib0t commented 8 months ago

Paging and auto-merge has never been tested. 😭

I'll take a look at this as soon as I can.

jedib0t commented 7 months ago

@xjxl520303 check https://github.com/jedib0t/go-pretty/releases/tag/v6.5.8 --- this should fix it.