英文:
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]
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论