Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generated corrupted Excel file on go1.21.5, excelize v2.8.1 #1925

Closed
MeTuA opened this issue Jun 17, 2024 · 3 comments
Closed

Generated corrupted Excel file on go1.21.5, excelize v2.8.1 #1925

MeTuA opened this issue Jun 17, 2024 · 3 comments

Comments

@MeTuA
Copy link

MeTuA commented Jun 17, 2024

Description
Hello, I am having a corruption error while generating an Excel file. Using go version 1.21.5, excelize v2.8.1.
It looks like a duplicate, but I couldn't find an issue with the go 1.21.5 version.

Steps to reproduce the issue:

func Export(ctx context.Context) (*excelize.File, error) {
	sheetName := "Sheet1"

	f := excelize.NewFile()

	err = drawTableHeaders(ctx, f, sheetName)
	if err != nil {
		return nil, err
	}

	err = drawTableBody(ctx, f, sheetName)
	if err != nil {
		return nil, err
	}

	limit := 5
	tableRange := fmt.Sprintf("A1:N%d", limit)
	disable := false
	err = f.AddTable(sheetName, &excelize.Table{
		Range:             tableRange,
		Name:              "table",
		StyleName:         "TableStyleMedium2",
		ShowFirstColumn:   true,
		ShowLastColumn:    true,
		ShowRowStripes:    &disable,
		ShowColumnStripes: true,
	})
	if err != nil {
		return nil, err
	}

	f.SetColWidth(sheetName, "A", "L", 17)
	f.SetColWidth(sheetName, "M", "N", 20)

	return f, nil
}

then

func ExportController(c *gin.Context) (interface{}, error) {
	...

	f, err := Export(c.Request.Context())
	if err != nil {
		return nil, errors.Ctx().Just(err)
	}
	defer f.Close()

	c.Header("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
	c.Header("Content-Disposition", "attachment; filename=data.xlsx")
	c.Header("Content-Transfer-Encoding", "binary")
	c.Header("Expires", "0")

	if err := f.Write(c.Writer); err != nil {
		c.String(http.StatusInternalServerError, err.Error())
	}

	return nil, nil
}

Describe the results you received:
image

Describe the results you expected:
Opening without error
Output of go version:
1.21.5

Excelize version or commit ID:
v2.8.1

Environment details (OS, Microsoft Excel™ version, physical, etc.):
Windows 11, Microsoft® Excel® for Microsoft 365 MSO (Version 2405 Build 16.0.17628.20006) 64-bit

@MeTuA MeTuA changed the title Corrupted file on go1.21.5, excelize v2.8.1 Generated corrupted Excel file on go1.21.5, excelize v2.8.1 Jun 17, 2024
@MeTuA
Copy link
Author

MeTuA commented Jun 17, 2024

Problem was on another part

@MeTuA MeTuA closed this as completed Jun 17, 2024
@tjalp
Copy link

tjalp commented Jun 18, 2024

Problem was on another part

I'm having the same issue. What did you do to fix it?

@xuri
Copy link
Member

xuri commented Jul 3, 2024

@tjalp, the workbook maybe corrupted caused by many different reasons, please provide more details or create issue to show us a reproducible demo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants