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

excelize.File does not implement io.WriterTo #1901

Open
fightlight opened this issue May 20, 2024 · 2 comments
Open

excelize.File does not implement io.WriterTo #1901

fightlight opened this issue May 20, 2024 · 2 comments

Comments

@fightlight
Copy link

fightlight commented May 20, 2024

Description

Hi! I'm migrating one of our projects from excelize v2.4.0 to v2.8.1 and can I not compile code:

cannot use xlsx (variable of type *excelize.File) as io.WriterTo value in return statement: *excelize.File does not implement io.WriterTo (wrong type for method WriteTo)
                have WriteTo(io.Writer, ...excelize.Options) (int64, error)
                want WriteTo(io.Writer) (int64, error)

I made a workaround returning *excelize.File instead of io.WriterTo, but anyway the issue (or the go doc comment) should be fixed, I think :)

Steps to reproduce the issue:

  1. Create a method returning excelize.NewFile()
  2. Make the return type as io.WriterTo
  3. go build

Describe the results you received:
Code doesn't compile.

Describe the results you expected:
Code compiles.

Output of go version:

go version go1.22.2 darwin/amd64

Excelize version or commit ID:

v2.8.1

Environment details (OS, Microsoft Excel™ version, physical, etc.):
MacOS Ventura 13.6.6

@dolmen
Copy link
Contributor

dolmen commented May 20, 2024

It is very unfortunate that fb1aab7 broke compatibilty with io.WriterTo (I was the one who introduced it in 2132de1) since v2.7.0.

However, at that point restoring the compatibility would be another another breaking change. So I don't think this is fixable. Except the documentation, of course.

@dolmen
Copy link
Contributor

dolmen commented May 20, 2024

Note that, as a workaround, it is easy to write your own wrapper to somewhat restore that compatibility:

type myExcelizeFile = excelize.File

type myExcelizeWriterTo struct {
    *myExcelizeFile
}

func (f myExcelizeWriterTo) WriteTo(w io.Writer) (int64, error) {
    return f.myExcelizeFile.WriteTo(w)
}

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

2 participants