Excel golang Function中如何返回结构副本
我需要从函数中重新运行struct duitory,当它运行脚本时,我无法在返回参数中使用res(type[]exceldata)作为type[]struct{} 我已经在我的go脚本中创建了struct,我添加了值并添加到数组中,现在我需要将它返回到主函数Excel golang Function中如何返回结构副本,excel,go,Excel,Go,我需要从函数中重新运行struct duitory,当它运行脚本时,我无法在返回参数中使用res(type[]exceldata)作为type[]struct{} 我已经在我的go脚本中创建了struct,我添加了值并添加到数组中,现在我需要将它返回到主函数 包干管 进口( “fmt” “数据库/sql” _“github.com/go-sql-driver/mysql” “github.com/360EntSecGroup Skylar/excelize” “日志” ) 类型exceldat
包干管
进口(
“fmt”
“数据库/sql”
_“github.com/go-sql-driver/mysql”
“github.com/360EntSecGroup Skylar/excelize”
“日志”
)
类型exceldata结构{
用户名字符串
射频识别字符串
用户字符串
}
func read()[]结构{}{
exdata:=exceldata{}
res:=[]exceldata{}
f、 错误:=excelize.OpenFile(“./required_details.xlsx”)
如果错误!=零{
fmt.Println(错误)
返回res
}
//通过给定的工作表名称和轴从单元格中获取值。
/*单元格,错误:=f.GetCellValue(“Sheet1”、“A566”)
如果错误!=零{
fmt.Println(错误)
回来
}
fmt.Println(单元)*/
//获取表1中的所有行。
行,err:=f.GetRows(“Sheet1”)
对于u,行:=范围行{
如果第[0]行!=“eof”{
exdata.username=行[0]
exdata.rfid=行[1]
exdata.user=行[2]
res=追加(res,exdata)
fmt.Println(res)
}否则{
返回res
}
}
返回res;
}
func main(){
fmt.Println(“Go MySQL教程”)
resexceldata:=[]exceldata{}
resexceldata=read()
fmt.Println(“路线被占用”)
}
您已经将exceldata定义为一种类型,因此应使用该类型:
type exceldata struct
...
func read() []exceldata {
...
}
func read()[]exceldata
exceldata
是一种结构类型,但它不是struct{}
(匿名空结构)类型。