Skip to content

Commit

Permalink
Init auto filter support, relate issue qax-os#59.
Browse files Browse the repository at this point in the history
  • Loading branch information
xuri committed Jun 8, 2017
1 parent c5dc632 commit c89d842
Show file tree
Hide file tree
Showing 6 changed files with 486 additions and 3 deletions.
52 changes: 52 additions & 0 deletions excelize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,19 @@ func TestSheetVisibility(t *testing.T) {
}
}

func TestRowVisibility(t *testing.T) {
xlsx, err := OpenFile("./test/Workbook_2.xlsx")
if err != nil {
t.Log(err)
}
xlsx.HideRow("Sheet3", 2)
xlsx.UnhideRow("Sheet3", 2)
err = xlsx.Save()
if err != nil {
t.Log(err)
}
}

func TestCopySheet(t *testing.T) {
xlsx, err := OpenFile("./test/Workbook_2.xlsx")
if err != nil {
Expand Down Expand Up @@ -541,6 +554,45 @@ func TestAddComments(t *testing.T) {
}
}

func TestAutoFilter(t *testing.T) {
xlsx, err := OpenFile("./test/Workbook_2.xlsx")
if err != nil {
t.Log(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)
err = xlsx.Save()
if err != nil {
t.Log(err)
}
}

func TestAddChart(t *testing.T) {
xlsx, err := OpenFile("./test/Workbook1.xlsx")
if err != nil {
Expand Down
24 changes: 24 additions & 0 deletions rows.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,27 @@ func (xlsx *xlsxC) getValueFrom(f *File, d *xlsxSST) (string, error) {
return f.formattedValue(xlsx.S, xlsx.V), nil
}
}

// HideRow provides a function to set hidden of a single row by given worksheet index and row index. For example, hide row 3 in Sheet1:
//
// xlsx.HideRow("Sheet1", 2)
//
func (f *File) HideRow(sheet string, rowIndex int) {
xlsx := f.workSheetReader(sheet)
rows := rowIndex + 1
cells := 0
completeRow(xlsx, rows, cells)
xlsx.SheetData.Row[rowIndex].Hidden = true
}

// UnhideRow provides a function to set unhidden of a single row by given worksheet index and row index. For example, unhide row 3 in Sheet1:
//
// xlsx.UnhideRow("Sheet1", 2)
//
func (f *File) UnhideRow(sheet string, rowIndex int) {
xlsx := f.workSheetReader(sheet)
rows := rowIndex + 1
cells := 0
completeRow(xlsx, rows, cells)
xlsx.SheetData.Row[rowIndex].Hidden = false
}
4 changes: 2 additions & 2 deletions sheet.go
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ func (f *File) HideSheet(name string) {
content := f.workbookReader()
count := 0
for _, v := range content.Sheets.Sheet {
if v.State != `hidden` {
if v.State != "hidden" {
count++
}
}
Expand All @@ -462,7 +462,7 @@ func (f *File) HideSheet(name string) {
tabSelected = xlsx.SheetViews.SheetView[0].TabSelected
}
if v.Name == name && count > 1 && !tabSelected {
content.Sheets.Sheet[k].State = `hidden`
content.Sheets.Sheet[k].State = "hidden"
}
}
}
Expand Down
Loading

0 comments on commit c89d842

Please sign in to comment.