如何随心所欲地发送REST响应Excel文件?

I'm trying to send in response excel file, but in it I get binary data. If try use reponse data as xlsx file, Excel show that it is corrupted. However if save it locally, everything is fine. For create xlsx file I'm using tealeg/xlsx. What am I doing wrong?

Go:

file := xlsx.NewFile()
...
// filling file with data
...
// works fine
err = file.Save("asd.xlsx")
if err != nil {
    fmt.Printf(err.Error())
}
// something went wrong
buffer := new(bytes.Buffer)
if err := file.Write(buffer); err != nil {
    return nil, err
}
r := bytes.NewReader(buffer.Bytes())
cr := ioutil.NopCloser(r)

Swagger:

get:
      tags:
        - "Report"
      summary: ""
      description: ""
      consumes:
        - "application/json"
      produces:
        - "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
      responses:
        200:
          description: ""
          schema:
            type: file

You need to add Content-Type header before writing the xlsx payload over http.

    r.Header.Set("Content-Type","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")