excelize.File does not implement io.WriterTo
fightlight opened this issue · comments
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:
- Create a method returning
excelize.NewFile()
- Make the return type as
io.WriterTo
- 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
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.
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)
}