(t *testing.T)
| 242 | } |
| 243 | |
| 244 | func TestGetConditionalFormats(t *testing.T) { |
| 245 | f := NewFile() |
| 246 | idx, err := f.NewConditionalStyle(&Style{Fill: Fill{Type: "pattern", Color: []string{"FEC7CE"}, Pattern: 1}}) |
| 247 | assert.NoError(t, err) |
| 248 | for idx, format := range [][]ConditionalFormatOptions{ |
| 249 | {{Type: "cell", Format: &idx, Criteria: "greater than", Value: "6"}}, |
| 250 | {{Type: "cell", Format: &idx, Criteria: "between", MinValue: "6", MaxValue: "8"}}, |
| 251 | {{Type: "time_period", Format: &idx, Criteria: "yesterday"}}, |
| 252 | {{Type: "time_period", Format: &idx, Criteria: "today"}}, |
| 253 | {{Type: "time_period", Format: &idx, Criteria: "tomorrow"}}, |
| 254 | {{Type: "time_period", Format: &idx, Criteria: "last 7 days"}}, |
| 255 | {{Type: "time_period", Format: &idx, Criteria: "last week"}}, |
| 256 | {{Type: "time_period", Format: &idx, Criteria: "this week"}}, |
| 257 | {{Type: "time_period", Format: &idx, Criteria: "continue week"}}, |
| 258 | {{Type: "time_period", Format: &idx, Criteria: "last month"}}, |
| 259 | {{Type: "time_period", Format: &idx, Criteria: "this month"}}, |
| 260 | {{Type: "time_period", Format: &idx, Criteria: "continue month"}}, |
| 261 | {{Type: "text", Format: &idx, Criteria: "containing", Value: "~!@#$%^&*()_+{}|:<>?\"';"}}, |
| 262 | {{Type: "text", Format: &idx, Criteria: "not containing", Value: "text"}}, |
| 263 | {{Type: "text", Format: &idx, Criteria: "begins with", Value: "prefix"}}, |
| 264 | {{Type: "text", Format: &idx, Criteria: "ends with", Value: "suffix"}}, |
| 265 | {{Type: "top", Format: &idx, Criteria: "=", Value: "6"}}, |
| 266 | {{Type: "bottom", Format: &idx, Criteria: "=", Value: "6"}}, |
| 267 | {{Type: "average", AboveAverage: true, Format: &idx, Criteria: "="}}, |
| 268 | {{Type: "duplicate", Format: &idx, Criteria: "="}}, |
| 269 | {{Type: "unique", Format: &idx, Criteria: "="}}, |
| 270 | {{Type: "3_color_scale", Criteria: "=", MinType: "num", MidType: "num", MaxType: "num", MinValue: "-10", MidValue: "50", MaxValue: "10", MinColor: "#FF0000", MidColor: "#00FF00", MaxColor: "#0000FF"}}, |
| 271 | {{Type: "2_color_scale", Criteria: "=", MinType: "num", MaxType: "num", MinColor: "#FF0000", MaxColor: "#0000FF"}}, |
| 272 | {{Type: "data_bar", Criteria: "=", MinType: "num", MaxType: "num", MinValue: "-10", MaxValue: "10", BarBorderColor: "#0000FF", BarColor: "#638EC6", BarOnly: true, BarSolid: true, StopIfTrue: true}}, |
| 273 | {{Type: "data_bar", Criteria: "=", MinType: "min", MaxType: "max", BarBorderColor: "#0000FF", BarColor: "#638EC6", BarDirection: "rightToLeft", BarOnly: true, BarSolid: true, StopIfTrue: true}}, |
| 274 | {{Type: "formula", Format: &idx, Criteria: "1"}}, |
| 275 | {{Type: "blanks", Format: &idx}}, |
| 276 | {{Type: "no_blanks", Format: &idx}}, |
| 277 | {{Type: "errors", Format: &idx}}, |
| 278 | {{Type: "no_errors", Format: &idx}}, |
| 279 | {{Type: "icon_set", IconStyle: "3Arrows", ReverseIcons: true, IconsOnly: true}}, |
| 280 | {{Type: "icon_set", IconStyle: "3Stars", ReverseIcons: true, IconsOnly: true}}, |
| 281 | {{Type: "icon_set", IconStyle: "3Triangles", ReverseIcons: true, IconsOnly: true}}, |
| 282 | {{Type: "icon_set", IconStyle: "5Boxes", ReverseIcons: true, IconsOnly: true}}, |
| 283 | } { |
| 284 | col, err := ColumnNumberToName(idx + 2) |
| 285 | assert.NoError(t, err) |
| 286 | err = f.SetConditionalFormat("Sheet1", fmt.Sprintf("%s1:%s10", col, col), format) |
| 287 | assert.NoError(t, err) |
| 288 | opts, err := f.GetConditionalFormats("Sheet1") |
| 289 | assert.NoError(t, err) |
| 290 | assert.Equal(t, format, opts[fmt.Sprintf("%s1:%s10", col, col)]) |
| 291 | } |
| 292 | assert.NoError(t, f.SaveAs(filepath.Join("test", "TestGetConditionalFormats.xlsx"))) |
| 293 | // Test unset all conditional formats |
| 294 | f, err = OpenFile(filepath.Join("test", "TestGetConditionalFormats.xlsx")) |
| 295 | assert.NoError(t, f.AddSparkline("Sheet1", &SparklineOptions{ |
| 296 | Location: []string{"C1"}, |
| 297 | Range: []string{"Sheet1!A1:B1"}, |
| 298 | })) |
| 299 | for _, rangeRef := range []string{"Y1:Y10", "Z1:Z10", "AG1:AG10", "AH1:AH10", "AI1:AI10"} { |
| 300 | assert.NoError(t, f.UnsetConditionalFormat("Sheet1", rangeRef)) |
| 301 | } |
nothing calls this directly
no test coverage detected