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

Output file error after formula manipulation #346

Closed
ArmandoZepeda opened this issue Feb 21, 2019 · 2 comments
Closed

Output file error after formula manipulation #346

ArmandoZepeda opened this issue Feb 21, 2019 · 2 comments
Labels
confirmed This issue can be reproduced

Comments

@ArmandoZepeda
Copy link

ArmandoZepeda commented Feb 21, 2019

Thank you for your work on excelize. This is a really helpful and flexible tool.

I found an issue when an existing formula on the input file is deleted from the cell or moved down when new rows are added.
The error messages are the same to #152

Scenario description

Input file structure

  • Rows at beginning acting as sheet header.
  • Data section that I need to populate with new rows.
  • Cells at bottom with formulas that I need to "rebuild"(update vertical range) after previous step is done.
    It would be so helpful if some day this rebuild could be automatic(like Microsoft Excel editor does)

Excelize steps
To apply final formulas result, I need to perform the following:

  1. Scan the whole sheet and find cells with formulas.
  2. Backup sheet formulas info.
  3. Populate sheet with new rows.
  4. Put back the formulas, with the new range calculation.

Issue

Input file info:

  • Name: HistoryTemplate.xlsx
  • Number values from "E9" to "E12"
  • Formula at "E14": SUM(E9:E12)
  1. Formula deletion:
    xlsx, _ := excelize.OpenFile("./HistoryTemplate.xlsx")
    sheetName := "Paros"
    xlsx.SetCellFormula(sheetName, "E14", "")
    xlsx.SaveAs("./output1.xlsx")

  2. Formula moved down:
    xlsx, _ := excelize.OpenFile("./HistoryTemplate.xlsx")
    sheetName := "Paros"
    xlsx.DuplicateRowTo(sheetName, 10, 11)
    xlsx.SaveAs("./output2.xlsx")

Error message to open output file:
"Removed Records: Formula from /xl/calcChain.xml part (Calculation properties)"

Files:

HistoryTemplate.xlsx
output1.xlsx
output2.xlsx

go env:
set GOARCH=amd64 set GOBIN= set GOCACHE=C:\Users\Mind\AppData\Local\go-build set GOEXE=.exe set GOHOSTARCH=amd64 set GOHOSTOS=windows set GOOS=windows set GOPATH=C:\GO_Projects set GORACE= set GOROOT=C:\Go set GOTMPDIR= set GOTOOLDIR=C:\Go\pkg\tool\windows_amd64 set GCCGO=gccgo set CC=gcc set CXX=g++ set CGO_ENABLED=1 set CGO_CFLAGS=-g -O2 set CGO_CPPFLAGS= set CGO_CXXFLAGS=-g -O2 set CGO_FFLAGS=-g -O2 set CGO_LDFLAGS=-g -O2 set PKG_CONFIG=pkg-config set GOGCCFLAGS=-m64 -mthreads -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=C:\Users\Mind\AppData\Local\Temp\go-build976948498=/tmp/go-build -gno-record-gcc-switches

@xuri xuri added confirmed This issue can be reproduced in progress Working in progress labels Feb 22, 2019
@xuri
Copy link
Member

xuri commented Feb 22, 2019

Hi @ArmandoZepeda, thanks for your issue. I have fixed the issue corrupted xlsx after deleting formula of cell.

However, when using DuplicateRow and DuplicateRowTo, it is still possible to cause file corruption. I have noted this potential problem in the documentation for these two functions.

Since that which will affect changes in references such as formulas, charts, and so on. If there is any referenced value of the worksheet, it will cause a file error when you open it. The excelize only partially updates these references currently.

I think that solving this problem requires the completion of the function adjustHelper. I'll certainly accept that patch if somebody did that.

@xuri xuri removed the in progress Working in progress label Feb 22, 2019
@ArmandoZepeda
Copy link
Author

Thanks for your fixing.
I know that DuplicateRow and DuplicateRowTo implies hard work.

Now the output file has no errors when formula is removed from cell.
Right now, this is enough for me.

@xuri xuri closed this as completed Mar 29, 2019
nullfy pushed a commit to nullfy/excelize that referenced this issue Oct 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed This issue can be reproduced
Projects
None yet
Development

No branches or pull requests

2 participants