tealeg / xlsx

Go library for reading and writing XLSX files.
Other
5.85k stars 819 forks source link

seems there is a bug in SetColAutoWidth #716

Closed ZongrongLi closed 1 year ago

ZongrongLi commented 3 years ago

v3@v3.2.3

func (s *Sheet) SetColAutoWidth(colIndex int, width func(string) float64) error {
    s.mustBeOpen()
    largestWidth := 0.0
    rowVisitor := func(r *Row) error {
        cell := r.GetCell(colIndex)
        value, err := cell.FormattedValue()
        if err != nil {
            return err
        }

        if width(value) > largestWidth {
            largestWidth = width(value)
        }
        return nil
    }
    err := s.ForEachRow(rowVisitor)

    if err != nil {
        return err
    }
    fmt.Println("====>>", colIndex, colIndex, largestWidth)
    s.SetColWidth(colIndex, colIndex, largestWidth)

    return nil
}
cell := r.GetCell(colIndex) // get col of index start from 0

and

s.SetColWidth(colIndex, colIndex, largestWidth) //set width of col from index start from 1
github-actions[bot] commented 1 year ago

Stale issue message