Original post


I have a use case where I need to read an excel and process it , which will be uploaded by the user.

I am using github.com/360EntSecGroup-Skylar/excelize this package to read the excel , the problem here is that to reach value of each cell I need to read the row as array and cell with the index , this will hardly bind the column sequence and will fail if the sequence is changed, I was thinking is there a way to read excel directly to a struct.

I found this https://github.com/szyhf/go-excel , but the issue here is it requires the file path to open it,

I receive the file in request which is *multipart.FileHeader format , here for this I need to first create a file and save it somewhere and then process it .

The other thing I tried was to convert the file into bytes and then write it to struct, this also doesn’t seems to work

inputFile, err := c.FormFile("file")
file, fileErr := inputFile.Open()
if fileErr != nil {
return c.JSON(http.StatusBadRequest, fileErr)
byteContainer, err := ioutil.ReadAll(file)
var excelStruct []ExcelStruct
json.Unmarshal(byteContainer, &excelStruct)

is there any other way where I can convert multipart.FileHeader into struct .