接上期:Go语言学习(13)读取excel表格之err处理

func TextEdit_click(a *walk.TextEdit) { oldtime := time.Now() // 当前时间 a.AppendText("欢迎关注“探索3000”nn") f, err := excelize.OpenFile("测试工作簿1.xlsx") if err != nil { fmt.Println(err) return } a.SetTextColor(walk.RGB(byte(255), byte(48), byte(48))) var sheetlist = f.GetSheetList() // 获取工作表中一整列 i := 2 //从第2行读取 var str1 string var total, total2 int col := "A" sht := sheetlist[0] for true { cell, _ := f.GetCellValue(sht, mycolstr(col, 0)+Itoa(i)) if cell == "" { break } cellB, _ := f.GetCellValue(sht, mycolstr(col, 1)+Itoa(i)) cellC, _ := f.GetCellValue(sht, mycolstr(col, 2)+Itoa(i)) cellD, _ := f.GetCellValue(sht, mycolstr(col, 3)+Itoa(i)) if i > 2 { total = Atoi(cellC) * Atoi(cellD) total2 = total2 + total } //写入单元格 f.SetCellInt(sht, mycolstr(col, 5)+Itoa(i), total) f.SetCellInt(sht, mycolstr(col, 6)+Itoa(i), total2) str1 = fmt.Sprintf("%vt %vt %vt %vt %vt 累计%vn", cell, cellB, cellC, cellD, total, total2) a.AppendText(str1 + "n") i++ } f.Save() a.AppendText(fmt.Sprintf("汇总金额总和是%vnn", total2)) a.AppendText(fmt.Sprintf("用时:%v nn", time.Since(oldtime))) }