Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add-FilterPrivacy-to-workbookPr #1154

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions sheetpr.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ type SheetPrOptionPtr interface {
}

type (
// FilterPrivacy is an option used for SheetPrOption and WorkbookPrOption
FilterPrivacy bool
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The filterPrivacy attribute didn't belong to worksheets properties, so I suggest defining it in the workbook.go, and correct doc comment for it.

// CodeName is an option used for SheetPrOption and WorkbookPrOption
CodeName string
// EnableFormatConditionsCalculation is a SheetPrOption
Expand Down
15 changes: 15 additions & 0 deletions workbook.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ func (o CodeName) setWorkbookPrOption(pr *xlsxWorkbookPr) {
pr.CodeName = string(o)
}

// setWorkbookPrOption implements the WorkbookPrOption interface.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest the get and set implement functions following the order in OOXML Spec, move this function before CodeName, and update the available options document of the functions SetWorkbookPrOptions and GetWorkbookPrOptions

func (o FilterPrivacy) setWorkbookPrOption(pr *xlsxWorkbookPr) {
pr.FilterPrivacy = bool(o)
}

// GetWorkbookPrOptions provides a function to gets workbook properties.
//
// Available options:
Expand All @@ -145,3 +150,13 @@ func (o *CodeName) getWorkbookPrOption(pr *xlsxWorkbookPr) {
}
*o = CodeName(pr.CodeName)
}

// getWorkbookPrOption implements the WorkbookPrOption interface and get the
// filter privacy of thw workbook.
func (o *FilterPrivacy) getWorkbookPrOption(pr *xlsxWorkbookPr) {
if pr == nil {
*o = true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This case was not been tested, please add a test case for this.

return
}
*o = FilterPrivacy(pr.FilterPrivacy)
}
14 changes: 14 additions & 0 deletions workbook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ func ExampleFile_SetWorkbookPrOptions() {
f := NewFile()
if err := f.SetWorkbookPrOptions(
CodeName("code"),
FilterPrivacy(false),
); err != nil {
fmt.Println(err)
}
Expand All @@ -23,11 +24,17 @@ func ExampleFile_GetWorkbookPrOptions() {
if err := f.GetWorkbookPrOptions(&codeName); err != nil {
fmt.Println(err)
}
var filterPrivacy FilterPrivacy
if err := f.GetWorkbookPrOptions(&filterPrivacy); err != nil {
fmt.Println(err)
}
fmt.Println("Defaults:")
fmt.Printf("- codeName: %q\n", codeName)
fmt.Printf("- filterPrivacy: %t\n", filterPrivacy)
// Output:
// Defaults:
// - codeName: ""
// - filterPrivacy: true
}

func TestWorkbookPr(t *testing.T) {
Expand All @@ -40,4 +47,11 @@ func TestWorkbookPr(t *testing.T) {
assert.NoError(t, f.SetWorkbookPrOptions(CodeName("code")))
assert.NoError(t, f.GetWorkbookPrOptions(&codeName))
assert.Equal(t, "code", string(codeName))

var filterPrivacy FilterPrivacy
assert.NoError(t, f.GetWorkbookPrOptions(&filterPrivacy))
assert.Equal(t, false, bool(filterPrivacy))
assert.NoError(t, f.SetWorkbookPrOptions(FilterPrivacy(true)))
assert.NoError(t, f.GetWorkbookPrOptions(&filterPrivacy))
assert.Equal(t, true, bool(filterPrivacy))
}