Skip to content

Commit 72701e8

Browse files
committed
Fix structs fields definition errors and keep double quotes in data validation formula
1 parent 63e97ff commit 72701e8

File tree

2 files changed

+47
-29
lines changed

2 files changed

+47
-29
lines changed

Diff for: datavalidation.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func (dd *DataValidation) SetDropList(keys []string) error {
112112
if dataValidationFormulaStrLen < len(formula) {
113113
return fmt.Errorf(dataValidationFormulaStrLenErr)
114114
}
115-
dd.Formula1 = formula
115+
dd.Formula1 = fmt.Sprintf("<formula1>%s</formula1>", formula)
116116
dd.Type = convDataValidationType(typeList)
117117
return nil
118118
}
@@ -121,12 +121,12 @@ func (dd *DataValidation) SetDropList(keys []string) error {
121121
func (dd *DataValidation) SetRange(f1, f2 int, t DataValidationType, o DataValidationOperator) error {
122122
formula1 := fmt.Sprintf("%d", f1)
123123
formula2 := fmt.Sprintf("%d", f2)
124-
if dataValidationFormulaStrLen < len(dd.Formula1) || dataValidationFormulaStrLen < len(dd.Formula2) {
124+
if dataValidationFormulaStrLen+21 < len(dd.Formula1) || dataValidationFormulaStrLen+21 < len(dd.Formula2) {
125125
return fmt.Errorf(dataValidationFormulaStrLenErr)
126126
}
127127

128-
dd.Formula1 = formula1
129-
dd.Formula2 = formula2
128+
dd.Formula1 = fmt.Sprintf("<formula1>%s</formula1>", formula1)
129+
dd.Formula2 = fmt.Sprintf("<formula2>%s</formula2>", formula2)
130130
dd.Type = convDataValidationType(t)
131131
dd.Operator = convDataValidationOperatior(o)
132132
return nil

Diff for: xmlWorksheet.go

+43-25
Original file line numberDiff line numberDiff line change
@@ -53,23 +53,27 @@ type xlsxDrawing struct {
5353
// footers on the first page can differ from those on odd- and even-numbered
5454
// pages. In the latter case, the first page is not considered an odd page.
5555
type xlsxHeaderFooter struct {
56-
DifferentFirst bool `xml:"differentFirst,attr,omitempty"`
57-
DifferentOddEven bool `xml:"differentOddEven,attr,omitempty"`
58-
OddHeader []*xlsxOddHeader `xml:"oddHeader"`
59-
OddFooter []*xlsxOddFooter `xml:"oddFooter"`
60-
}
61-
62-
// xlsxOddHeader directly maps the oddHeader element in the namespace
63-
// http://schemas.openxmlformats.org/spreadsheetml/2006/main - currently I have
64-
// not checked it for completeness - it does as much as I need.
65-
type xlsxOddHeader struct {
66-
Content string `xml:",chardata"`
67-
}
68-
69-
// xlsxOddFooter directly maps the oddFooter element in the namespace
70-
// http://schemas.openxmlformats.org/spreadsheetml/2006/main - currently I have
71-
// not checked it for completeness - it does as much as I need.
72-
type xlsxOddFooter struct {
56+
AlignWithMargins bool `xml:"alignWithMargins,attr,omitempty"`
57+
DifferentFirst bool `xml:"differentFirst,attr,omitempty"`
58+
DifferentOddEven bool `xml:"differentOddEven,attr,omitempty"`
59+
ScaleWithDoc bool `xml:"scaleWithDoc,attr,omitempty"`
60+
OddHeader string `xml:"oddHeader,omitempty"`
61+
OddFooter string `xml:"oddFooter,omitempty"`
62+
EvenHeader string `xml:"evenHeader,omitempty"`
63+
EvenFooter string `xml:"evenFooter,omitempty"`
64+
FirstFooter string `xml:"firstFooter,omitempty"`
65+
FirstHeader string `xml:"firstHeader,omitempty"`
66+
DrawingHF *xlsxDrawingHF `xml:"drawingHF"`
67+
}
68+
69+
// xlsxDrawingHF (Drawing Reference in Header Footer) specifies the usage of
70+
// drawing objects to be rendered in the headers and footers of the sheet. It
71+
// specifies an explicit relationship to the part containing the DrawingML
72+
// shapes used in the headers and footers. It also indicates where in the
73+
// headers and footers each shape belongs. One drawing object can appear in
74+
// each of the left section, center section and right section of a header and
75+
// a footer.
76+
type xlsxDrawingHF struct {
7377
Content string `xml:",chardata"`
7478
}
7579

@@ -324,16 +328,16 @@ type DataValidation struct {
324328
Error *string `xml:"error,attr"`
325329
ErrorStyle *string `xml:"errorStyle,attr"`
326330
ErrorTitle *string `xml:"errorTitle,attr"`
327-
Operator string `xml:"operator,attr"`
331+
Operator string `xml:"operator,attr,omitempty"`
328332
Prompt *string `xml:"prompt,attr"`
329-
PromptTitle *string `xml:"promptTitle"`
330-
ShowDropDown bool `xml:"showDropDown,attr"`
331-
ShowErrorMessage bool `xml:"showErrorMessage,attr"`
332-
ShowInputMessage bool `xml:"showInputMessage,attr"`
333+
PromptTitle *string `xml:"promptTitle,attr"`
334+
ShowDropDown bool `xml:"showDropDown,attr,omitempty"`
335+
ShowErrorMessage bool `xml:"showErrorMessage,attr,omitempty"`
336+
ShowInputMessage bool `xml:"showInputMessage,attr,omitempty"`
333337
Sqref string `xml:"sqref,attr"`
334338
Type string `xml:"type,attr"`
335-
Formula1 string `xml:"formula1"`
336-
Formula2 string `xml:"formula2"`
339+
Formula1 string `xml:",innerxml"`
340+
Formula2 string `xml:",innerxml"`
337341
}
338342

339343
// xlsxC directly maps the c element in the namespace
@@ -482,7 +486,7 @@ type xlsxIconSet struct {
482486
type xlsxCfvo struct {
483487
Gte bool `xml:"gte,attr,omitempty"`
484488
Type string `xml:"type,attr,omitempty"`
485-
Val string `xml:"val,attr"`
489+
Val string `xml:"val,attr,omitempty"`
486490
ExtLst *xlsxExtLst `xml:"extLst"`
487491
}
488492

@@ -627,3 +631,17 @@ type FormatSheetProtection struct {
627631
SelectUnlockedCells bool
628632
Sort bool
629633
}
634+
635+
// FormatHeaderFooter directly maps the settings of header and footer.
636+
type FormatHeaderFooter struct {
637+
AlignWithMargins bool
638+
DifferentFirst bool
639+
DifferentOddEven bool
640+
ScaleWithDoc bool
641+
OddHeader string
642+
OddFooter string
643+
EvenHeader string
644+
EvenFooter string
645+
FirstFooter string
646+
FirstHeader string
647+
}

0 commit comments

Comments
 (0)