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

.xlsm file is getting corrupted after using writeTo() #2090

Open
2 tasks done
azju opened this issue Feb 13, 2025 · 0 comments
Open
2 tasks done

.xlsm file is getting corrupted after using writeTo() #2090

azju opened this issue Feb 13, 2025 · 0 comments

Comments

@azju
Copy link

azju commented Feb 13, 2025

Description

Hi there,

We are experiencing performance issues when using SaveAs() to save an .xlsm file with macros. To improve performance, we attempted to use WriteTo(), which successfully creates the file, but the resulting file is corrupted.

Just a few questions:

  • Is WriteTo() effective for improving performance when saving large files? If not, are there better alternatives?
  • Additionally, can WriteTo() handle .xlsm files with macros

Steps to reproduce the issue

  1. create an excel file
  2. add vbaProject.bin to the file
file, err := embeddedFile.ReadFile("vbaProject.bin")
	if err != nil {
		return nil, err
	}

	if err := f.AddVBAProject(file); err != nil {
		return nil, err
	}
  1. save file using writeTo()
file, err := os.Create("output.xlsm")
	if err != nil {
		fmt.Println("Failed to create file:", err)
		return "", err
	}
	defer file.Close()

	if _, err := sf.ExcelFile.WriteTo(file); err != nil {
		fmt.Println("Failed to write file:", err)
		return "", err
	}

	fmt.Println("File written `successfully")

Describe the results you received

Image

Describe the results you expected

I expect the file to be openable with macros, just like it is when using SaveAs().

Go version

go1.22.3

Excelize version or commit ID

2.9.0

Environment

linux/amd64

Validations

  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • The provided reproduction is a minimal reproducible example of the bug.
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

1 participant