Skip to content

Commit

Permalink
Also consider cellname as y
Browse files Browse the repository at this point in the history
  • Loading branch information
noborus committed Nov 20, 2023
1 parent c9c8a92 commit 6fa9402
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func NewXLSXReader(reader io.Reader, opts *trdsql.ReadOpts) (trdsql.Reader, erro
}
isFilter = true
cellX--
cellY--
}

rows, err := f.GetRows(sheet)
Expand Down Expand Up @@ -87,15 +88,15 @@ 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)
for i := 0; i < len(r.names); i++ {
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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -195,15 +196,15 @@ 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)
c := 0
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 {
Expand Down

0 comments on commit 6fa9402

Please sign in to comment.