Skip to content

Commit eb62256

Browse files
committed
Simplify testing code, add test case for outline functions and update the godoc.
1 parent b5655ce commit eb62256

File tree

5 files changed

+56
-38
lines changed

5 files changed

+56
-38
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func main() {
109109
for k, v := range values {
110110
xlsx.SetCellValue("Sheet1", k, v)
111111
}
112-
xlsx.AddChart("Sheet1", "E1", `{"type":"col3DClustered","dimension":{"width":640, "height":480},"series":[{"name":"Sheet1!$A$2","categories":"Sheet1!$B$1:$D$1","values":"Sheet1!$B$2:$D$2"},{"name":"Sheet1!$A$3","categories":"Sheet1!$B$1:$D$1","values":"Sheet1!$B$3:$D$3"},{"name":"Sheet1!$A$4","categories":"Sheet1!$B$1:$D$1","values":"Sheet1!$B$4:$D$4"}],"title":{"name":"Fruit 3D Clustered Column Chart"}}`)
112+
xlsx.AddChart("Sheet1", "E1", `{"type":"col3DClustered","series":[{"name":"Sheet1!$A$2","categories":"Sheet1!$B$1:$D$1","values":"Sheet1!$B$2:$D$2"},{"name":"Sheet1!$A$3","categories":"Sheet1!$B$1:$D$1","values":"Sheet1!$B$3:$D$3"},{"name":"Sheet1!$A$4","categories":"Sheet1!$B$1:$D$1","values":"Sheet1!$B$4:$D$4"}],"title":{"name":"Fruit 3D Clustered Column Chart"}}`)
113113
// Save xlsx file by the given path.
114114
err := xlsx.SaveAs("./Book1.xlsx")
115115
if err != nil {

chart.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ func parseFormatChartSet(formatSet string) *formatChart {
243243
// for k, v := range values {
244244
// xlsx.SetCellValue("Sheet1", k, v)
245245
// }
246-
// xlsx.AddChart("Sheet1", "E1", `{"type":"col3DClustered","series":[{"name":"Sheet1!$A$2","categories":"Sheet1!$B$1:$D$1","values":"Sheet1!$B$2:$D$2"},{"name":"Sheet1!$A$3","categories":"Sheet1!$B$1:$D$1","values":"Sheet1!$B$3:$D$3"},{"name":"Sheet1!$A$4","categories":"Sheet1!$B$1:$D$1","values":"Sheet1!$B$4:$D$4"}],"format":{"x_scale":1.0,"y_scale":1.0,"x_offset":15,"y_offset":10,"print_obj":true,"lock_aspect_ratio":false,"locked":false},"legend":{"position":"bottom","show_legend_key":false},"title":{"name":"Fruit 3D Clustered Column Chart"},"plotarea":{"show_bubble_size":true,"show_cat_name":false,"show_leader_lines":false,"show_percent":true,"show_series_name":true,"show_val":true},"show_blanks_as":"zero","x_axis":{"reverse_order":true},"y_axis":{"maximum":7.5,"minimum":0.5}}`)
246+
// xlsx.AddChart("Sheet1", "E1", `{"type":"col3DClustered","dimension":{"width":640,"height":480},"series":[{"name":"Sheet1!$A$2","categories":"Sheet1!$B$1:$D$1","values":"Sheet1!$B$2:$D$2"},{"name":"Sheet1!$A$3","categories":"Sheet1!$B$1:$D$1","values":"Sheet1!$B$3:$D$3"},{"name":"Sheet1!$A$4","categories":"Sheet1!$B$1:$D$1","values":"Sheet1!$B$4:$D$4"}],"format":{"x_scale":1.0,"y_scale":1.0,"x_offset":15,"y_offset":10,"print_obj":true,"lock_aspect_ratio":false,"locked":false},"legend":{"position":"bottom","show_legend_key":false},"title":{"name":"Fruit 3D Clustered Column Chart"},"plotarea":{"show_bubble_size":true,"show_cat_name":false,"show_leader_lines":false,"show_percent":true,"show_series_name":true,"show_val":true},"show_blanks_as":"zero","x_axis":{"reverse_order":true},"y_axis":{"maximum":7.5,"minimum":0.5}}`)
247247
// // Save xlsx file by the given path.
248248
// err := xlsx.SaveAs("./Book1.xlsx")
249249
// if err != nil {
@@ -355,6 +355,8 @@ func parseFormatChartSet(formatSet string) *formatChart {
355355
// maximum: Specifies that the fixed maximum, 0 is auto. The maximum property is optional. The default value is auto.
356356
// minimum: Specifies that the fixed minimum, 0 is auto. The minimum property is optional. The default value is auto.
357357
//
358+
// Set chart size by dimension property. The dimension property is optional. The default width is 480, and height is 290.
359+
//
358360
func (f *File) AddChart(sheet, cell, format string) {
359361
formatSet := parseFormatChartSet(format)
360362
// Read sheet data.

col.go

+7-6
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ func (f *File) SetColVisible(sheet, column string, visible bool) {
6767
xlsx.Cols.Col = append(xlsx.Cols.Col, col)
6868
}
6969

70-
// GetColOutlineLevel provides a function to get outline level of a single column by given
71-
// worksheet name and column name. For example, get outline level of column D
72-
// in Sheet1:
70+
// GetColOutlineLevel provides a function to get outline level of a single
71+
// column by given worksheet name and column name. For example, get outline
72+
// level of column D in Sheet1:
7373
//
74-
// xlsx.getColOutlineLevel("Sheet1", "D")
74+
// xlsx.GetColOutlineLevel("Sheet1", "D")
7575
//
7676
func (f *File) GetColOutlineLevel(sheet, column string) uint8 {
7777
xlsx := f.workSheetReader(sheet)
@@ -88,8 +88,9 @@ func (f *File) GetColOutlineLevel(sheet, column string) uint8 {
8888
return level
8989
}
9090

91-
// SetColOutlineLevel provides a function to set outline level of a single column by given
92-
// worksheet name and column name. For example, set outline level of column D in Sheet1 to 2:
91+
// SetColOutlineLevel provides a function to set outline level of a single
92+
// column by given worksheet name and column name. For example, set outline
93+
// level of column D in Sheet1 to 2:
9394
//
9495
// xlsx.SetColOutlineLevel("Sheet1", "D", 2)
9596
//

excelize_test.go

+42-28
Original file line numberDiff line numberDiff line change
@@ -799,34 +799,25 @@ func TestAutoFilter(t *testing.T) {
799799
if err != nil {
800800
t.Error(err)
801801
}
802-
err = xlsx.AutoFilter("Sheet3", "D4", "B1", ``)
803-
t.Log(err)
804-
err = xlsx.AutoFilter("Sheet3", "D4", "B1", `{"column":"B","expression":"x != blanks"}`)
805-
t.Log(err)
806-
err = xlsx.AutoFilter("Sheet3", "D4", "B1", `{"column":"B","expression":"x == blanks"}`)
807-
t.Log(err)
808-
err = xlsx.AutoFilter("Sheet3", "D4", "B1", `{"column":"B","expression":"x != nonblanks"}`)
809-
t.Log(err)
810-
err = xlsx.AutoFilter("Sheet3", "D4", "B1", `{"column":"B","expression":"x == nonblanks"}`)
811-
t.Log(err)
812-
err = xlsx.AutoFilter("Sheet3", "D4", "B1", `{"column":"B","expression":"x <= 1 and x >= 2"}`)
813-
t.Log(err)
814-
err = xlsx.AutoFilter("Sheet3", "D4", "B1", `{"column":"B","expression":"x == 1 or x == 2"}`)
815-
t.Log(err)
816-
err = xlsx.AutoFilter("Sheet3", "D4", "B1", `{"column":"B","expression":"x == 1 or x == 2*"}`)
817-
t.Log(err)
818-
err = xlsx.AutoFilter("Sheet3", "D4", "B1", `{"column":"B","expression":"x <= 1 and x >= blanks"}`)
819-
t.Log(err)
820-
err = xlsx.AutoFilter("Sheet3", "D4", "B1", `{"column":"B","expression":"x -- y or x == *2*"}`)
821-
t.Log(err)
822-
err = xlsx.AutoFilter("Sheet3", "D4", "B1", `{"column":"B","expression":"x != y or x ? *2"}`)
823-
t.Log(err)
824-
err = xlsx.AutoFilter("Sheet3", "D4", "B1", `{"column":"B","expression":"x -- y o r x == *2"}`)
825-
t.Log(err)
826-
err = xlsx.AutoFilter("Sheet3", "D4", "B1", `{"column":"B","expression":"x -- y"}`)
827-
t.Log(err)
828-
err = xlsx.AutoFilter("Sheet3", "D4", "B1", `{"column":"A","expression":"x -- y"}`)
829-
t.Log(err)
802+
formats := []string{``,
803+
`{"column":"B","expression":"x != blanks"}`,
804+
`{"column":"B","expression":"x == blanks"}`,
805+
`{"column":"B","expression":"x != nonblanks"}`,
806+
`{"column":"B","expression":"x == nonblanks"}`,
807+
`{"column":"B","expression":"x <= 1 and x >= 2"}`,
808+
`{"column":"B","expression":"x == 1 or x == 2"}`,
809+
`{"column":"B","expression":"x == 1 or x == 2*"}`,
810+
`{"column":"B","expression":"x <= 1 and x >= blanks"}`,
811+
`{"column":"B","expression":"x -- y or x == *2*"}`,
812+
`{"column":"B","expression":"x != y or x ? *2"}`,
813+
`{"column":"B","expression":"x -- y o r x == *2"}`,
814+
`{"column":"B","expression":"x -- y"}`,
815+
`{"column":"A","expression":"x -- y"}`,
816+
}
817+
for _, format := range formats {
818+
err = xlsx.AutoFilter("Sheet3", "D4", "B1", format)
819+
t.Log(err)
820+
}
830821
err = xlsx.Save()
831822
if err != nil {
832823
t.Error(err)
@@ -1103,6 +1094,29 @@ func TestRows(t *testing.T) {
11031094
}
11041095
}
11051096

1097+
func TestOutlineLevel(t *testing.T) {
1098+
xlsx := NewFile()
1099+
xlsx.NewSheet("Sheet2")
1100+
xlsx.SetColOutlineLevel("Sheet1", "D", 4)
1101+
xlsx.GetColOutlineLevel("Sheet1", "D")
1102+
xlsx.GetColOutlineLevel("Shee2", "A")
1103+
xlsx.SetColWidth("Sheet2", "A", "D", 13)
1104+
xlsx.SetColOutlineLevel("Sheet2", "B", 2)
1105+
xlsx.SetRowOutlineLevel("Sheet1", 2, 1)
1106+
xlsx.GetRowOutlineLevel("Sheet1", 2)
1107+
err := xlsx.SaveAs("./test/Book_outline_level.xlsx")
1108+
if err != nil {
1109+
t.Error(err)
1110+
return
1111+
}
1112+
xlsx, err = OpenFile("./test/Book1.xlsx")
1113+
if err != nil {
1114+
t.Error(err)
1115+
return
1116+
}
1117+
xlsx.SetColOutlineLevel("Sheet2", "B", 2)
1118+
}
1119+
11061120
func trimSliceSpace(s []string) []string {
11071121
for {
11081122
if len(s) > 0 && s[len(s)-1] == "" {

rows.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,9 @@ func (f *File) GetRowVisible(sheet string, rowIndex int) bool {
301301
return !xlsx.SheetData.Row[rowIndex].Hidden
302302
}
303303

304-
// SetRowOutlineLevel provides a function to set outline level number of a single row by given
305-
// worksheet name and row index. For example, outline row 2 in Sheet1 to level 1:
304+
// SetRowOutlineLevel provides a function to set outline level number of a
305+
// single row by given worksheet name and row index. For example, outline row
306+
// 2 in Sheet1 to level 1:
306307
//
307308
// xlsx.SetRowOutlineLevel("Sheet1", 2, 1)
308309
//

0 commit comments

Comments
 (0)