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

Opening a file and saving it corrupts the file #1666

Closed
abdelaziz-ouhammou opened this issue Sep 20, 2023 · 7 comments
Closed

Opening a file and saving it corrupts the file #1666

abdelaziz-ouhammou opened this issue Sep 20, 2023 · 7 comments
Labels
bug Something isn't working

Comments

@abdelaziz-ouhammou
Copy link
Contributor

abdelaziz-ouhammou commented Sep 20, 2023

Excelize version : 2.8.0

the following code corrupts the file:

f, err := excelize.OpenFile("report.xlsx", excelize.Options{})
	if err != nil {
		fmt.Println(err)
		return
	}
	defer func() {
		if err := f.Close(); err != nil {
			fmt.Println(err)
		}
	}()
	f.Save()

The issue is not there in Excelize 2.7.0

I unzipped the before and after files and did a comparison on them.

These are the changes in "xl\styles.xml" that cause the file to be corrupted.

<!-- Before -->
<numFmts count="5">
    <numFmt numFmtId="43" formatCode="_(* #,##0.00_);_(* \(#,##0.00\);_(* &quot;-&quot;??_);_(@_)" />
    <numFmt numFmtId="164" formatCode="_-* #,##0.00_-;\-* #,##0.00_-;_-* &quot;-&quot;??_-;_-@_-" />
    <numFmt numFmtId="167" formatCode="[$-409]d\-mmm\-yyyy;@" />
    <numFmt numFmtId="169" formatCode="[$-809]dd\ mmm\ yyyy;@" />
    <numFmt numFmtId="170" formatCode="_(* #,##0_);_(* \(#,##0\);_(* &quot;-&quot;??_);_(@_)" />
</numFmts>
<!-- After -->
<numFmts count="5">
    <numFmt numFmtId="43" formatCode="_(* #,##0.00_);_(* \(#,##0.00\);_(* &#34;-&#34;??_);_(@_)"></numFmt>
    <numFmt numFmtId="164" formatCode="_-* #,##0.00_-;\-* #,##0.00_-;_-* &#34;-&#34;??_-;_-@_-"></numFmt>
    <numFmt numFmtId="167" formatCode="[$-409]d\-mmm\-yyyy;@"></numFmt>
    <numFmt numFmtId="169" formatCode="[$-809]dd\ mmm\ yyyy;@"></numFmt>
    <numFmt numFmtId="170" formatCode="_(* #,##0_);_(* \(#,##0\);_(* &#34;-&#34;??_);_(@_)"></numFmt>
</numFmts>
<!-- Before -->
 <colors>
        <mruColors>
            <color rgb="FFFDFDFD" />
            <color rgb="FFFFFFFF" />
            <color rgb="FFFFFFF0" />
            <color rgb="FFFFFFF1" />
            <color rgb="FF385723" />
            <color rgb="FF7030A0" />
            <color rgb="FFFF0000" />
            <color rgb="FF4472C4" />
            <color rgb="FFBCE292" />
            <color rgb="FFFAFDB5" />
        </mruColors>
    </colors>
<!-- After-->
 <colors>
          <indexedColors></indexedColors> <!-- This line -->
          <mruColors>
              <color rgb="FFFDFDFD" />
              <color rgb="FFFFFFFF" />
              <color rgb="FFFFFFF0" />
              <color rgb="FFFFFFF1" />
              <color rgb="FF385723" />
              <color rgb="FF7030A0" />
              <color rgb="FFFF0000" />
              <color rgb="FF4472C4" />
              <color rgb="FFBCE292" />
              <color rgb="FFFAFDB5" />
          </mruColors>
      </colors>

Manually reverting these changes and zipping the file fixes the issue.

@xuri
Copy link
Member

xuri commented Sep 20, 2023

Thanks for your issue. It seems this problem has been fixed in the master branch, please try to upgrade the master branch code. If still have this problem, please provide a workbook as attachments without confidential info.

@HerbertNatal
Copy link

I Tryed to start and executed your introduction:
image

getting the error:
image

It some dependecies to install?
my other machine at home works fine.

@HerbertNatal
Copy link

HerbertNatal commented Sep 20, 2023

Sorry my goenv:

go env

set GO111MODULE=on
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\Herbert\AppData\Local\go-build
set GOENV=C:\Users\Herbert\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\Herbert\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\Herbert\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:/Users/Herbert/scoop/apps/go/current
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLCHAIN=auto
set GOTOOLDIR=C:\Users\Herbert\scoop\apps\go\current\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.21.0
set GCCGO=gccgo
set GOAMD64=v1
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=C:\Users\Herbert\GolandProjects\exceltest\go.mod
set GOWORK=
set CGO_CFLAGS=-O2 -g
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-O2 -g
set CGO_FFLAGS=-O2 -g
set CGO_LDFLAGS=-O2 -g
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=C:\Users\Herbert\AppData\Local\Temp\go-build574737849=/tmp/go-build -gno-record-gcc-switches

@HerbertNatal
Copy link

image
error:

Parte Reparada: Parte de /xl/worksheets/sheet1.xml com erro XML.  Falha catastrófica Linha 2, coluna 419.
Parte Reparada: Parte de /xl/worksheets/sheet2.xml com erro XML.  Falha catastrófica Linha 2, coluna 302.

@xuri
Copy link
Member

xuri commented Sep 20, 2023

Hi @HerbertNatal, thanks for your feedback. If it does not work with Go 1.21.0, please reference the issues #1465, #1595, #1603, #1608, #1614, #1619, #1620, #1621, #1623, #1633, #1637, #1641, #1642, #1648, #1651, #1652, #1656, #1657, #1660 and #1663. There are some incompatible changes in the Go 1.21.0 encoding/xml library. I have given feedback to the Go team and created a patch for it (golang/go#61881), and it has been fixed on Go 1.21.1. Please using the Go 1.20.7 and previous Go released version or upgrade to Go 1.21.1 and later. I have already added notice on the README and documentation website for this.

@abdelaziz-ouhammou
Copy link
Contributor Author

abdelaziz-ouhammou commented Sep 20, 2023

@HerbertNatal Please upgrade to GO 1.21.1 since @xuri already mentioned that 1.20.0 has an issue with xml encoding.

also please install excelize librabry this way in your project:

go get github.com/xuri/excelize/v2@744236b4b840d71cff471e45f8641d0a682d0292

@HerbertNatal
Copy link

Hi @HerbertNatal, thanks for your feedback. If it does not work with Go 1.21.0, please reference the issues #1465, #1595, #1603, #1608, #1614, #1619, #1620, #1621, #1623, #1633, #1637, #1641, #1642, #1648, #1651, #1652, #1656, #1657, #1660 and #1663. There are some incompatible changes in the Go 1.21.0 encoding/xml library. I have given feedback to the Go team and created a patch for it (golang/go#61881), and it has been fixed on Go 1.21.1. Please using the Go 1.20.7 and previous Go released version or upgrade to Go 1.21.1 and later. I have already added notice on the README and documentation website for this.

Thank you Xuri, it was version 1.21.0...
the version 1.21.1 its working.
you're awesome

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants