瀏覽代碼

Fix structs fields definition errors and keep double quotes in data validation formula

xuri 6 年之前
父節點
當前提交
72701e89c7
共有 2 個文件被更改,包括 47 次插入29 次删除
  1. 4 4
      datavalidation.go
  2. 43 25
      xmlWorksheet.go

+ 4 - 4
datavalidation.go

@@ -112,7 +112,7 @@ func (dd *DataValidation) SetDropList(keys []string) error {
 	if dataValidationFormulaStrLen < len(formula) {
 		return fmt.Errorf(dataValidationFormulaStrLenErr)
 	}
-	dd.Formula1 = formula
+	dd.Formula1 = fmt.Sprintf("<formula1>%s</formula1>", formula)
 	dd.Type = convDataValidationType(typeList)
 	return nil
 }
@@ -121,12 +121,12 @@ func (dd *DataValidation) SetDropList(keys []string) error {
 func (dd *DataValidation) SetRange(f1, f2 int, t DataValidationType, o DataValidationOperator) error {
 	formula1 := fmt.Sprintf("%d", f1)
 	formula2 := fmt.Sprintf("%d", f2)
-	if dataValidationFormulaStrLen < len(dd.Formula1) || dataValidationFormulaStrLen < len(dd.Formula2) {
+	if dataValidationFormulaStrLen+21 < len(dd.Formula1) || dataValidationFormulaStrLen+21 < len(dd.Formula2) {
 		return fmt.Errorf(dataValidationFormulaStrLenErr)
 	}
 
-	dd.Formula1 = formula1
-	dd.Formula2 = formula2
+	dd.Formula1 = fmt.Sprintf("<formula1>%s</formula1>", formula1)
+	dd.Formula2 = fmt.Sprintf("<formula2>%s</formula2>", formula2)
 	dd.Type = convDataValidationType(t)
 	dd.Operator = convDataValidationOperatior(o)
 	return nil

+ 43 - 25
xmlWorksheet.go

@@ -53,23 +53,27 @@ type xlsxDrawing struct {
 // footers on the first page can differ from those on odd- and even-numbered
 // pages. In the latter case, the first page is not considered an odd page.
 type xlsxHeaderFooter struct {
-	DifferentFirst   bool             `xml:"differentFirst,attr,omitempty"`
-	DifferentOddEven bool             `xml:"differentOddEven,attr,omitempty"`
-	OddHeader        []*xlsxOddHeader `xml:"oddHeader"`
-	OddFooter        []*xlsxOddFooter `xml:"oddFooter"`
-}
-
-// xlsxOddHeader directly maps the oddHeader element in the namespace
-// http://schemas.openxmlformats.org/spreadsheetml/2006/main - currently I have
-// not checked it for completeness - it does as much as I need.
-type xlsxOddHeader struct {
-	Content string `xml:",chardata"`
-}
-
-// xlsxOddFooter directly maps the oddFooter element in the namespace
-// http://schemas.openxmlformats.org/spreadsheetml/2006/main - currently I have
-// not checked it for completeness - it does as much as I need.
-type xlsxOddFooter struct {
+	AlignWithMargins bool           `xml:"alignWithMargins,attr,omitempty"`
+	DifferentFirst   bool           `xml:"differentFirst,attr,omitempty"`
+	DifferentOddEven bool           `xml:"differentOddEven,attr,omitempty"`
+	ScaleWithDoc     bool           `xml:"scaleWithDoc,attr,omitempty"`
+	OddHeader        string         `xml:"oddHeader,omitempty"`
+	OddFooter        string         `xml:"oddFooter,omitempty"`
+	EvenHeader       string         `xml:"evenHeader,omitempty"`
+	EvenFooter       string         `xml:"evenFooter,omitempty"`
+	FirstFooter      string         `xml:"firstFooter,omitempty"`
+	FirstHeader      string         `xml:"firstHeader,omitempty"`
+	DrawingHF        *xlsxDrawingHF `xml:"drawingHF"`
+}
+
+// xlsxDrawingHF (Drawing Reference in Header Footer) specifies the usage of
+// drawing objects to be rendered in the headers and footers of the sheet. It
+// specifies an explicit relationship to the part containing the DrawingML
+// shapes used in the headers and footers. It also indicates where in the
+// headers and footers each shape belongs. One drawing object can appear in
+// each of the left section, center section and right section of a header and
+// a footer.
+type xlsxDrawingHF struct {
 	Content string `xml:",chardata"`
 }
 
@@ -324,16 +328,16 @@ type DataValidation struct {
 	Error            *string `xml:"error,attr"`
 	ErrorStyle       *string `xml:"errorStyle,attr"`
 	ErrorTitle       *string `xml:"errorTitle,attr"`
-	Operator         string  `xml:"operator,attr"`
+	Operator         string  `xml:"operator,attr,omitempty"`
 	Prompt           *string `xml:"prompt,attr"`
-	PromptTitle      *string `xml:"promptTitle"`
-	ShowDropDown     bool    `xml:"showDropDown,attr"`
-	ShowErrorMessage bool    `xml:"showErrorMessage,attr"`
-	ShowInputMessage bool    `xml:"showInputMessage,attr"`
+	PromptTitle      *string `xml:"promptTitle,attr"`
+	ShowDropDown     bool    `xml:"showDropDown,attr,omitempty"`
+	ShowErrorMessage bool    `xml:"showErrorMessage,attr,omitempty"`
+	ShowInputMessage bool    `xml:"showInputMessage,attr,omitempty"`
 	Sqref            string  `xml:"sqref,attr"`
 	Type             string  `xml:"type,attr"`
-	Formula1         string  `xml:"formula1"`
-	Formula2         string  `xml:"formula2"`
+	Formula1         string  `xml:",innerxml"`
+	Formula2         string  `xml:",innerxml"`
 }
 
 // xlsxC directly maps the c element in the namespace
@@ -482,7 +486,7 @@ type xlsxIconSet struct {
 type xlsxCfvo struct {
 	Gte    bool        `xml:"gte,attr,omitempty"`
 	Type   string      `xml:"type,attr,omitempty"`
-	Val    string      `xml:"val,attr"`
+	Val    string      `xml:"val,attr,omitempty"`
 	ExtLst *xlsxExtLst `xml:"extLst"`
 }
 
@@ -627,3 +631,17 @@ type FormatSheetProtection struct {
 	SelectUnlockedCells bool
 	Sort                bool
 }
+
+// FormatHeaderFooter directly maps the settings of header and footer.
+type FormatHeaderFooter struct {
+	AlignWithMargins bool
+	DifferentFirst   bool
+	DifferentOddEven bool
+	ScaleWithDoc     bool
+	OddHeader        string
+	OddFooter        string
+	EvenHeader       string
+	EvenFooter       string
+	FirstFooter      string
+	FirstHeader      string
+}