From 6fa94021f7a260ccd8e1a84c8e9dfa5a07e395eb Mon Sep 17 00:00:00 2001 From: Noboru Saito Date: Mon, 20 Nov 2023 20:33:38 +0900 Subject: [PATCH 1/2] Also consider cellname as y --- reader.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/reader.go b/reader.go index 14c5054..3737e8e 100644 --- a/reader.go +++ b/reader.go @@ -46,6 +46,7 @@ func NewXLSXReader(reader io.Reader, opts *trdsql.ReadOpts) (trdsql.Reader, erro } isFilter = true cellX-- + cellY-- } rows, err := f.GetRows(sheet) @@ -87,7 +88,7 @@ func NewXLSXReader(reader io.Reader, opts *trdsql.ReadOpts) (trdsql.Reader, erro } } - r.names, r.types = nameType(rows[header], cellX, columnNum, opts.InHeader) + r.names, r.types = nameType(rows[header], cellX, cellY, columnNum, opts.InHeader) rowNum := len(rows) - skip body := make([][]any, 0, rowNum) validColumns := make([]bool, columnNum) @@ -95,7 +96,7 @@ func NewXLSXReader(reader io.Reader, opts *trdsql.ReadOpts) (trdsql.Reader, erro if r.names[i] != "" { validColumns[i] = true } else { - name, err := cellName(cellX + i) + name, err := cellName(cellX+i, cellY) if err != nil { return nil, err } @@ -134,8 +135,8 @@ func NewXLSXReader(reader io.Reader, opts *trdsql.ReadOpts) (trdsql.Reader, erro return r, nil } -func cellName(i int) (string, error) { - cn, err := excelize.CoordinatesToCellName(i+1, 1) +func cellName(x int, y int) (string, error) { + cn, err := excelize.CoordinatesToCellName(x+1, y+1) if err != nil { return "", err } @@ -195,7 +196,7 @@ func parseExtend(ext string) (string, string) { } } -func nameType(row []string, cellX int, columnNum int, header bool) ([]string, []string) { +func nameType(row []string, cellX int, cellY int, columnNum int, header bool) ([]string, []string) { nameMap := make(map[string]bool) names := make([]string, columnNum) types := make([]string, columnNum) @@ -203,7 +204,7 @@ func nameType(row []string, cellX int, columnNum int, header bool) ([]string, [] for i := cellX; i < cellX+columnNum; i++ { if header && len(row) > i && row[i] != "" { if _, ok := nameMap[row[i]]; ok { - name, err := cellName(cellX + i) + name, err := cellName(cellX+i, cellY) if err != nil { names[c] = row[i] + "_" + fmt.Sprint(i) } else { From 0eda609f3f8b91dc252308f392aefb6363f1c1fd Mon Sep 17 00:00:00 2001 From: Noboru Saito Date: Tue, 21 Nov 2023 06:33:26 +0900 Subject: [PATCH 2/2] Fixed by decrementing cellY by 1 first Modified to stop decrementing when skip is set, because cellY was decreased by 1. --- reader.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/reader.go b/reader.go index 3737e8e..55afa27 100644 --- a/reader.go +++ b/reader.go @@ -55,10 +55,7 @@ func NewXLSXReader(reader io.Reader, opts *trdsql.ReadOpts) (trdsql.Reader, erro } r := XLSXReader{} - skip := 0 - if cellY > 0 { - skip = cellY - 1 - } + skip := cellY if opts.InSkip > 0 { skip = opts.InSkip }