tealeg / xlsx

Go library for reading and writing XLSX files.
Other
5.81k stars 808 forks source link

golang 1.21 incompatibility - Suddenly all my sheets are empty -- all projects #784

Closed givsly-stephen closed 3 months ago

givsly-stephen commented 9 months ago

UPDATE: Rolledback to golang 1.20.10 and it's all back -- Seems 1.21 is incompatible.

Went back to basics to make a simple HELLO WORLD and still empty. Baffled. Production runs on AWS, but now happening even on my mac.

import "github.com/tealeg/xlsx"

    xlsFile := xlsx.NewFile()
    sheet, err := xlsFile.AddSheet("Responses")
    if err != nil {
        log.Fatal(err)
    }

    rowName := sheet.AddRow()
    cellLabelName := rowName.AddCell()
    cellLabelName.Value = "Name"
    rowOfferName.AddCell().Value = "HELLO WORLD"

    err = xlsFile.Save("myfile.xlsx")
    if err != nil {
        log.Fatal(err)
    }

my go.mod

module lambda

go 1.21

require (
    github.com/aws/aws-lambda-go v1.41.0
    github.com/r3labs/diff/v3 v3.0.1
    github.com/stretchr/testify v1.8.4
    github.com/tealeg/xlsx v1.0.5
)

require (
    github.com/davecgh/go-spew v1.1.1 // indirect
    github.com/pmezard/go-difflib v1.0.0 // indirect
    github.com/vmihailenco/msgpack/v5 v5.4.0 // indirect
    github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
    gopkg.in/yaml.v3 v3.0.1 // indirect
)
tealeg commented 8 months ago

There are potential problems with legacy code and go1.2.1 around the use of init functions - I'm going to start looking there.

tealeg commented 8 months ago

Note that this is a problem of xlsx v1.0.5 not the v3 version.

tealeg commented 8 months ago

Another piece of information - I ran the code above (fixing the variable name rowOfferName to rowName), it compiled, ran and the output loaded fine in LibreOffice. I suspect that this is one of those occasions where Excel is extremely picky about the XML (it wants the XML exactly as it would write it, and won't accept it in any other logically valid form). I don't have Excel to hand, but if you send me the working and not-working xlsx files I can try and work out what changed between them. @givsly-stephen

tealeg commented 8 months ago

@givsly-stephen - if you're in fact using V3 you should try the latest release as I have recently fixed an issue with similar results. (See #786 )

givsly-stephen commented 8 months ago

Yes, I was using github.com/tealeg/xlsx v1.0.5 see my go.mod

OK - I will take a look at v3.

It's funny though it works perfectly with golang 1.20, but fails with 1.21 -- did golang break compatibility???

tealeg commented 8 months ago

Yeah, I did think so. Moving to V3 would require quite a lot of changes on your front, but it's likely to be better maintained going forward.

xiazemin commented 6 months ago

image

注释掉golang 源码里这几行就解决了

github-actions[bot] commented 4 months ago

Stale issue message