Skip to content

Commit b635fc4

Browse files
committed
added some error handling options to xlsx2csv
1 parent 017f3c5 commit b635fc4

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

cmds/xlsx2csv/xlsx2csv.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ Putting it all together in a shell script.
7676
// Application Options
7777
showSheetCount bool
7878
showSheetNames bool
79+
verbose bool
80+
permissive bool
7981
)
8082

8183
func sheetCount(workBookName string) (int, error) {
@@ -106,14 +108,23 @@ func xlsx2CSV(out io.Writer, workBookName, sheetName string) error {
106108
results := [][]string{}
107109
cells := []string{}
108110
if sheet, ok := xlFile.Sheet[sheetName]; ok == true {
109-
for _, row := range sheet.Rows {
111+
for i, row := range sheet.Rows {
112+
//FIXME: I would be nice to optionally only the columns you wanted to output from the sheet...
110113
cells = []string{}
111-
for _, cell := range row.Cells {
114+
for j, cell := range row.Cells {
112115
val, err := cell.String()
113116
if err != nil {
114-
//val = fmt.Sprintf("%s", err)
117+
if permissive == true {
118+
cells = append(cells, fmt.Sprintf("%s", val))
119+
} else {
120+
cells = append(cells, fmt.Sprintf("%s", err))
121+
}
122+
if verbose == true {
123+
fmt.Fprintf(os.Stderr, "row %d, col %d %s\n", i, j, err)
124+
}
125+
} else {
126+
cells = append(cells, val)
115127
}
116-
cells = append(cells, val)
117128
}
118129
results = append(results, cells)
119130
}
@@ -145,6 +156,8 @@ func init() {
145156
// App Specific Options
146157
flag.BoolVar(&showSheetCount, "c", false, "display number of sheets in Excel Workbook")
147158
flag.BoolVar(&showSheetNames, "n", false, "display sheet names in Excel W9rkbook")
159+
flag.BoolVar(&verbose, "verbose", false, "output cell level errors")
160+
flag.BoolVar(&verbose, "permissive", false, "ignore cell level errors")
148161
}
149162

150163
func main() {

0 commit comments

Comments
 (0)