From e820388d70da551cacdf3212b559d597a6fdbec8 Mon Sep 17 00:00:00 2001 From: Ri Xu Date: Tue, 19 Sep 2017 11:59:33 +0800 Subject: Handle coordinate parse exception, relate issue #122. --- cell.go | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) (limited to 'cell.go') diff --git a/cell.go b/cell.go index d0f747a..af98cf0 100644 --- a/cell.go +++ b/cell.go @@ -76,7 +76,10 @@ func (f *File) SetCellValue(sheet, axis string, value interface{}) { func (f *File) GetCellValue(sheet, axis string) string { xlsx := f.workSheetReader(sheet) axis = f.mergeCellsParser(xlsx, axis) - row, _ := strconv.Atoi(strings.Map(intOnlyMapF, axis)) + row, err := strconv.Atoi(strings.Map(intOnlyMapF, axis)) + if err != nil { + return "" + } xAxis := row - 1 rows := len(xlsx.SheetData.Row) if rows > 1 { @@ -124,7 +127,10 @@ func (f *File) GetCellStyle(sheet, axis string) int { xlsx := f.workSheetReader(sheet) axis = f.mergeCellsParser(xlsx, axis) col := string(strings.Map(letterOnlyMapF, axis)) - row, _ := strconv.Atoi(strings.Map(intOnlyMapF, axis)) + row, err := strconv.Atoi(strings.Map(intOnlyMapF, axis)) + if err != nil { + return 0 + } xAxis := row - 1 yAxis := TitleToNumber(col) @@ -142,7 +148,10 @@ func (f *File) GetCellStyle(sheet, axis string) int { func (f *File) GetCellFormula(sheet, axis string) string { xlsx := f.workSheetReader(sheet) axis = f.mergeCellsParser(xlsx, axis) - row, _ := strconv.Atoi(strings.Map(intOnlyMapF, axis)) + row, err := strconv.Atoi(strings.Map(intOnlyMapF, axis)) + if err != nil { + return "" + } xAxis := row - 1 rows := len(xlsx.SheetData.Row) if rows > 1 { @@ -176,7 +185,10 @@ func (f *File) SetCellFormula(sheet, axis, formula string) { xlsx := f.workSheetReader(sheet) axis = f.mergeCellsParser(xlsx, axis) col := string(strings.Map(letterOnlyMapF, axis)) - row, _ := strconv.Atoi(strings.Map(intOnlyMapF, axis)) + row, err := strconv.Atoi(strings.Map(intOnlyMapF, axis)) + if err != nil { + return + } xAxis := row - 1 yAxis := TitleToNumber(col) @@ -326,7 +338,10 @@ func (f *File) SetCellInt(sheet, axis string, value int) { xlsx := f.workSheetReader(sheet) axis = f.mergeCellsParser(xlsx, axis) col := string(strings.Map(letterOnlyMapF, axis)) - row, _ := strconv.Atoi(strings.Map(intOnlyMapF, axis)) + row, err := strconv.Atoi(strings.Map(intOnlyMapF, axis)) + if err != nil { + return + } xAxis := row - 1 yAxis := TitleToNumber(col) @@ -363,7 +378,10 @@ func (f *File) SetCellStr(sheet, axis, value string) { value = value[0:32767] } col := string(strings.Map(letterOnlyMapF, axis)) - row, _ := strconv.Atoi(strings.Map(intOnlyMapF, axis)) + row, err := strconv.Atoi(strings.Map(intOnlyMapF, axis)) + if err != nil { + return + } xAxis := row - 1 yAxis := TitleToNumber(col) @@ -393,7 +411,10 @@ func (f *File) SetCellDefault(sheet, axis, value string) { xlsx := f.workSheetReader(sheet) axis = f.mergeCellsParser(xlsx, axis) col := string(strings.Map(letterOnlyMapF, axis)) - row, _ := strconv.Atoi(strings.Map(intOnlyMapF, axis)) + row, err := strconv.Atoi(strings.Map(intOnlyMapF, axis)) + if err != nil { + return + } xAxis := row - 1 yAxis := TitleToNumber(col) -- cgit v1.2.1