forked from unidoc/unioffice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
workbookprotection.go
68 lines (57 loc) · 1.89 KB
/
workbookprotection.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Copyright 2017 FoxyUtils ehf. All rights reserved.
//
// Use of this software package and source code is governed by the terms of the
// UniDoc End User License Agreement (EULA) that is available at:
// https://unidoc.io/eula/
// A trial license code for evaluation can be obtained at https://unidoc.io.
package spreadsheet
import (
"github.com/unidoc/unioffice"
"github.com/unidoc/unioffice/schema/soo/sml"
)
type WorkbookProtection struct {
x *sml.CT_WorkbookProtection
}
// X returns the inner wrapped XML type.
func (p WorkbookProtection) X() *sml.CT_WorkbookProtection {
return p.x
}
// IsStructureLocked returns whether the workbook structure is locked.
func (p WorkbookProtection) IsStructureLocked() bool {
return p.x.LockStructureAttr != nil && *p.x.LockStructureAttr
}
// LockStructure controls the locking of the workbook structure.
func (p WorkbookProtection) LockStructure(b bool) {
if !b {
p.x.LockStructureAttr = nil
} else {
p.x.LockStructureAttr = unioffice.Bool(true)
}
}
// IsWindowLocked returns whether the workbook windows are locked.
func (p WorkbookProtection) IsWindowLocked() bool {
return p.x.LockWindowsAttr != nil && *p.x.LockWindowsAttr
}
// LockWindow controls the locking of the workbook windows.
func (p WorkbookProtection) LockWindow(b bool) {
if !b {
p.x.LockWindowsAttr = nil
} else {
p.x.LockWindowsAttr = unioffice.Bool(true)
}
}
// PasswordHash returns the hash of the workbook password.
func (p WorkbookProtection) PasswordHash() string {
if p.x.WorkbookPasswordAttr == nil {
return ""
}
return *p.x.WorkbookPasswordAttr
}
// SetPassword sets the password hash to a hash of the input password.
func (p WorkbookProtection) SetPassword(pw string) {
p.SetPasswordHash(PasswordHash(pw))
}
// SetPasswordHash sets the password hash to the input.
func (p WorkbookProtection) SetPasswordHash(pwHash string) {
p.x.WorkbookPasswordAttr = unioffice.String(pwHash)
}