已验证 提交 eb62256d 编写于 作者: xurime's avatar xurime

Simplify testing code, add test case for outline functions and update the godoc.

上级 b5655ce1
......@@ -109,7 +109,7 @@ func main() {
for k, v := range values {
xlsx.SetCellValue("Sheet1", k, v)
}
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"}}`)
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"}}`)
// Save xlsx file by the given path.
err := xlsx.SaveAs("./Book1.xlsx")
if err != nil {
......
......@@ -243,7 +243,7 @@ func parseFormatChartSet(formatSet string) *formatChart {
// for k, v := range values {
// xlsx.SetCellValue("Sheet1", k, v)
// }
// 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}}`)
// 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}}`)
// // Save xlsx file by the given path.
// err := xlsx.SaveAs("./Book1.xlsx")
// if err != nil {
......@@ -355,6 +355,8 @@ func parseFormatChartSet(formatSet string) *formatChart {
// maximum: Specifies that the fixed maximum, 0 is auto. The maximum property is optional. The default value is auto.
// minimum: Specifies that the fixed minimum, 0 is auto. The minimum property is optional. The default value is auto.
//
// Set chart size by dimension property. The dimension property is optional. The default width is 480, and height is 290.
//
func (f *File) AddChart(sheet, cell, format string) {
formatSet := parseFormatChartSet(format)
// Read sheet data.
......
......@@ -67,11 +67,11 @@ func (f *File) SetColVisible(sheet, column string, visible bool) {
xlsx.Cols.Col = append(xlsx.Cols.Col, col)
}
// GetColOutlineLevel provides a function to get outline level of a single column by given
// worksheet name and column name. For example, get outline level of column D
// in Sheet1:
// GetColOutlineLevel provides a function to get outline level of a single
// column by given worksheet name and column name. For example, get outline
// level of column D in Sheet1:
//
// xlsx.getColOutlineLevel("Sheet1", "D")
// xlsx.GetColOutlineLevel("Sheet1", "D")
//
func (f *File) GetColOutlineLevel(sheet, column string) uint8 {
xlsx := f.workSheetReader(sheet)
......@@ -88,8 +88,9 @@ func (f *File) GetColOutlineLevel(sheet, column string) uint8 {
return level
}
// SetColOutlineLevel provides a function to set outline level of a single column by given
// worksheet name and column name. For example, set outline level of column D in Sheet1 to 2:
// SetColOutlineLevel provides a function to set outline level of a single
// column by given worksheet name and column name. For example, set outline
// level of column D in Sheet1 to 2:
//
// xlsx.SetColOutlineLevel("Sheet1", "D", 2)
//
......
......@@ -799,34 +799,25 @@ func TestAutoFilter(t *testing.T) {
if err != nil {
t.Error(err)
}
err = xlsx.AutoFilter("Sheet3", "D4", "B1", ``)
t.Log(err)
err = xlsx.AutoFilter("Sheet3", "D4", "B1", `{"column":"B","expression":"x != blanks"}`)
t.Log(err)
err = xlsx.AutoFilter("Sheet3", "D4", "B1", `{"column":"B","expression":"x == blanks"}`)
t.Log(err)
err = xlsx.AutoFilter("Sheet3", "D4", "B1", `{"column":"B","expression":"x != nonblanks"}`)
t.Log(err)
err = xlsx.AutoFilter("Sheet3", "D4", "B1", `{"column":"B","expression":"x == nonblanks"}`)
t.Log(err)
err = xlsx.AutoFilter("Sheet3", "D4", "B1", `{"column":"B","expression":"x <= 1 and x >= 2"}`)
t.Log(err)
err = xlsx.AutoFilter("Sheet3", "D4", "B1", `{"column":"B","expression":"x == 1 or x == 2"}`)
t.Log(err)
err = xlsx.AutoFilter("Sheet3", "D4", "B1", `{"column":"B","expression":"x == 1 or x == 2*"}`)
t.Log(err)
err = xlsx.AutoFilter("Sheet3", "D4", "B1", `{"column":"B","expression":"x <= 1 and x >= blanks"}`)
t.Log(err)
err = xlsx.AutoFilter("Sheet3", "D4", "B1", `{"column":"B","expression":"x -- y or x == *2*"}`)
t.Log(err)
err = xlsx.AutoFilter("Sheet3", "D4", "B1", `{"column":"B","expression":"x != y or x ? *2"}`)
t.Log(err)
err = xlsx.AutoFilter("Sheet3", "D4", "B1", `{"column":"B","expression":"x -- y o r x == *2"}`)
t.Log(err)
err = xlsx.AutoFilter("Sheet3", "D4", "B1", `{"column":"B","expression":"x -- y"}`)
t.Log(err)
err = xlsx.AutoFilter("Sheet3", "D4", "B1", `{"column":"A","expression":"x -- y"}`)
t.Log(err)
formats := []string{``,
`{"column":"B","expression":"x != blanks"}`,
`{"column":"B","expression":"x == blanks"}`,
`{"column":"B","expression":"x != nonblanks"}`,
`{"column":"B","expression":"x == nonblanks"}`,
`{"column":"B","expression":"x <= 1 and x >= 2"}`,
`{"column":"B","expression":"x == 1 or x == 2"}`,
`{"column":"B","expression":"x == 1 or x == 2*"}`,
`{"column":"B","expression":"x <= 1 and x >= blanks"}`,
`{"column":"B","expression":"x -- y or x == *2*"}`,
`{"column":"B","expression":"x != y or x ? *2"}`,
`{"column":"B","expression":"x -- y o r x == *2"}`,
`{"column":"B","expression":"x -- y"}`,
`{"column":"A","expression":"x -- y"}`,
}
for _, format := range formats {
err = xlsx.AutoFilter("Sheet3", "D4", "B1", format)
t.Log(err)
}
err = xlsx.Save()
if err != nil {
t.Error(err)
......@@ -1103,6 +1094,29 @@ func TestRows(t *testing.T) {
}
}
func TestOutlineLevel(t *testing.T) {
xlsx := NewFile()
xlsx.NewSheet("Sheet2")
xlsx.SetColOutlineLevel("Sheet1", "D", 4)
xlsx.GetColOutlineLevel("Sheet1", "D")
xlsx.GetColOutlineLevel("Shee2", "A")
xlsx.SetColWidth("Sheet2", "A", "D", 13)
xlsx.SetColOutlineLevel("Sheet2", "B", 2)
xlsx.SetRowOutlineLevel("Sheet1", 2, 1)
xlsx.GetRowOutlineLevel("Sheet1", 2)
err := xlsx.SaveAs("./test/Book_outline_level.xlsx")
if err != nil {
t.Error(err)
return
}
xlsx, err = OpenFile("./test/Book1.xlsx")
if err != nil {
t.Error(err)
return
}
xlsx.SetColOutlineLevel("Sheet2", "B", 2)
}
func trimSliceSpace(s []string) []string {
for {
if len(s) > 0 && s[len(s)-1] == "" {
......
......@@ -301,8 +301,9 @@ func (f *File) GetRowVisible(sheet string, rowIndex int) bool {
return !xlsx.SheetData.Row[rowIndex].Hidden
}
// SetRowOutlineLevel provides a function to set outline level number of a single row by given
// worksheet name and row index. For example, outline row 2 in Sheet1 to level 1:
// SetRowOutlineLevel provides a function to set outline level number of a
// single row by given worksheet name and row index. For example, outline row
// 2 in Sheet1 to level 1:
//
// xlsx.SetRowOutlineLevel("Sheet1", 2, 1)
//
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册