Browse Source

Change some strings to bools

Ryan Hollis 6 years ago
parent
commit
5ba9a951f9
2 changed files with 10 additions and 18 deletions
  1. 3 11
      datavalidation.go
  2. 7 7
      xmlWorksheet.go

+ 3 - 11
datavalidation.go

@@ -64,9 +64,9 @@ const (
 // NewXlsxCellDataValidation return data validation struct
 func NewXlsxCellDataValidation(allowBlank, ShowInputMessage, showErrorMessage bool) *xlsxCellDataValidation {
 	return &xlsxCellDataValidation{
-		AllowBlank:       convBoolToStr(allowBlank),
-		ShowErrorMessage: convBoolToStr(showErrorMessage),
-		ShowInputMessage: convBoolToStr(ShowInputMessage),
+		AllowBlank:       allowBlank,
+		ShowErrorMessage: showErrorMessage,
+		ShowInputMessage: ShowInputMessage,
 	}
 }
 
@@ -131,14 +131,6 @@ func (dd *xlsxCellDataValidation) SetRange(f1, f2 int, t DataValidationType, o D
 	return nil
 }
 
-// convBoolToStr  convert boolean to string , false to 0, true to 1
-func convBoolToStr(bl bool) string {
-	if bl {
-		return "1"
-	}
-	return "0"
-}
-
 // convDataValidationType get excel data validation type
 func convDataValidationType(t DataValidationType) string {
 	typeMap := map[DataValidationType]string{

+ 7 - 7
xmlWorksheet.go

@@ -232,19 +232,19 @@ type xlsxCellDataValidations struct {
 
 // xlsxCellDataValidation single data validation
 type xlsxCellDataValidation struct {
-	AllowBlank       string  `xml:"allowBlank,attr"`         // allow empty
-	ShowInputMessage string  `xml:"showInputMessage,attr"`   // 1, true,0,false,  select cell,  Whether the input message is displayed
-	ShowErrorMessage string  `xml:"showErrorMessage,attr"`   // 1, true,0,false,  input error value, Whether the error message is displayed
+	AllowBlank       bool    `xml:"allowBlank,attr"`         // allow empty
+	ShowInputMessage bool    `xml:"showInputMessage,attr"`   // 1, true,0,false,  select cell,  Whether the input message is displayed
+	ShowErrorMessage bool    `xml:"showErrorMessage,attr"`   // 1, true,0,false,  input error value, Whether the error message is displayed
 	ErrorStyle       *string `xml:"errorStyle,attr"`         //error icon style, warning, infomation,stop
 	ErrorTitle       *string `xml:"errorTitle,attr"`         // error title
 	Operator         string  `xml:"operator,attr,omitempty"` //
 	Error            *string `xml:"error,attr"`              // input error value,  notice message
 	PromptTitle      *string `xml:"promptTitle,attr"`
 	Prompt           *string `xml:"prompt,attr"`
-	Type             string  `xml:"type,attr"`  //data type, none,custom,date,decimal,list, textLength,time,whole
-	Sqref            string  `xml:"sqref,attr"` //Validity of data validation rules, cell and range, eg: A1 OR A1:A20
-	Formula1         string  `xml:"formula1"`   // data validation role
-	Formula2         string  `xml:"formula2"`   //data validation role
+	Type             string  `xml:"type,attr"`            //data type, none,custom,date,decimal,list, textLength,time,whole
+	Sqref            string  `xml:"sqref,attr,omitempty"` //Validity of data validation rules, cell and range, eg: A1 OR A1:A20
+	Formula1         string  `xml:"formula1"`             // data validation role
+	Formula2         string  `xml:"formula2,omitempty"`   //data validation role
 	minRow           int     //`xml:"-"`
 	maxRow           int     //`xml:"-"`
 	//minCol         int     `xml:"-"` //spare