How do I get the sheet's name using github.com/tealeg/xlsx?

huangapple go评论105阅读模式
英文:

How do I get the sheet's name using github.com/tealeg/xlsx?

问题

我正在使用github.com/tealeg/xlsx来读取XLSX文件。
它读取得很快,但我想按工作表名称读取。
有人知道如何做吗?

// 按工作表索引可以正常工作

xlFile,err := xlsx.OpenFile(xlsFile)

for _,sheet := range xlFile.Sheets {

 for _,row := range sheet.Rows {

 }

}
英文:

I am using github.com/tealeg/xlsx to read XLSX files.
It is read pretty fast, however I would like to read by Sheet Name.
Does anyone know how to do?

// by sheet index works fine

xlFile,err := xlsx.OpenFile(xlsFile)

for _,sheet := range xlFile.Sheets {

 for _,row := range sheet.Rows {

 }

}

答案1

得分: 4

只需使用xlsx.File中包含的Sheet映射,并通过键访问(键是您的工作表名称):

xlFile, err := xlsx.OpenFile(xlsFile)
// 检查错误

sheetName := "YourSheetName"
sheet := xlFile.Sheet[sheetName]
英文:

Just use the map Sheet contained in xlsx.File and access by key (the key is your sheet name):

xlFile, err := xlsx.OpenFile(xlsFile)
// check err

sheetName := "YourSheetName"
sheet := xlFile.Sheet[sheetName]

huangapple
  • 本文由 发表于 2014年5月8日 21:35:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/23543360.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定