Go语言学习(14)excel表格数据汇总计算写入

Go语言学习(14)excel表格数据汇总计算写入

首页休闲益智Text or Walk更新时间:2024-04-29

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

func TextEdit_click(a *walk.TextEdit) { oldtime := time.Now() // 当前时间 a.AppendText("欢迎关注“探索3000”\n\n") 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("%v\t %v\t %v\t %v\t %v\t 累计%v\n", cell, cellB, cellC, cellD, total, total2) a.AppendText(str1 "\n") i } f.Save() a.AppendText(fmt.Sprintf("汇总金额总和是%v\n\n", total2)) a.AppendText(fmt.Sprintf("用时:%v \n\n", time.Since(oldtime))) }

查看全文
大家还看了
也许喜欢
更多游戏

Copyright © 2024 妖气游戏网 www.17u1u.com All Rights Reserved