Prechádzať zdrojové kódy

Set cell support column style predefined detection, relate issue #54.

Ri Xu 8 rokov pred
rodič
commit
e41ee8a124
1 zmenil súbory, kde vykonal 17 pridanie a 0 odobranie
  1. 17 0
      excelize.go

+ 17 - 0
excelize.go

@@ -135,10 +135,25 @@ func (f *File) SetCellInt(sheet, axis string, value int) {
 	completeRow(xlsx, rows, cell)
 	completeRow(xlsx, rows, cell)
 	completeCol(xlsx, rows, cell)
 	completeCol(xlsx, rows, cell)
 
 
+	xlsx.SheetData.Row[xAxis].C[yAxis].S = f.prepareCellStyle(xlsx, cell)
 	xlsx.SheetData.Row[xAxis].C[yAxis].T = ""
 	xlsx.SheetData.Row[xAxis].C[yAxis].T = ""
 	xlsx.SheetData.Row[xAxis].C[yAxis].V = strconv.Itoa(value)
 	xlsx.SheetData.Row[xAxis].C[yAxis].V = strconv.Itoa(value)
 }
 }
 
 
+// prepareCellStyle provides function to prepare style index of cell in
+// worksheet by given column index.
+func (f *File) prepareCellStyle(xlsx *xlsxWorksheet, col int) int {
+	s := 0
+	if xlsx.Cols != nil {
+		for _, v := range xlsx.Cols.Col {
+			if v.Min <= col && col <= v.Max {
+				s = v.Style
+			}
+		}
+	}
+	return s
+}
+
 // SetCellStr provides function to set string type value of a cell. Total number
 // SetCellStr provides function to set string type value of a cell. Total number
 // of characters that a cell can contain 32767 characters.
 // of characters that a cell can contain 32767 characters.
 func (f *File) SetCellStr(sheet, axis, value string) {
 func (f *File) SetCellStr(sheet, axis, value string) {
@@ -168,6 +183,7 @@ func (f *File) SetCellStr(sheet, axis, value string) {
 			}
 			}
 		}
 		}
 	}
 	}
+	xlsx.SheetData.Row[xAxis].C[yAxis].S = f.prepareCellStyle(xlsx, cell)
 	xlsx.SheetData.Row[xAxis].C[yAxis].T = "str"
 	xlsx.SheetData.Row[xAxis].C[yAxis].T = "str"
 	xlsx.SheetData.Row[xAxis].C[yAxis].V = value
 	xlsx.SheetData.Row[xAxis].C[yAxis].V = value
 }
 }
@@ -189,6 +205,7 @@ func (f *File) SetCellDefault(sheet, axis, value string) {
 	completeRow(xlsx, rows, cell)
 	completeRow(xlsx, rows, cell)
 	completeCol(xlsx, rows, cell)
 	completeCol(xlsx, rows, cell)
 
 
+	xlsx.SheetData.Row[xAxis].C[yAxis].S = f.prepareCellStyle(xlsx, cell)
 	xlsx.SheetData.Row[xAxis].C[yAxis].T = ""
 	xlsx.SheetData.Row[xAxis].C[yAxis].T = ""
 	xlsx.SheetData.Row[xAxis].C[yAxis].V = value
 	xlsx.SheetData.Row[xAxis].C[yAxis].V = value
 }
 }