Closed shadyabhi closed 7 years ago
Excel Sheet: Google Drive link for the excel sheet
Sample code which is panicing due to nil value.
nil
➜ $?=0 /tmp [ 8:37AM] % cat main.go package main import "fmt" import "github.com/extrame/xls" func main() { if xlFile, err := xls.Open("expenses.xls", "utf-8"); err == nil { if sheet1 := xlFile.GetSheet(0); sheet1 != nil { fmt.Print("Total Lines ", sheet1.MaxRow, sheet1.Name) col1 := sheet1.Rows[0].Cols[0] col2 := sheet1.Rows[0].Cols[0] for i := 0; i <= (int(sheet1.MaxRow)); i++ { row1 := sheet1.Rows[uint16(i)] col1 = row1.Cols[0] col2 = row1.Cols[1] fmt.Print("\n", col1.String(xlFile), ",", col2.String(xlFile)) } } } } >>> 0s elasped... ➜ $?=0 /tmp [ 8:37AM] % go run main.go Total Lines 1Transactions [Sr. No. ],[Date]panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x30 pc=0x243d] goroutine 1 [running]: panic(0xb96e0, 0xc42000a110) /usr/local/Cellar/go/1.7.3/libexec/src/runtime/panic.go:500 +0x1a1 main.main() /tmp/main.go:16 +0x3fd exit status 2 >>> 0s elasped... ➜ $?=1 /tmp [ 8:37AM] %
It should be fixed
Excel Sheet: Google Drive link for the excel sheet
Sample code which is panicing due to
nil
value.