Closed
Description
The version of tealeg/xlsx is v3.3.4, and the v1 also has the same problem.
The returned excel file from backend service api and download through browser, then open it and the Microsoft Excel will thorw a warning message:
We found a problem with some content in xxx.xslx. Do you want us to try to revocer as much as we can? If you trust the source of this workbook, click Yes.
If I click yes, the excel file will be repaired successfully and can be opened.
My backend service use Gin framework and the summary code to generate excel file and return it to browser as bellow:
func ExportHandler(c *gin.Context) {
file := xlsx.NewFile()
sheet, _ := file.AddSheet("InsuranceActive")
// Add titles.
titles := []string{
"Id",
"CreatedAt",
"UpdatedAt",
"CreatorId",
"UpdaterId",
"CompanyName",
}
row := sheet.AddRow()
for _, title := range titles {
cell := row.AddCell()
cell.Value = title
}
// Add rows
...
// Return the excel file.
c.Header("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
filename := fmt.Sprintf("IndustryInfos_%v.xlsx", time.Now().Format("2006-01-02T15:04:05"))
c.Header("Content-Disposition", "attachment; filename="+filename)
if err := file.Write(c.Writer); err != nil {
c.JSON(http.StatusOK, "failed")
return
}
c.JSON(http.StatusOK, "suceess")
}
Metadata
Assignees
Labels
No labels
Activity