Browse Source

Rename xlsxCellDataValidation to xlsxDataValidation

Geoffrey J. Teale 6 năm trước cách đây
mục cha
commit
9589f975db
11 tập tin đã thay đổi với 86 bổ sung86 xóa
  1. 2 2
      cell.go
  2. 42 43
      col.go
  3. 3 3
      col_test.go
  4. 7 7
      data_validation.go
  5. 1 1
      file_test.go
  6. 3 3
      lib.go
  7. 4 4
      sheet.go
  8. 0 0
      sheet_test.go
  9. 1 1
      stream_file_builder.go
  10. 3 2
      xmlStyle.go
  11. 20 20
      xmlWorksheet.go

+ 2 - 2
cell.go

@@ -66,7 +66,7 @@ type Cell struct {
 	HMerge         int
 	VMerge         int
 	cellType       CellType
-	DataValidation *xlsxCellDataValidation
+	DataValidation *xlsxDataValidation
 }
 
 // CellInterface defines the public API of the Cell.
@@ -388,7 +388,7 @@ func (c *Cell) FormattedValue() (string, error) {
 }
 
 // SetDataValidation set data validation
-func (c *Cell) SetDataValidation(dd *xlsxCellDataValidation) {
+func (c *Cell) SetDataValidation(dd *xlsxDataValidation) {
 	c.DataValidation = dd
 }
 

+ 42 - 43
col.go

@@ -18,7 +18,6 @@ type Col struct {
 	numFmt          string
 	parsedNumFmt    *parsedNumberFormat
 	style           *Style
-	DataValidation  []*xlsxCellDataValidation
 	defaultCellType *CellType
 	outXfID         int
 }
@@ -85,50 +84,50 @@ func (c *Col) SetStyle(style *Style) {
 	c.style = style
 }
 
-// SetDataValidation set data validation with zero based start and end.
-// Set end to -1 for all rows.
-func (c *Col) SetDataValidation(dd *xlsxCellDataValidation, start, end int) {
-	if end < 0 {
-		end = Excel2006MaxRowIndex
-	}
-
-	dd.minRow = start
-	dd.maxRow = end
-
-	tmpDD := make([]*xlsxCellDataValidation, 0)
-	for _, item := range c.DataValidation {
-		if item.maxRow < dd.minRow {
-			tmpDD = append(tmpDD, item) //No intersection
-		} else if item.minRow > dd.maxRow {
-			tmpDD = append(tmpDD, item) //No intersection
-		} else if dd.minRow <= item.minRow && dd.maxRow >= item.maxRow {
-			continue //union , item can be ignored
-		} else if dd.minRow >= item.minRow {
-			//Split into three or two, Newly added object, intersect with the current object in the lower half
-			tmpSplit := new(xlsxCellDataValidation)
-			*tmpSplit = *item
-
-			if dd.minRow > item.minRow { //header whetherneed to split
-				item.maxRow = dd.minRow - 1
-				tmpDD = append(tmpDD, item)
-			}
-			if dd.maxRow < tmpSplit.maxRow { //footer whetherneed to split
-				tmpSplit.minRow = dd.maxRow + 1
-				tmpDD = append(tmpDD, tmpSplit)
-			}
-
-		} else {
-			item.minRow = dd.maxRow + 1
-			tmpDD = append(tmpDD, item)
-		}
-	}
-	tmpDD = append(tmpDD, dd)
-	c.DataValidation = tmpDD
-}
+// // SetDataValidation set data validation with zero based start and end.
+// // Set end to -1 for all rows.
+// func (c *Col) SetDataValidation(dd *xlsxDataValidation, start, end int) {
+// 	if end < 0 {
+// 		end = Excel2006MaxRowIndex
+// 	}
+
+// 	dd.minRow = start
+// 	dd.maxRow = end
+
+// 	tmpDD := make([]*xlsxDataValidation, 0)
+// 	for _, item := range c.DataValidation {
+// 		if item.maxRow < dd.minRow {
+// 			tmpDD = append(tmpDD, item) //No intersection
+// 		} else if item.minRow > dd.maxRow {
+// 			tmpDD = append(tmpDD, item) //No intersection
+// 		} else if dd.minRow <= item.minRow && dd.maxRow >= item.maxRow {
+// 			continue //union , item can be ignored
+// 		} else if dd.minRow >= item.minRow {
+// 			//Split into three or two, Newly added object, intersect with the current object in the lower half
+// 			tmpSplit := new(xlsxDataValidation)
+// 			*tmpSplit = *item
+
+// 			if dd.minRow > item.minRow { //header whetherneed to split
+// 				item.maxRow = dd.minRow - 1
+// 				tmpDD = append(tmpDD, item)
+// 			}
+// 			if dd.maxRow < tmpSplit.maxRow { //footer whetherneed to split
+// 				tmpSplit.minRow = dd.maxRow + 1
+// 				tmpDD = append(tmpDD, tmpSplit)
+// 			}
+
+// 		} else {
+// 			item.minRow = dd.maxRow + 1
+// 			tmpDD = append(tmpDD, item)
+// 		}
+// 	}
+// 	tmpDD = append(tmpDD, dd)
+// 	c.DataValidation = tmpDD
+// }
 
 // SetDataValidationWithStart set data validation with a zero basd start row.
 // This will apply to the rest of the rest of the column.
-func (c *Col) SetDataValidationWithStart(dd *xlsxCellDataValidation, start int) {
+func (c *Col) SetDataValidationWithStart(dd *xlsxDataValidation, start int) {
 	c.SetDataValidation(dd, start, -1)
 }
 
@@ -168,7 +167,7 @@ func (c *Col) copyToRange(min, max int) *Col {
 		numFmt:          c.numFmt,
 		parsedNumFmt:    c.parsedNumFmt,
 		style:           c.style,
-		DataValidation:  append([]*xlsxCellDataValidation{}, c.DataValidation...),
+		DataValidation:  append([]*xlsxDataValidation{}, c.DataValidation...),
 		defaultCellType: c.defaultCellType,
 	}
 }

+ 3 - 3
col_test.go

@@ -55,8 +55,8 @@ func TestCol(t *testing.T) {
 	c.Run("copyToRange", func(c *qt.C) {
 		nf := &parsedNumberFormat{}
 		s := &Style{}
-		cdv1 := &xlsxCellDataValidation{}
-		cdv2 := &xlsxCellDataValidation{}
+		cdv1 := &xlsxDataValidation{}
+		cdv2 := &xlsxDataValidation{}
 		ct := CellTypeBool.Ptr()
 		c1 := &Col{
 			Min:             1,
@@ -68,7 +68,7 @@ func TestCol(t *testing.T) {
 			numFmt:          "-0.00",
 			parsedNumFmt:    nf,
 			style:           s,
-			DataValidation:  []*xlsxCellDataValidation{cdv1, cdv2},
+			DataValidation:  []*xlsxDataValidation{cdv1, cdv2},
 			defaultCellType: ct,
 		}
 

+ 7 - 7
data_validation.go

@@ -62,14 +62,14 @@ const (
 )
 
 // NewXlsxCellDataValidation return data validation struct
-func NewXlsxCellDataValidation(allowBlank bool) *xlsxCellDataValidation {
-	return &xlsxCellDataValidation{
+func NewXlsxCellDataValidation(allowBlank bool) *xlsxDataValidation {
+	return &xlsxDataValidation{
 		AllowBlank: allowBlank,
 	}
 }
 
 // SetError set error notice
-func (dd *xlsxCellDataValidation) SetError(style DataValidationErrorStyle, title, msg *string) {
+func (dd *xlsxDataValidation) SetError(style DataValidationErrorStyle, title, msg *string) {
 	dd.ShowErrorMessage = true
 	dd.Error = msg
 	dd.ErrorTitle = title
@@ -87,7 +87,7 @@ func (dd *xlsxCellDataValidation) SetError(style DataValidationErrorStyle, title
 }
 
 // SetInput set prompt notice
-func (dd *xlsxCellDataValidation) SetInput(title, msg *string) {
+func (dd *xlsxDataValidation) SetInput(title, msg *string) {
 	dd.ShowInputMessage = true
 	dd.PromptTitle = title
 	dd.Prompt = msg
@@ -95,7 +95,7 @@ func (dd *xlsxCellDataValidation) SetInput(title, msg *string) {
 
 // SetDropList sets a hard coded list of values that the drop down will choose from.
 // List validations do not work in Apple Numbers.
-func (dd *xlsxCellDataValidation) SetDropList(keys []string) error {
+func (dd *xlsxDataValidation) SetDropList(keys []string) error {
 	formula := "\"" + strings.Join(keys, ",") + "\""
 	if dataValidationFormulaStrLen < len(formula) {
 		return fmt.Errorf(dataValidationFormulaStrLenErr)
@@ -111,7 +111,7 @@ func (dd *xlsxCellDataValidation) SetDropList(keys []string) error {
 // column will cause Google Sheets to spin indefinitely while trying to load the possible drop down
 // values (more than 5 minutes).
 // List validations do not work in Apple Numbers.
-func (dd *xlsxCellDataValidation) SetInFileList(sheet string, x1, y1, x2, y2 int) error {
+func (dd *xlsxDataValidation) SetInFileList(sheet string, x1, y1, x2, y2 int) error {
 	start := GetCellIDStringFromCoordsWithFixed(x1, y1, true, true)
 	if y2 < 0 {
 		y2 = Excel2006MaxRowIndex
@@ -128,7 +128,7 @@ func (dd *xlsxCellDataValidation) SetInFileList(sheet string, x1, y1, x2, y2 int
 }
 
 // SetDropList data validation range
-func (dd *xlsxCellDataValidation) SetRange(f1, f2 int, t DataValidationType, o DataValidationOperator) error {
+func (dd *xlsxDataValidation) SetRange(f1, f2 int, t DataValidationType, o DataValidationOperator) error {
 	formula1 := fmt.Sprintf("%d", f1)
 	formula2 := fmt.Sprintf("%d", f2)
 

+ 1 - 1
file_test.go

@@ -847,7 +847,7 @@ func (l *FileSuite) TestMarshalFile(c *C) {
 	// For now we only allow simple string data in the
 	// spreadsheet.  Style support will follow.
 	expectedStyles := `<?xml version="1.0" encoding="UTF-8"?>
-<styleSheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"><borders count="1"><border><left style="none"></left><right style="none"></right><top style="none"></top><bottom style="none"></bottom></border></borders><cellXfs count="1"><xf applyAlignment="0" applyBorder="0" applyFont="0" applyFill="0" applyNumberFormat="0" applyProtection="0" borderId="0" fillId="0" fontId="0" numFmtId="0"><alignment horizontal="general" indent="0" shrinkToFit="0" textRotation="0" vertical="bottom" wrapText="0"/></xf></cellXfs></styleSheet>`
+<styleSheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"><borders count="1"><border><left style="none"></left><right style="none"></right><top style="none"></top><bottom style="none"></bottom></border></borders><cellStyleXfs count="1"><xf applyAlignment="0" applyBorder="0" applyFont="0" applyFill="0" applyNumberFormat="0" applyProtection="0" borderId="0" fillId="0" fontId="0" numFmtId="0"><alignment horizontal="general" indent="0" shrinkToFit="0" textRotation="0" vertical="bottom" wrapText="0"/></xf></cellStyleXfs><cellXfs count="1"><xf applyAlignment="0" applyBorder="0" applyFont="0" applyFill="0" applyNumberFormat="0" applyProtection="0" borderId="0" fillId="0" fontId="0" numFmtId="0"><alignment horizontal="general" indent="0" shrinkToFit="0" textRotation="0" vertical="bottom" wrapText="0"/></xf></cellXfs></styleSheet>`
 
 	c.Assert(parts["xl/styles.xml"], Equals, expectedStyles)
 }

+ 3 - 3
lib.go

@@ -735,14 +735,14 @@ func readSheetFromFile(sc chan *indexedSheet, index int, rsheet xlsxSheet, fi *F
 					}
 
 					if minCol == maxCol && minRow == maxRow {
-						newDD := new(xlsxCellDataValidation)
+						newDD := new(xlsxDataValidation)
 						*newDD = *dd
 						newDD.Sqref = ""
 						sheet.Cell(minRow, minCol).SetDataValidation(newDD)
 					} else {
 						// one col mutli dd , error todo
 						for i := minCol; i <= maxCol; i++ {
-							newDD := new(xlsxCellDataValidation)
+							newDD := new(xlsxDataValidation)
 							*newDD = *dd
 							newDD.Sqref = ""
 							sheet.Col(i).SetDataValidation(dd, minRow, maxRow)
@@ -750,7 +750,7 @@ func readSheetFromFile(sc chan *indexedSheet, index int, rsheet xlsxSheet, fi *F
 
 					}
 				} else {
-					newDD := new(xlsxCellDataValidation)
+					newDD := new(xlsxDataValidation)
 					*newDD = *dd
 					newDD.Sqref = ""
 					sheet.Cell(minRow, minCol).SetDataValidation(dd)

+ 4 - 4
sheet.go

@@ -197,14 +197,14 @@ func (s *Sheet) SetColWidth(min, max int, width float64) {
 }
 
 // Set the data validation for a range of columns.
-func (s *Sheet) SetDataValidation(minCol, maxCol int, dd *xlsxCellDataValidation, minRow, maxRow int) {
+func (s *Sheet) SetDataValidation(minCol, maxCol int, dd *xlsxDataValidation, minRow, maxRow int) {
 	s.setCol(minCol, maxCol, func(col *Col) {
 		col.SetDataValidation(dd, minRow, maxRow)
 	})
 }
 
 // Set the data validation for a range of columns.
-func (s *Sheet) SetDataValidationWithStart(minCol, maxCol int, dd *xlsxCellDataValidation, start int) {
+func (s *Sheet) SetDataValidationWithStart(minCol, maxCol int, dd *xlsxDataValidation, start int) {
 	s.setCol(minCol, maxCol, func(col *Col) {
 		col.SetDataValidation(dd, start, -1)
 	})
@@ -343,7 +343,7 @@ func (s *Sheet) makeCols(worksheet *xlsxWorksheet, styles *xlsxStyleSheet) (maxL
 			}
 			if nil != col.DataValidation {
 				if nil == worksheet.DataValidations {
-					worksheet.DataValidations = &xlsxCellDataValidations{}
+					worksheet.DataValidations = &xlsxDataValidations{}
 				}
 				colName := ColIndexToLetters(c)
 				for _, dd := range col.DataValidation {
@@ -447,7 +447,7 @@ func (s *Sheet) makeRows(worksheet *xlsxWorksheet, styles *xlsxStyleSheet, refTa
 			xRow.C = append(xRow.C, xC)
 			if nil != cell.DataValidation {
 				if nil == worksheet.DataValidations {
-					worksheet.DataValidations = &xlsxCellDataValidations{}
+					worksheet.DataValidations = &xlsxDataValidations{}
 				}
 				cell.DataValidation.Sqref = xC.R
 				worksheet.DataValidations.DataValidation = append(worksheet.DataValidations.DataValidation, cell.DataValidation)

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 0 - 0
sheet_test.go


+ 1 - 1
stream_file_builder.go

@@ -228,7 +228,7 @@ func (sb *StreamFileBuilder) AddSheetS(name string, columnStyles []StreamStyle)
 }
 
 // AddValidation will add a validation to a specific column.
-func (sb *StreamFileBuilder) AddValidation(sheetIndex, colIndex, rowStartIndex int, validation *xlsxCellDataValidation) {
+func (sb *StreamFileBuilder) AddValidation(sheetIndex, colIndex, rowStartIndex int, validation *xlsxDataValidation) {
 	sheet := sb.xlsxFile.Sheets[sheetIndex]
 	column := sheet.Col(colIndex)
 	column.SetDataValidationWithStart(validation, rowStartIndex)

+ 3 - 2
xmlStyle.go

@@ -130,9 +130,10 @@ func (styles *xlsxStyleSheet) reset() {
 			Bottom: xlsxLine{Style: "none"},
 		})
 
-	styles.CellStyleXfs = &xlsxCellStyleXfs{}
+	// add 0th CellStyleXf by default, as required by the standard
+	styles.CellStyleXfs = &xlsxCellStyleXfs{Count: 1, Xf: []xlsxXf{{}}}
 
-	// add default xf
+	// add 0th CellXf by default, as required by the standard
 	styles.CellXfs = xlsxCellXfs{Count: 1, Xf: []xlsxXf{{}}}
 	styles.NumFmts = xlsxNumFmts{}
 }

+ 20 - 20
xmlWorksheet.go

@@ -10,20 +10,20 @@ import (
 // currently I have not checked it for completeness - it does as much
 // as I need.
 type xlsxWorksheet struct {
-	XMLName         xml.Name                 `xml:"http://schemas.openxmlformats.org/spreadsheetml/2006/main worksheet"`
-	SheetPr         xlsxSheetPr              `xml:"sheetPr"`
-	Dimension       xlsxDimension            `xml:"dimension"`
-	SheetViews      xlsxSheetViews           `xml:"sheetViews"`
-	SheetFormatPr   xlsxSheetFormatPr        `xml:"sheetFormatPr"`
-	Cols            *xlsxCols                `xml:"cols,omitempty"`
-	SheetData       xlsxSheetData            `xml:"sheetData"`
-	DataValidations *xlsxCellDataValidations `xml:"dataValidations"`
-	AutoFilter      *xlsxAutoFilter          `xml:"autoFilter,omitempty"`
-	MergeCells      *xlsxMergeCells          `xml:"mergeCells,omitempty"`
-	PrintOptions    xlsxPrintOptions         `xml:"printOptions"`
-	PageMargins     xlsxPageMargins          `xml:"pageMargins"`
-	PageSetUp       xlsxPageSetUp            `xml:"pageSetup"`
-	HeaderFooter    xlsxHeaderFooter         `xml:"headerFooter"`
+	XMLName         xml.Name             `xml:"http://schemas.openxmlformats.org/spreadsheetml/2006/main worksheet"`
+	SheetPr         xlsxSheetPr          `xml:"sheetPr"`
+	Dimension       xlsxDimension        `xml:"dimension"`
+	SheetViews      xlsxSheetViews       `xml:"sheetViews"`
+	SheetFormatPr   xlsxSheetFormatPr    `xml:"sheetFormatPr"`
+	Cols            *xlsxCols            `xml:"cols,omitempty"`
+	SheetData       xlsxSheetData        `xml:"sheetData"`
+	DataValidations *xlsxDataValidations `xml:"dataValidations"`
+	AutoFilter      *xlsxAutoFilter      `xml:"autoFilter,omitempty"`
+	MergeCells      *xlsxMergeCells      `xml:"mergeCells,omitempty"`
+	PrintOptions    xlsxPrintOptions     `xml:"printOptions"`
+	PageMargins     xlsxPageMargins      `xml:"pageMargins"`
+	PageSetUp       xlsxPageSetUp        `xml:"pageSetup"`
+	HeaderFooter    xlsxHeaderFooter     `xml:"headerFooter"`
 }
 
 // xlsxHeaderFooter directly maps the headerFooter element in the namespace
@@ -226,16 +226,16 @@ type xlsxSheetData struct {
 	Row     []xlsxRow `xml:"row"`
 }
 
-// xlsxCellDataValidations  excel cell data validation
-type xlsxCellDataValidations struct {
-	DataValidation []*xlsxCellDataValidation `xml:"dataValidation"`
-	Count          int                       `xml:"count,attr"`
+// xlsxDataValidations  excel cell data validation
+type xlsxDataValidations struct {
+	DataValidation []*xlsxDataValidation `xml:"dataValidation"`
+	Count          int                   `xml:"count,attr"`
 }
 
-// xlsxCellDataValidation
+// xlsxDataValidation
 // A single item of data validation defined on a range of the worksheet.
 // The list validation type would more commonly be called "a drop down box."
-type xlsxCellDataValidation struct {
+type xlsxDataValidation struct {
 	// A boolean value indicating whether the data validation allows the use of empty or blank
 	//entries. 1 means empty entries are OK and do not violate the validation constraints.
 	AllowBlank bool `xml:"allowBlank,attr,omitempty"`

Một số tệp đã không được hiển thị bởi vì quá nhiều tập tin thay đổi trong này khác