@@ -38,16 +38,16 @@ import (
3838)
3939
4040func main () {
41- xlsx := excelize.NewFile ()
41+ f := excelize.NewFile ()
4242 // Create a new sheet.
43- index := xlsx .NewSheet (" Sheet2" )
43+ index := f .NewSheet (" Sheet2" )
4444 // Set value of a cell.
45- xlsx .SetCellValue (" Sheet2" , " A2" , " Hello world." )
46- xlsx .SetCellValue (" Sheet1" , " B2" , 100 )
45+ f .SetCellValue (" Sheet2" , " A2" , " Hello world." )
46+ f .SetCellValue (" Sheet1" , " B2" , 100 )
4747 // Set active sheet of the workbook.
48- xlsx .SetActiveSheet (index)
48+ f .SetActiveSheet (index)
4949 // Save xlsx file by the given path.
50- err := xlsx .SaveAs (" ./Book1.xlsx" )
50+ err := f .SaveAs (" ./Book1.xlsx" )
5151 if err != nil {
5252 fmt.Println (err)
5353 }
@@ -68,16 +68,16 @@ import (
6868)
6969
7070func main () {
71- xlsx , err := excelize.OpenFile (" ./Book1.xlsx" )
71+ f , err := excelize.OpenFile (" ./Book1.xlsx" )
7272 if err != nil {
7373 fmt.Println (err)
7474 return
7575 }
7676 // Get value from cell by given worksheet name and axis.
77- cell := xlsx .GetCellValue (" Sheet1" , " B2" )
77+ cell := f .GetCellValue (" Sheet1" , " B2" )
7878 fmt.Println (cell)
7979 // Get all the rows in the Sheet1.
80- rows := xlsx .GetRows (" Sheet1" )
80+ rows , err := f .GetRows (" Sheet1" )
8181 for _ , row := range rows {
8282 for _ , colCell := range row {
8383 fmt.Print (colCell, " \t " )
@@ -105,16 +105,20 @@ import (
105105func main () {
106106 categories := map [string ]string {" A2" : " Small" , " A3" : " Normal" , " A4" : " Large" , " B1" : " Apple" , " C1" : " Orange" , " D1" : " Pear" }
107107 values := map [string ]int {" B2" : 2 , " C2" : 3 , " D2" : 3 , " B3" : 5 , " C3" : 2 , " D3" : 4 , " B4" : 6 , " C4" : 7 , " D4" : 8 }
108- xlsx := excelize.NewFile ()
108+ f := excelize.NewFile ()
109109 for k , v := range categories {
110- xlsx .SetCellValue (" Sheet1" , k, v)
110+ f .SetCellValue (" Sheet1" , k, v)
111111 }
112112 for k , v := range values {
113- xlsx.SetCellValue (" Sheet1" , k, v)
113+ f.SetCellValue (" Sheet1" , k, v)
114+ }
115+ err := f.AddChart (" Sheet1" , " E1" , ` {"type":"col3DClustered","series":[{"name":"Sheet1!$A$2","categories":"Sheet1!$B$1:$D$1","values":"Sheet1!$B$2:$D$2"},{"name":"Sheet1!$A$3","categories":"Sheet1!$B$1:$D$1","values":"Sheet1!$B$3:$D$3"},{"name":"Sheet1!$A$4","categories":"Sheet1!$B$1:$D$1","values":"Sheet1!$B$4:$D$4"}],"title":{"name":"Fruit 3D Clustered Column Chart"}}` )
116+ if err != nil {
117+ fmt.Println (err)
118+ return
114119 }
115- xlsx.AddChart (" Sheet1" , " E1" , ` {"type":"col3DClustered","series":[{"name":"Sheet1!$A$2","categories":"Sheet1!$B$1:$D$1","values":"Sheet1!$B$2:$D$2"},{"name":"Sheet1!$A$3","categories":"Sheet1!$B$1:$D$1","values":"Sheet1!$B$3:$D$3"},{"name":"Sheet1!$A$4","categories":"Sheet1!$B$1:$D$1","values":"Sheet1!$B$4:$D$4"}],"title":{"name":"Fruit 3D Clustered Column Chart"}}` )
116120 // Save xlsx file by the given path.
117- err := xlsx .SaveAs (" ./Book1.xlsx" )
121+ err = f .SaveAs (" ./Book1.xlsx" )
118122 if err != nil {
119123 fmt.Println (err)
120124 }
@@ -136,28 +140,28 @@ import (
136140)
137141
138142func main () {
139- xlsx , err := excelize.OpenFile (" ./Book1.xlsx" )
143+ f , err := excelize.OpenFile (" ./Book1.xlsx" )
140144 if err != nil {
141145 fmt.Println (err)
142146 return
143147 }
144148 // Insert a picture.
145- err = xlsx .AddPicture (" Sheet1" , " A2" , " ./image1.png" , " " )
149+ err = f .AddPicture (" Sheet1" , " A2" , " ./image1.png" , " " )
146150 if err != nil {
147151 fmt.Println (err)
148152 }
149153 // Insert a picture to worksheet with scaling.
150- err = xlsx .AddPicture (" Sheet1" , " D2" , " ./image2.jpg" , ` {"x_scale": 0.5, "y_scale": 0.5}` )
154+ err = f .AddPicture (" Sheet1" , " D2" , " ./image2.jpg" , ` {"x_scale": 0.5, "y_scale": 0.5}` )
151155 if err != nil {
152156 fmt.Println (err)
153157 }
154158 // Insert a picture offset in the cell with printing support.
155- err = xlsx .AddPicture (" Sheet1" , " H2" , " ./image3.gif" , ` {"x_offset": 15, "y_offset": 10, "print_obj": true, "lock_aspect_ratio": false, "locked": false}` )
159+ err = f .AddPicture (" Sheet1" , " H2" , " ./image3.gif" , ` {"x_offset": 15, "y_offset": 10, "print_obj": true, "lock_aspect_ratio": false, "locked": false}` )
156160 if err != nil {
157161 fmt.Println (err)
158162 }
159163 // Save the xlsx file with the origin path.
160- err = xlsx .Save ()
164+ err = f .Save ()
161165 if err != nil {
162166 fmt.Println (err)
163167 }
0 commit comments