Procházet zdrojové kódy

column and cell support data validation lib issue #380

rentiansheng před 7 roky
rodič
revize
0d4f1ce1c5
2 změnil soubory, kde provedl 62 přidání a 20 odebrání
  1. 16 11
      cell.go
  2. 46 9
      col.go

+ 16 - 11
cell.go

@@ -42,17 +42,18 @@ func (ct CellType) Ptr() *CellType {
 // Cell is a high level structure intended to provide user access to
 // the contents of Cell within an xlsx.Row.
 type Cell struct {
-	Row          *Row
-	Value        string
-	formula      string
-	style        *Style
-	NumFmt       string
-	parsedNumFmt *parsedNumberFormat
-	date1904     bool
-	Hidden       bool
-	HMerge       int
-	VMerge       int
-	cellType     CellType
+	Row            *Row
+	Value          string
+	formula        string
+	style          *Style
+	NumFmt         string
+	parsedNumFmt   *parsedNumberFormat
+	date1904       bool
+	Hidden         bool
+	HMerge         int
+	VMerge         int
+	cellType       CellType
+	DataValidation *xlsxCellDataValidation
 }
 
 // CellInterface defines the public API of the Cell.
@@ -371,3 +372,7 @@ func (c *Cell) FormattedValue() (string, error) {
 	}
 	return returnVal, err
 }
+
+func (c *Cell) SetDataValidation(dd *xlsxCellDataValidation) {
+	c.DataValidation = dd
+}

+ 46 - 9
col.go

@@ -2,17 +2,22 @@ package xlsx
 
 // Default column width in excel
 const ColWidth = 9.5
+const Excel2006MaxRowIndex = 1048576
+const Excel2006MinRowIndex = 1
 
 type Col struct {
-	Min          int
-	Max          int
-	Hidden       bool
-	Width        float64
-	Collapsed    bool
-	OutlineLevel uint8
-	numFmt       string
-	parsedNumFmt *parsedNumberFormat
-	style        *Style
+	Min                 int
+	Max                 int
+	Hidden              bool
+	Width               float64
+	Collapsed           bool
+	OutlineLevel        uint8
+	numFmt              string
+	parsedNumFmt        *parsedNumberFormat
+	style               *Style
+	DataValidation      *xlsxCellDataValidation
+	DataValidationStart int
+	DataValidationEnd   int
 }
 
 // SetType will set the format string of a column based on the type that you want to set it to.
@@ -47,3 +52,35 @@ func (c *Col) GetStyle() *Style {
 func (c *Col) SetStyle(style *Style) {
 	c.style = style
 }
+
+// SetDataValidation set data validation with start,end ; start or end  = 0  equal all column
+func (c *Col) SetDataValidation(dd *xlsxCellDataValidation, start, end int) {
+	//2006 excel all row 1048576
+	if 0 == start {
+		c.DataValidationStart = Excel2006MinRowIndex
+	} else {
+		c.DataValidationStart = start
+	}
+
+	if 0 == end || c.DataValidationEnd > Excel2006MaxRowIndex {
+		c.DataValidationEnd = Excel2006MaxRowIndex
+	} else {
+		c.DataValidationEnd = end
+	}
+	c.DataValidation = dd
+
+}
+
+// SetDataValidationWithStart set data validation with start
+func (c *Col) SetDataValidationWithStart(dd *xlsxCellDataValidation, start int) {
+	//2006 excel all row 1048576
+	if 0 == start {
+		c.DataValidationStart = Excel2006MinRowIndex
+	} else {
+		c.DataValidationStart = start
+	}
+
+	c.DataValidationEnd = Excel2006MaxRowIndex
+	c.DataValidation = dd
+
+}