Golang Excel文件读取
I'm using tealeg xlsx library to read an excel file https://github.com/tealeg/xlsx . They have documentation here https://godoc.org/github.com/tealeg/ . It works perfectly fine if I call the OpenFile()
by local directory, but I wanted to use an http.Request.FormFile()
return object which is of type multipart.Form
. How do I use this file to be read by the tealeg package?
Tealeg's OpenReaderAt()
looks like something I should use, but the multipart. Form object returned from http.Request.FormFile()
returns a file interface but I'm not sure how to access the readerAt object? https://golang.org/pkg/mime/multipart/#File
我正在使用tealeg xlsx库读取Excel文件 https://github.com/tealeg/xlsx 。 他们在 https://godoc.org/github.com/tealeg/ 中提供了文档。 如果我通过本地目录调用 Tealeg的 OpenFile() code>,它工作得很好,但是我想使用
http.Request.FormFile() code>返回对象,其类型为
multipart.Form 代码>。 我如何使用tealeg包读取此文件? p>
OpenReaderAt() code>看起来应该使用,但是要分多个部分。 从
http.Request.FormFile() code>返回的Form对象返回文件接口,但是我不确定如何访问readerAt对象? https://golang.org/pkg/mime/multipart/#File p>
div>
func OpenReaderAt(r io.ReaderAt, size int64) (*File, error)
xlsx.OpenReaderAt
takes in an io.ReaderAt
interface and multipart.File
also implements io.ReaderAt
.
So you can directly pass it to xlsx.OpenReaderAt
var (
file multipart.File
size int64
err error
)
file, _,err = req.FormFile("key")
// size = // Calculate size
xlsx.OpenReaderAt(file,size)