diff options
author | Christian Fiedler <fdlr.christian@gmail.com> | 2019-09-22 14:52:01 +0200 |
---|---|---|
committer | xuri <xuri.me@gmail.com> | 2019-09-22 20:52:01 +0800 |
commit | 3280e1b68664e12143cbd2b3a408f9f494a72897 (patch) | |
tree | b21ebb3377bee840191b54497924cd5ab8ae93e6 /cell.go | |
parent | 3c636da46029b1c578871dfab3e1692e989af9f7 (diff) |
Allow access to more formula attributes in SetCellFormula (#484)
* Allow access to more formula attributes in SetCellFormula
Make SetCellFormula variadic to not break API.
The new arguments are option arguments in which the type of
the formula and the ref attribute may be set.
These need to be set for an array formula to work.
* Add TestWriteArrayFormula to test optional parameters of SetCellFormula
TestWriteArrayFormula writes a document to the test directory that
contains array formulas that are used to calculate standard deviations.
The file also contains values calculated by the Go testcase, so the
results can be verified. It should be tested, if the array formula
works (i.e. shows a number, not an error) and that the values calculated
by the formula and those calculated by Go are the same.
Diffstat (limited to 'cell.go')
-rw-r--r-- | cell.go | 19 |
1 files changed, 18 insertions, 1 deletions
@@ -273,9 +273,15 @@ func (f *File) GetCellFormula(sheet, axis string) (string, error) { }) } +// FormulaOpts can be passed to SetCellFormula to use other formula types. +type FormulaOpts struct { + Type *string // Formula type + Ref *string // Shared formula ref +} + // SetCellFormula provides a function to set cell formula by given string and // worksheet name. -func (f *File) SetCellFormula(sheet, axis, formula string) error { +func (f *File) SetCellFormula(sheet, axis, formula string, opts ...FormulaOpts) error { xlsx, err := f.workSheetReader(sheet) if err != nil { return err @@ -295,6 +301,17 @@ func (f *File) SetCellFormula(sheet, axis, formula string) error { } else { cellData.F = &xlsxF{Content: formula} } + + for _, o := range opts { + if o.Type != nil { + cellData.F.T = *o.Type + } + + if o.Ref != nil { + cellData.F.Ref = *o.Ref + } + } + return err } |