Golang excel 文件读取
Golang excel file reading
我正在使用 tealeg xlsx 库读取 excel 文件 https://github.com/tealeg/xlsx . They have documentation here https://godoc.org/github.com/tealeg/。如果我通过本地目录调用 OpenFile()
,它工作得很好,但我想使用类型为 multipart.Form
的 http.Request.FormFile()
return 对象。我如何使用这个文件让 tealeg 包读取?
Tealeg 的 OpenReaderAt()
看起来像我应该使用的东西,但是是多部分的。表单对象 return 来自 http.Request.FormFile()
return 的文件接口,但我不确定如何访问 readerAt 对象? https://golang.org/pkg/mime/multipart/#File
func OpenReaderAt(r io.ReaderAt, size int64) (*File, error)
xlsx.OpenReaderAt
采用 io.ReaderAt
接口,multipart.File
也实现了 io.ReaderAt
.
所以可以直接传给xlsx.OpenReaderAt
var (
file multipart.File
size int64
err error
)
file, _,err = req.FormFile("key")
// size = // Calculate size
xlsx.OpenReaderAt(file,size)
我正在使用 tealeg xlsx 库读取 excel 文件 https://github.com/tealeg/xlsx . They have documentation here https://godoc.org/github.com/tealeg/。如果我通过本地目录调用 OpenFile()
,它工作得很好,但我想使用类型为 multipart.Form
的 http.Request.FormFile()
return 对象。我如何使用这个文件让 tealeg 包读取?
Tealeg 的 OpenReaderAt()
看起来像我应该使用的东西,但是是多部分的。表单对象 return 来自 http.Request.FormFile()
return 的文件接口,但我不确定如何访问 readerAt 对象? https://golang.org/pkg/mime/multipart/#File
func OpenReaderAt(r io.ReaderAt, size int64) (*File, error)
xlsx.OpenReaderAt
采用 io.ReaderAt
接口,multipart.File
也实现了 io.ReaderAt
.
所以可以直接传给xlsx.OpenReaderAt
var (
file multipart.File
size int64
err error
)
file, _,err = req.FormFile("key")
// size = // Calculate size
xlsx.OpenReaderAt(file,size)