Skip to content

Commit 0660f30

Browse files
committed
godoc update and typo fixed
1 parent 0f9170a commit 0660f30

File tree

13 files changed

+155
-145
lines changed

13 files changed

+155
-145
lines changed

README.md

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,16 @@ import (
3838
)
3939

4040
func 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

7070
func 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 (
105105
func 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

138142
func 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
}

README_zh.md

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,16 @@ import (
3737
)
3838

3939
func main() {
40-
xlsx := excelize.NewFile()
40+
f := excelize.NewFile()
4141
// 创建一个工作表
42-
index := xlsx.NewSheet("Sheet2")
42+
index := f.NewSheet("Sheet2")
4343
// 设置单元格的值
44-
xlsx.SetCellValue("Sheet2", "A2", "Hello world.")
45-
xlsx.SetCellValue("Sheet1", "B2", 100)
44+
f.SetCellValue("Sheet2", "A2", "Hello world.")
45+
f.SetCellValue("Sheet1", "B2", 100)
4646
// 设置工作簿的默认工作表
47-
xlsx.SetActiveSheet(index)
47+
f.SetActiveSheet(index)
4848
// 根据指定路径保存文件
49-
err := xlsx.SaveAs("./Book1.xlsx")
49+
err := f.SaveAs("./Book1.xlsx")
5050
if err != nil {
5151
fmt.Println(err)
5252
}
@@ -67,16 +67,16 @@ import (
6767
)
6868

6969
func main() {
70-
xlsx, err := excelize.OpenFile("./Book1.xlsx")
70+
f, err := excelize.OpenFile("./Book1.xlsx")
7171
if err != nil {
7272
fmt.Println(err)
7373
return
7474
}
7575
// 获取工作表中指定单元格的值
76-
cell := xlsx.GetCellValue("Sheet1", "B2")
76+
cell := f.GetCellValue("Sheet1", "B2")
7777
fmt.Println(cell)
7878
// 获取 Sheet1 上所有单元格
79-
rows := xlsx.GetRows("Sheet1")
79+
rows, err := f.GetRows("Sheet1")
8080
for _, row := range rows {
8181
for _, colCell := range row {
8282
fmt.Print(colCell, "\t")
@@ -104,16 +104,20 @@ import (
104104
func main() {
105105
categories := map[string]string{"A2": "Small", "A3": "Normal", "A4": "Large", "B1": "Apple", "C1": "Orange", "D1": "Pear"}
106106
values := map[string]int{"B2": 2, "C2": 3, "D2": 3, "B3": 5, "C3": 2, "D3": 4, "B4": 6, "C4": 7, "D4": 8}
107-
xlsx := excelize.NewFile()
107+
f := excelize.NewFile()
108108
for k, v := range categories {
109-
xlsx.SetCellValue("Sheet1", k, v)
109+
f.SetCellValue("Sheet1", k, v)
110110
}
111111
for k, v := range values {
112-
xlsx.SetCellValue("Sheet1", k, v)
112+
f.SetCellValue("Sheet1", k, v)
113+
}
114+
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"}}`)
115+
if err != nil {
116+
fmt.Println(err)
117+
return
113118
}
114-
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"}}`)
115119
// 根据指定路径保存文件
116-
err := xlsx.SaveAs("./Book1.xlsx")
120+
err = f.SaveAs("./Book1.xlsx")
117121
if err != nil {
118122
fmt.Println(err)
119123
}
@@ -136,28 +140,28 @@ import (
136140
)
137141

138142
func 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
// 插入图片
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
// 在工作表中插入图片,并设置图片的缩放比例
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
// 在工作表中插入图片,并设置图片的打印属性
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
// 保存文件
160-
err = xlsx.Save()
164+
err = f.Save()
161165
if err != nil {
162166
fmt.Println(err)
163167
}

cell.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ func (f *File) SetCellFormula(sheet, axis, formula string) error {
304304
// the value of link will be false and the value of the target will be a blank
305305
// string. For example get hyperlink of Sheet1!H6:
306306
//
307-
// link, target, err := xlsx.GetCellHyperLink("Sheet1", "H6")
307+
// link, target, err := f.GetCellHyperLink("Sheet1", "H6")
308308
//
309309
func (f *File) GetCellHyperLink(sheet, axis string) (bool, string, error) {
310310
// Check for correct cell name
@@ -338,14 +338,14 @@ func (f *File) GetCellHyperLink(sheet, axis string) (bool, string, error) {
338338
// hyperlink "External" for web site or "Location" for moving to one of cell
339339
// in this workbook. The below is example for external link.
340340
//
341-
// err := xlsx.SetCellHyperLink("Sheet1", "A3", "https://github.com/360EntSecGroup-Skylar/excelize", "External")
341+
// err := f.SetCellHyperLink("Sheet1", "A3", "https://github.com/360EntSecGroup-Skylar/excelize", "External")
342342
// // Set underline and font color style for the cell.
343-
// style, err := xlsx.NewStyle(`{"font":{"color":"#1265BE","underline":"single"}}`)
344-
// err = xlsx.SetCellStyle("Sheet1", "A3", "A3", style)
343+
// style, err := f.NewStyle(`{"font":{"color":"#1265BE","underline":"single"}}`)
344+
// err = f.SetCellStyle("Sheet1", "A3", "A3", style)
345345
//
346346
// A this is another example for "Location":
347347
//
348-
// err := xlsx.SetCellHyperLink("Sheet1", "A3", "Sheet1!A40", "Location")
348+
// err := f.SetCellHyperLink("Sheet1", "A3", "Sheet1!A40", "Location")
349349
//
350350
func (f *File) SetCellHyperLink(sheet, axis, link, linkType string) error {
351351
// Check for correct cell name
@@ -390,7 +390,7 @@ func (f *File) SetCellHyperLink(sheet, axis, link, linkType string) error {
390390
// MergeCell provides a function to merge cells by given coordinate area and
391391
// sheet name. For example create a merged cell of D3:E9 on Sheet1:
392392
//
393-
// err := xlsx.MergeCell("Sheet1", "D3", "E9")
393+
// err := f.MergeCell("Sheet1", "D3", "E9")
394394
//
395395
// If you create a merged cell that overlaps with another existing merged cell,
396396
// those merged cells that already exist will be removed.
@@ -452,7 +452,7 @@ func (f *File) MergeCell(sheet, hcell, vcell string) error {
452452
// coordinate and a pointer to array type 'slice'. For example, writes an
453453
// array to row 6 start with the cell B6 on Sheet1:
454454
//
455-
// err := xlsx.SetSheetRow("Sheet1", "B6", &[]interface{}{"1", nil, 2})
455+
// err := f.SetSheetRow("Sheet1", "B6", &[]interface{}{"1", nil, 2})
456456
//
457457
func (f *File) SetSheetRow(sheet, axis string, slice interface{}) error {
458458
col, row, err := CellNameToCoordinates(axis)

col.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const (
2222
// worksheet name and column name. For example, get visible state of column D
2323
// in Sheet1:
2424
//
25-
// visiable, err := xlsx.GetColVisible("Sheet1", "D")
25+
// visiable, err := f.GetColVisible("Sheet1", "D")
2626
//
2727
func (f *File) GetColVisible(sheet, col string) (bool, error) {
2828
visible := true
@@ -51,7 +51,7 @@ func (f *File) GetColVisible(sheet, col string) (bool, error) {
5151
// SetColVisible provides a function to set visible of a single column by given
5252
// worksheet name and column name. For example, hide column D in Sheet1:
5353
//
54-
// err := xlsx.SetColVisible("Sheet1", "D", false)
54+
// err := f.SetColVisible("Sheet1", "D", false)
5555
//
5656
func (f *File) SetColVisible(sheet, col string, visible bool) error {
5757
colNum, err := ColumnNameToNumber(col)
@@ -91,7 +91,7 @@ func (f *File) SetColVisible(sheet, col string, visible bool) error {
9191
// column by given worksheet name and column name. For example, get outline
9292
// level of column D in Sheet1:
9393
//
94-
// level, err := xlsx.GetColOutlineLevel("Sheet1", "D")
94+
// level, err := f.GetColOutlineLevel("Sheet1", "D")
9595
//
9696
func (f *File) GetColOutlineLevel(sheet, col string) (uint8, error) {
9797
level := uint8(0)
@@ -119,7 +119,7 @@ func (f *File) GetColOutlineLevel(sheet, col string) (uint8, error) {
119119
// column by given worksheet name and column name. For example, set outline
120120
// level of column D in Sheet1 to 2:
121121
//
122-
// err := xlsx.SetColOutlineLevel("Sheet1", "D", 2)
122+
// err := f.SetColOutlineLevel("Sheet1", "D", 2)
123123
//
124124
func (f *File) SetColOutlineLevel(sheet, col string, level uint8) error {
125125
colNum, err := ColumnNameToNumber(col)
@@ -158,8 +158,8 @@ func (f *File) SetColOutlineLevel(sheet, col string, level uint8) error {
158158
// SetColWidth provides a function to set the width of a single column or
159159
// multiple columns. For example:
160160
//
161-
// xlsx := excelize.NewFile()
162-
// err := xlsx.SetColWidth("Sheet1", "A", "H", 20)
161+
// f := excelize.NewFile()
162+
// err := f.SetColWidth("Sheet1", "A", "H", 20)
163163
//
164164
func (f *File) SetColWidth(sheet, startcol, endcol string, width float64) error {
165165
min, err := ColumnNameToNumber(startcol)
@@ -348,7 +348,7 @@ func (f *File) GetColWidth(sheet, col string) (float64, error) {
348348
// InsertCol provides a function to insert a new column before given column
349349
// index. For example, create a new column before column C in Sheet1:
350350
//
351-
// err := xlsx.InsertCol("Sheet1", "C")
351+
// err := f.InsertCol("Sheet1", "C")
352352
//
353353
func (f *File) InsertCol(sheet, col string) error {
354354
num, err := ColumnNameToNumber(col)
@@ -361,7 +361,7 @@ func (f *File) InsertCol(sheet, col string) error {
361361
// RemoveCol provides a function to remove single column by given worksheet
362362
// name and column index. For example, remove column C in Sheet1:
363363
//
364-
// err := xlsx.RemoveCol("Sheet1", "C")
364+
// err := f.RemoveCol("Sheet1", "C")
365365
//
366366
// Use this method with caution, which will affect changes in references such
367367
// as formulas, charts, and so on. If there is any referenced value of the

datavalidation.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ func (dd *DataValidation) SetRange(f1, f2 int, t DataValidationType, o DataValid
142142
// dvRange := excelize.NewDataValidation(true)
143143
// dvRange.Sqref = "A7:B8"
144144
// dvRange.SetSqrefDropList("E1:E3", true)
145-
// xlsx.AddDataValidation("Sheet1", dvRange)
145+
// f.AddDataValidation("Sheet1", dvRange)
146146
//
147147
func (dd *DataValidation) SetSqrefDropList(sqref string, isCurrentSheet bool) error {
148148
if isCurrentSheet {
@@ -208,7 +208,7 @@ func convDataValidationOperatior(o DataValidationOperator) string {
208208
// dvRange.Sqref = "A1:B2"
209209
// dvRange.SetRange(10, 20, excelize.DataValidationTypeWhole, excelize.DataValidationOperatorBetween)
210210
// dvRange.SetError(excelize.DataValidationErrorStyleStop, "error title", "error body")
211-
// err := xlsx.AddDataValidation("Sheet1", dvRange)
211+
// err := f.AddDataValidation("Sheet1", dvRange)
212212
//
213213
// Example 2, set data validation on Sheet1!A3:B4 with validation criteria
214214
// settings, and show input message when cell is selected:
@@ -217,15 +217,15 @@ func convDataValidationOperatior(o DataValidationOperator) string {
217217
// dvRange.Sqref = "A3:B4"
218218
// dvRange.SetRange(10, 20, excelize.DataValidationTypeWhole, excelize.DataValidationOperatorGreaterThan)
219219
// dvRange.SetInput("input title", "input body")
220-
// err = xlsx.AddDataValidation("Sheet1", dvRange)
220+
// err = f.AddDataValidation("Sheet1", dvRange)
221221
//
222222
// Example 3, set data validation on Sheet1!A5:B6 with validation criteria
223223
// settings, create in-cell dropdown by allowing list source:
224224
//
225225
// dvRange = excelize.NewDataValidation(true)
226226
// dvRange.Sqref = "A5:B6"
227227
// dvRange.SetDropList([]string{"1", "2", "3"})
228-
// err = xlsx.AddDataValidation("Sheet1", dvRange)
228+
// err = f.AddDataValidation("Sheet1", dvRange)
229229
//
230230
func (f *File) AddDataValidation(sheet string, dv *DataValidation) error {
231231
xlsx, err := f.workSheetReader(sheet)

excelize.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,8 @@ func (f *File) UpdateLinkedValue() error {
216216
return nil
217217
}
218218

219-
// GetMergeCells provides a function to get all merged cells from a worksheet currently.
219+
// GetMergeCells provides a function to get all merged cells from a worksheet
220+
// currently.
220221
func (f *File) GetMergeCells(sheet string) ([]MergeCell, error) {
221222
var mergeCells []MergeCell
222223
xlsx, err := f.workSheetReader(sheet)

0 commit comments

Comments
 (0)