Closed RalfMetzingLeik closed 3 months ago
Thanks for your issue. This is similar to the issues #634, #1195 and #1808. Please try to use UpdateLinkedValue
to clean up the cell calculation cache value before saving the spreadsheet. In addition, you needn't create a new workbook if just save it as the new workbook, the code can be simply like this:
package main
import (
"fmt"
"github.com/xuri/excelize/v2"
)
func main() {
- f := excelize.NewFile()
- defer func() {
- if err := f.Close(); err != nil {
- fmt.Println(err)
- }
- }()
-
// Test Change Data on existing complex excel-file
f, err := excelize.OpenFile("Input1.xlsx")
if err != nil {
fmt.Println(err)
}
defer f.Close()
sheet1 := f.GetSheetName(0)
sheet2 := f.GetSheetName(1)
f.SetCellStr(sheet1, "G1", "test_ralf")
f.SetCellFloat(sheet2, "E7", 1234567.89, 2, 32)
+ if err = f.UpdateLinkedValue(); err != nil {
+ fmt.Println(err)
+ return
+ }
f.SaveAs("Output1.xlsx")
}
Thanks a lot, this solves the problem!
Just out of curiosity, what is the reason that the file is about 10% smaller after the "saveAs"?
The workbook file with the XLSX extension is a zipped, XML-based file format, and the size of the zipped folder (compression implementations by Go archive/zip package) by this library was different from the Office app.
Thank you very much for the quick and detailed explanation.
You're welcome. Please close the issue if this problem has been resolved.
Description
I've a program to modify an existing Excel file, which changes the number in on cell (source code and Excel file appended in Zip) Another sheet refers to this cell. After modifying the file with excelize (V2.8.1) and saving, then opening in Excel (Microsoft® Excel® für Microsoft 365 MSO (Version 2402 Build 16.0.17328.20124) 64 Bit ). Now the changed value ist changed in the cell, which is changed with excelize, but ist is not changed in the refering cell.
If I run the same with previous excelize (2.8.0), then i get a message on opening with excel, which says, that Excel found problems with the file and tries to fix. With V2.8.1. no message is shown. I think that the fixes in 2.8.1 do not fix all issues on the problem.
Another thing is, that the file size of the file saved by excelize ist about 10% less(!) than the original file on both versions (2.8.0 and 2.8.1)
Steps to reproduce the issue:
Describe the results you received: Cell "Auswertung!D13" is not updated/recalculated by Excel after opening "Output1.xlsx"
Describe the results you expected: Cell "Auswertung!D13" should show the value of "Rohdaten!E7" like in "Input1.xlsx"
Output of
go version
:Excelize version or commit ID:
Environment details (OS, Microsoft Excel™ version, excelize-test.zip physical, etc.): Windows 11 Enterprise (V 22H2) running on virtual machine Microsoft® Excel® für Microsoft 365 MSO (Version 2402 Build 16.0.17328.20124) 64 Bit