2022-02-17 00:09:11 +08:00
|
|
|
package excelize
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func ExampleFile_SetWorkbookPrOptions() {
|
|
|
|
f := NewFile()
|
|
|
|
if err := f.SetWorkbookPrOptions(
|
2022-02-25 21:37:49 +08:00
|
|
|
FilterPrivacy(false),
|
2022-02-17 00:09:11 +08:00
|
|
|
CodeName("code"),
|
|
|
|
); err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
}
|
|
|
|
// Output:
|
|
|
|
}
|
|
|
|
|
|
|
|
func ExampleFile_GetWorkbookPrOptions() {
|
|
|
|
f := NewFile()
|
2022-02-25 21:37:49 +08:00
|
|
|
var (
|
|
|
|
filterPrivacy FilterPrivacy
|
|
|
|
codeName CodeName
|
|
|
|
)
|
|
|
|
if err := f.GetWorkbookPrOptions(&filterPrivacy); err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
}
|
2022-02-17 00:09:11 +08:00
|
|
|
if err := f.GetWorkbookPrOptions(&codeName); err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
}
|
|
|
|
fmt.Println("Defaults:")
|
2022-02-25 21:37:49 +08:00
|
|
|
fmt.Printf("- filterPrivacy: %t\n", filterPrivacy)
|
2022-02-17 00:09:11 +08:00
|
|
|
fmt.Printf("- codeName: %q\n", codeName)
|
|
|
|
// Output:
|
|
|
|
// Defaults:
|
2022-02-25 21:37:49 +08:00
|
|
|
// - filterPrivacy: true
|
2022-02-17 00:09:11 +08:00
|
|
|
// - codeName: ""
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestWorkbookPr(t *testing.T) {
|
|
|
|
f := NewFile()
|
|
|
|
wb := f.workbookReader()
|
|
|
|
wb.WorkbookPr = nil
|
|
|
|
var codeName CodeName
|
|
|
|
assert.NoError(t, f.GetWorkbookPrOptions(&codeName))
|
|
|
|
assert.Equal(t, "", string(codeName))
|
|
|
|
assert.NoError(t, f.SetWorkbookPrOptions(CodeName("code")))
|
|
|
|
assert.NoError(t, f.GetWorkbookPrOptions(&codeName))
|
|
|
|
assert.Equal(t, "code", string(codeName))
|
2022-02-25 21:37:49 +08:00
|
|
|
|
|
|
|
wb.WorkbookPr = nil
|
|
|
|
var filterPrivacy FilterPrivacy
|
|
|
|
assert.NoError(t, f.GetWorkbookPrOptions(&filterPrivacy))
|
|
|
|
assert.Equal(t, false, bool(filterPrivacy))
|
2022-02-17 00:09:11 +08:00
|
|
|
}
|