1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
| func main() { f := excelize.NewFile() f.SetSheetName("Sheet1", "Test_Origin")
f.NewSheet("Test")
for i := 1; i <= 10; i++ { f.SetCellValue("Test", "A"+strconv.Itoa(i), strconv.Itoa(i*100)) }
f.SetColWidth("Test", "A", "H", 25)
f.SetRowHeight("Test", 1, 100)
for i := 3; i <= 8; i++ { f.SetRowOutlineLevel("Test", i, 1) }
dvRangeAgent := excelize.NewDataValidation(true) dvRangeAgent.Sqref = "D2:F10" dvRangeAgent.SetSqrefDropList("=Test!$A$1:$A$10") f.AddDataValidation("Test", dvRangeAgent) f.AddDataValidation("Test_Origin", dvRangeAgent)
style, _ := f.NewStyle(&excelize.Style{ Fill: excelize.Fill{Type: "pattern", Color: []string{"#FF0000"}, Pattern: 1}, }) f.SetCellStyle("Test_Origin", "A1", "H10", style)
if err := f.SaveAs("./test.xlsx"); err != nil { fmt.Println(err) return }
return }
|