Skip to content

Commit a00ba75

Browse files
authored
Fix #493 Merge pull request #495 from jaby/493-ShowZeros
Add missing ShowZeros SheetViewOption implementation
2 parents eb520ae + babfeb6 commit a00ba75

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

sheetview.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,18 @@ type (
5151
// visible cell Location of the top left visible cell in the bottom right
5252
// pane (when in Left-to-Right mode).
5353
TopLeftCell string
54+
// ShowZeros is a SheetViewOption. It specifies a flag indicating
55+
// whether to "show a zero in cells that have zero value".
56+
// When using a formula to reference another cell which is empty, the referenced value becomes 0
57+
// when the flag is true. (Default setting is true.)
58+
ShowZeros bool
59+
5460
/* TODO
5561
// ShowWhiteSpace is a SheetViewOption. It specifies a flag indicating
5662
// whether page layout view shall display margins. False means do not display
5763
// left, right, top (header), and bottom (footer) margins (even when there is
5864
// data in the header or footer).
5965
ShowWhiteSpace bool
60-
// ShowZeros is a SheetViewOption.
61-
ShowZeros bool
6266
// WindowProtection is a SheetViewOption.
6367
WindowProtection bool
6468
*/
@@ -106,6 +110,14 @@ func (o *ShowGridLines) getSheetViewOption(view *xlsxSheetView) {
106110
*o = ShowGridLines(defaultTrue(view.ShowGridLines)) // Excel default: true
107111
}
108112

113+
func (o ShowZeros) setSheetViewOption(view *xlsxSheetView) {
114+
view.ShowZeros = boolPtr(bool(o))
115+
}
116+
117+
func (o *ShowZeros) getSheetViewOption(view *xlsxSheetView) {
118+
*o = ShowZeros(defaultTrue(view.ShowZeros)) // Excel default: true
119+
}
120+
109121
func (o ShowRowColHeaders) setSheetViewOption(view *xlsxSheetView) {
110122
view.ShowRowColHeaders = boolPtr(bool(o))
111123
}

sheetview_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ func ExampleFile_GetSheetViewOptions() {
9595
rightToLeft excelize.RightToLeft
9696
showFormulas excelize.ShowFormulas
9797
showGridLines excelize.ShowGridLines
98+
showZeros excelize.ShowZeros
9899
showRowColHeaders excelize.ShowRowColHeaders
99100
zoomScale excelize.ZoomScale
100101
topLeftCell excelize.TopLeftCell
@@ -105,6 +106,7 @@ func ExampleFile_GetSheetViewOptions() {
105106
&rightToLeft,
106107
&showFormulas,
107108
&showGridLines,
109+
&showZeros,
108110
&showRowColHeaders,
109111
&zoomScale,
110112
&topLeftCell,
@@ -117,6 +119,7 @@ func ExampleFile_GetSheetViewOptions() {
117119
fmt.Println("- rightToLeft:", rightToLeft)
118120
fmt.Println("- showFormulas:", showFormulas)
119121
fmt.Println("- showGridLines:", showGridLines)
122+
fmt.Println("- showZeros:", showZeros)
120123
fmt.Println("- showRowColHeaders:", showRowColHeaders)
121124
fmt.Println("- zoomScale:", zoomScale)
122125
fmt.Println("- topLeftCell:", `"`+topLeftCell+`"`)
@@ -137,8 +140,17 @@ func ExampleFile_GetSheetViewOptions() {
137140
panic(err)
138141
}
139142

143+
if err := f.SetSheetViewOptions(sheet, 0, excelize.ShowZeros(false)); err != nil {
144+
panic(err)
145+
}
146+
147+
if err := f.GetSheetViewOptions(sheet, 0, &showZeros); err != nil {
148+
panic(err)
149+
}
150+
140151
fmt.Println("After change:")
141152
fmt.Println("- showGridLines:", showGridLines)
153+
fmt.Println("- showZeros:", showZeros)
142154
fmt.Println("- topLeftCell:", topLeftCell)
143155

144156
// Output:
@@ -147,11 +159,13 @@ func ExampleFile_GetSheetViewOptions() {
147159
// - rightToLeft: false
148160
// - showFormulas: false
149161
// - showGridLines: true
162+
// - showZeros: true
150163
// - showRowColHeaders: true
151164
// - zoomScale: 0
152165
// - topLeftCell: ""
153166
// After change:
154167
// - showGridLines: false
168+
// - showZeros: false
155169
// - topLeftCell: B2
156170
}
157171

xmlWorksheet.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ type xlsxSheetView struct {
167167
ShowFormulas bool `xml:"showFormulas,attr,omitempty"`
168168
ShowGridLines *bool `xml:"showGridLines,attr"`
169169
ShowRowColHeaders *bool `xml:"showRowColHeaders,attr"`
170-
ShowZeros bool `xml:"showZeros,attr,omitempty"`
170+
ShowZeros *bool `xml:"showZeros,attr,omitempty"`
171171
RightToLeft bool `xml:"rightToLeft,attr,omitempty"`
172172
TabSelected bool `xml:"tabSelected,attr,omitempty"`
173173
ShowWhiteSpace *bool `xml:"showWhiteSpace,attr"`

0 commit comments

Comments
 (0)