diff options
author | xuri <xuri.me@gmail.com> | 2021-09-05 11:59:50 +0800 |
---|---|---|
committer | xuri <xuri.me@gmail.com> | 2021-09-05 11:59:50 +0800 |
commit | 32b23ef42d3ecb393e102c5f63ab5125db354435 (patch) | |
tree | e73ec4e2e062d15ca6d53407039ddb3004942995 /cell_test.go | |
parent | 2616aa88cb2b1e45c03ada60093f4dfe7fabfb87 (diff) |
This closes #998
- Support text comparison in the formula, also ref #65
- `GetCellValue`, `GetRows`, `GetCols`, `Rows` and `Cols` support to specify read cell with raw value, ref #621
- Add missing properties for the cell formula
- Update the unit test for the `CalcCellValue`
Diffstat (limited to 'cell_test.go')
-rw-r--r-- | cell_test.go | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/cell_test.go b/cell_test.go index ad78436..d56854b 100644 --- a/cell_test.go +++ b/cell_test.go @@ -356,6 +356,16 @@ func TestSetCellFormula(t *testing.T) { ref = "" assert.EqualError(t, f.SetCellFormula("Sheet1", "D1", "=A1+C1", FormulaOpts{Ref: &ref, Type: &formulaType}), ErrParameterInvalid.Error()) assert.NoError(t, f.SaveAs(filepath.Join("test", "TestSetCellFormula5.xlsx"))) + + // Test set table formula for the cells. + f = NewFile() + for idx, row := range [][]interface{}{{"A", "B", "C"}, {1, 2}} { + assert.NoError(t, f.SetSheetRow("Sheet1", fmt.Sprintf("A%d", idx+1), &row)) + } + assert.NoError(t, f.AddTable("Sheet1", "A1", "C2", `{"table_name":"Table1","table_style":"TableStyleMedium2"}`)) + formulaType = STCellFormulaTypeDataTable + assert.NoError(t, f.SetCellFormula("Sheet1", "C2", "=SUM(Table1[[A]:[B]])", FormulaOpts{Type: &formulaType})) + assert.NoError(t, f.SaveAs(filepath.Join("test", "TestSetCellFormula6.xlsx"))) } func TestGetCellRichText(t *testing.T) { @@ -503,20 +513,20 @@ func TestSetCellRichText(t *testing.T) { func TestFormattedValue2(t *testing.T) { f := NewFile() - v := f.formattedValue(0, "43528") + v := f.formattedValue(0, "43528", false) assert.Equal(t, "43528", v) - v = f.formattedValue(15, "43528") + v = f.formattedValue(15, "43528", false) assert.Equal(t, "43528", v) - v = f.formattedValue(1, "43528") + v = f.formattedValue(1, "43528", false) assert.Equal(t, "43528", v) customNumFmt := "[$-409]MM/DD/YYYY" _, err := f.NewStyle(&Style{ CustomNumFmt: &customNumFmt, }) assert.NoError(t, err) - v = f.formattedValue(1, "43528") + v = f.formattedValue(1, "43528", false) assert.Equal(t, "03/04/2019", v) // formatted value with no built-in number format ID @@ -524,20 +534,20 @@ func TestFormattedValue2(t *testing.T) { f.Styles.CellXfs.Xf = append(f.Styles.CellXfs.Xf, xlsxXf{ NumFmtID: &numFmtID, }) - v = f.formattedValue(2, "43528") + v = f.formattedValue(2, "43528", false) assert.Equal(t, "43528", v) // formatted value with invalid number format ID f.Styles.CellXfs.Xf = append(f.Styles.CellXfs.Xf, xlsxXf{ NumFmtID: nil, }) - _ = f.formattedValue(3, "43528") + _ = f.formattedValue(3, "43528", false) // formatted value with empty number format f.Styles.NumFmts = nil f.Styles.CellXfs.Xf = append(f.Styles.CellXfs.Xf, xlsxXf{ NumFmtID: &numFmtID, }) - v = f.formattedValue(1, "43528") + v = f.formattedValue(1, "43528", false) assert.Equal(t, "43528", v) } |