-
-
Notifications
You must be signed in to change notification settings - Fork 24
/
range_test.go
52 lines (42 loc) · 1.63 KB
/
range_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright (c) 2017 Andrey Gayvoronsky <[email protected]>
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package xlsx
import (
"github.com/plandem/xlsx/format/styles"
"github.com/stretchr/testify/require"
"testing"
)
func TestRange(t *testing.T) {
xl, err := Open("./test_files/example_simple.xlsx")
if err != nil {
panic(err)
}
defer xl.Close()
sheet := xl.Sheet(0)
r := sheet.RangeByRef("D10:E10")
require.Equal(t, []string{"1", "2"}, r.Values())
require.Equal(t, styles.DirectStyleID(0), sheet.CellByRef("D10").ml.Style)
require.Equal(t, styles.DirectStyleID(0), sheet.CellByRef("E10").ml.Style)
r = sheet.Range(3, 9, 4, 9)
require.Equal(t, []string{"1", "2"}, r.Values())
require.Equal(t, styles.DirectStyleID(0), sheet.CellByRef("D10").ml.Style)
require.Equal(t, styles.DirectStyleID(0), sheet.CellByRef("E10").ml.Style)
//test styles
style := styles.New(
styles.Font.Name("Calibri"),
styles.Font.Size(12),
)
styleRef := xl.AddStyles(style)
r.SetStyles(styleRef)
require.Equal(t, styles.DirectStyleID(styleRef), sheet.CellByRef("D10").ml.Style)
require.Equal(t, styles.DirectStyleID(styleRef), sheet.CellByRef("E10").ml.Style)
r.Clear()
require.Equal(t, []string{"", ""}, r.Values())
require.Equal(t, styles.DirectStyleID(styleRef), sheet.CellByRef("D10").ml.Style)
require.Equal(t, styles.DirectStyleID(styleRef), sheet.CellByRef("E10").ml.Style)
r.Reset()
require.Equal(t, []string{"", ""}, r.Values())
require.Equal(t, styles.DirectStyleID(0), sheet.CellByRef("D10").ml.Style)
require.Equal(t, styles.DirectStyleID(0), sheet.CellByRef("E10").ml.Style)
}