mirror of
https://github.com/unidoc/unioffice.git
synced 2025-04-25 13:48:53 +08:00
spreadsheet: add method to clear cached formula results
This commit is contained in:
parent
f3eca9e68e
commit
9e6bfaf6e1
@ -505,3 +505,17 @@ func (s Sheet) AddDataValidation() DataValidation {
|
||||
s.x.DataValidations.CountAttr = gooxml.Uint32(uint32(len(s.x.DataValidations.DataValidation)))
|
||||
return DataValidation{dv}
|
||||
}
|
||||
|
||||
// ClearCachedFormulaResults clears any computed formula values that are stored
|
||||
// in the sheet. This may be required if you modify cells that are used as a
|
||||
// formula input to force the formulas to be recomputed the next time the sheet
|
||||
// is opened in Excel.
|
||||
func (s *Sheet) ClearCachedFormulaResults() {
|
||||
for _, r := range s.Rows() {
|
||||
for _, c := range r.Cells() {
|
||||
if c.X().F != nil {
|
||||
c.X().V = nil
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ import (
|
||||
"math/rand"
|
||||
"testing"
|
||||
|
||||
"baliance.com/gooxml"
|
||||
"baliance.com/gooxml/spreadsheet"
|
||||
)
|
||||
|
||||
@ -186,3 +187,16 @@ func TestSheetExtents(t *testing.T) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestSheetClearCachedFormula(t *testing.T) {
|
||||
ss := spreadsheet.New()
|
||||
sheet := ss.AddSheet()
|
||||
cell := sheet.Cell("A1")
|
||||
cell.SetFormulaRaw("foo")
|
||||
cell.X().V = gooxml.String("cached-results")
|
||||
sheet.ClearCachedFormulaResults()
|
||||
if cell.X().V != nil {
|
||||
t.Errorf("cached result not cleared")
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -414,3 +414,13 @@ func (wb *Workbook) DefinedNames() []DefinedName {
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
// ClearCachedFormulaResults clears any computed formula values that are stored
|
||||
// in the sheet. This may be required if you modify cells that are used as a
|
||||
// formula input to force the formulas to be recomputed the next time the sheet
|
||||
// is opened in Excel.
|
||||
func (wb *Workbook) ClearCachedFormulaResults() {
|
||||
for _, s := range wb.Sheets() {
|
||||
s.ClearCachedFormulaResults()
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user