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