-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added filter for when row is blank #5
Changes from 3 commits
9c7ed9a
d70b707
7b53ac3
dba3850
33f27f6
1c89ea3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -95,7 +95,7 @@ func NewXLSXReader(reader io.Reader, opts *trdsql.ReadOpts) (trdsql.Reader, erro | |||||||||||||||||||||||||||
if r.names[i] != "" { | ||||||||||||||||||||||||||||
validColumns[i] = true | ||||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||||
r.names[i] = fmt.Sprintf("C%d", i+1) | ||||||||||||||||||||||||||||
r.names[i] = cellName(i) | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
for j, row := range rows { | ||||||||||||||||||||||||||||
|
@@ -109,6 +109,9 @@ func NewXLSXReader(reader io.Reader, opts *trdsql.ReadOpts) (trdsql.Reader, erro | |||||||||||||||||||||||||||
validColumns[c] = true | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
c++ | ||||||||||||||||||||||||||||
if len(data) <= c { | ||||||||||||||||||||||||||||
break | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
body = append(body, data) | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
|
@@ -124,7 +127,15 @@ func NewXLSXReader(reader io.Reader, opts *trdsql.ReadOpts) (trdsql.Reader, erro | |||||||||||||||||||||||||||
return r, nil | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
func filterColumns(body [][]interface{}, dataFlag []bool) [][]interface{} { | ||||||||||||||||||||||||||||
func cellName(i int) string { | ||||||||||||||||||||||||||||
cn, err := excelize.CoordinatesToCellName(i+1, 1) | ||||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||||
return fmt.Sprintf("C%d", i+1) | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
return cn | ||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The if err != nil {
- return fmt.Sprintf("C%d", i+1)
+ // Handle the error more appropriately, e.g., log it and propagate it up
+ return "", err
} Commitable suggestion
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. indeed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @noborus Acknowledged. I will update the func cellName(i int) (string, error) {
cn, err := excelize.CoordinatesToCellName(i+1, 1)
if err != nil {
// Log the error and propagate it up
return "", err
}
return cn, nil
} This change will require updating all calls to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thank you. I'll do it myself. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @noborus Understood. If you need any further assistance or have more requests in the future, feel free to reach out. Good luck with your implementation! |
||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
func filterColumns(src [][]interface{}, dataFlag []bool) [][]interface{} { | ||||||||||||||||||||||||||||
count := len(dataFlag) | ||||||||||||||||||||||||||||
start := false | ||||||||||||||||||||||||||||
for i, f := range dataFlag { | ||||||||||||||||||||||||||||
|
@@ -136,15 +147,22 @@ func filterColumns(body [][]interface{}, dataFlag []bool) [][]interface{} { | |||||||||||||||||||||||||||
break | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
newBody := make([][]interface{}, 0, len(body)) | ||||||||||||||||||||||||||||
for _, row := range body { | ||||||||||||||||||||||||||||
dst := make([][]interface{}, 0, len(src)) | ||||||||||||||||||||||||||||
for _, row := range src { | ||||||||||||||||||||||||||||
cols := make([]interface{}, count) | ||||||||||||||||||||||||||||
valid := false | ||||||||||||||||||||||||||||
for i := 0; i < count; i++ { | ||||||||||||||||||||||||||||
cols[i] = row[i] | ||||||||||||||||||||||||||||
if cols[i] != "" { | ||||||||||||||||||||||||||||
valid = true | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
if !valid { | ||||||||||||||||||||||||||||
break | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
newBody = append(newBody, cols) | ||||||||||||||||||||||||||||
dst = append(dst, cols) | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
return newBody | ||||||||||||||||||||||||||||
return dst | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
func parseExtend(ext string) (string, string) { | ||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The - if !valid {
- break
- } |
||||||||||||||||||||||||||||
|
@@ -166,7 +184,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 { | ||||||||||||||||||||||||||||
names[c] = fmt.Sprintf("C%d", i+1) | ||||||||||||||||||||||||||||
names[c] = cellName(i) | ||||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||||
nameMap[row[i]] = true | ||||||||||||||||||||||||||||
names[c] = row[i] | ||||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The loop termination condition seems incorrect. The loop should not break based on the length of
data
but rather should iterate over all the columns. The current condition could lead to missing columns ifcellX
is greater than 0.Commitable suggestion