Skip to content

Commit

Permalink
godoc update and typo fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
xuri committed Apr 20, 2019
1 parent 0f9170a commit 0660f30
Show file tree
Hide file tree
Showing 13 changed files with 155 additions and 145 deletions.
42 changes: 23 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,16 @@ import (
)

func main() {
xlsx := excelize.NewFile()
f := excelize.NewFile()
// Create a new sheet.
index := xlsx.NewSheet("Sheet2")
index := f.NewSheet("Sheet2")
// Set value of a cell.
xlsx.SetCellValue("Sheet2", "A2", "Hello world.")
xlsx.SetCellValue("Sheet1", "B2", 100)
f.SetCellValue("Sheet2", "A2", "Hello world.")
f.SetCellValue("Sheet1", "B2", 100)
// Set active sheet of the workbook.
xlsx.SetActiveSheet(index)
f.SetActiveSheet(index)
// Save xlsx file by the given path.
err := xlsx.SaveAs("./Book1.xlsx")
err := f.SaveAs("./Book1.xlsx")
if err != nil {
fmt.Println(err)
}
Expand All @@ -68,16 +68,16 @@ import (
)

func main() {
xlsx, err := excelize.OpenFile("./Book1.xlsx")
f, err := excelize.OpenFile("./Book1.xlsx")
if err != nil {
fmt.Println(err)
return
}
// Get value from cell by given worksheet name and axis.
cell := xlsx.GetCellValue("Sheet1", "B2")
cell := f.GetCellValue("Sheet1", "B2")
fmt.Println(cell)
// Get all the rows in the Sheet1.
rows := xlsx.GetRows("Sheet1")
rows, err := f.GetRows("Sheet1")
for _, row := range rows {
for _, colCell := range row {
fmt.Print(colCell, "\t")
Expand Down Expand Up @@ -105,16 +105,20 @@ import (
func main() {
categories := map[string]string{"A2": "Small", "A3": "Normal", "A4": "Large", "B1": "Apple", "C1": "Orange", "D1": "Pear"}
values := map[string]int{"B2": 2, "C2": 3, "D2": 3, "B3": 5, "C3": 2, "D3": 4, "B4": 6, "C4": 7, "D4": 8}
xlsx := excelize.NewFile()
f := excelize.NewFile()
for k, v := range categories {
xlsx.SetCellValue("Sheet1", k, v)
f.SetCellValue("Sheet1", k, v)
}
for k, v := range values {
xlsx.SetCellValue("Sheet1", k, v)
f.SetCellValue("Sheet1", k, v)
}
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"}}`)
if err != nil {
fmt.Println(err)
return
}
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"}}`)
// Save xlsx file by the given path.
err := xlsx.SaveAs("./Book1.xlsx")
err = f.SaveAs("./Book1.xlsx")
if err != nil {
fmt.Println(err)
}
Expand All @@ -136,28 +140,28 @@ import (
)

func main() {
xlsx, err := excelize.OpenFile("./Book1.xlsx")
f, err := excelize.OpenFile("./Book1.xlsx")
if err != nil {
fmt.Println(err)
return
}
// Insert a picture.
err = xlsx.AddPicture("Sheet1", "A2", "./image1.png", "")
err = f.AddPicture("Sheet1", "A2", "./image1.png", "")
if err != nil {
fmt.Println(err)
}
// Insert a picture to worksheet with scaling.
err = xlsx.AddPicture("Sheet1", "D2", "./image2.jpg", `{"x_scale": 0.5, "y_scale": 0.5}`)
err = f.AddPicture("Sheet1", "D2", "./image2.jpg", `{"x_scale": 0.5, "y_scale": 0.5}`)
if err != nil {
fmt.Println(err)
}
// Insert a picture offset in the cell with printing support.
err = xlsx.AddPicture("Sheet1", "H2", "./image3.gif", `{"x_offset": 15, "y_offset": 10, "print_obj": true, "lock_aspect_ratio": false, "locked": false}`)
err = f.AddPicture("Sheet1", "H2", "./image3.gif", `{"x_offset": 15, "y_offset": 10, "print_obj": true, "lock_aspect_ratio": false, "locked": false}`)
if err != nil {
fmt.Println(err)
}
// Save the xlsx file with the origin path.
err = xlsx.Save()
err = f.Save()
if err != nil {
fmt.Println(err)
}
Expand Down
42 changes: 23 additions & 19 deletions README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,16 @@ import (
)

func main() {
xlsx := excelize.NewFile()
f := excelize.NewFile()
// 创建一个工作表
index := xlsx.NewSheet("Sheet2")
index := f.NewSheet("Sheet2")
// 设置单元格的值
xlsx.SetCellValue("Sheet2", "A2", "Hello world.")
xlsx.SetCellValue("Sheet1", "B2", 100)
f.SetCellValue("Sheet2", "A2", "Hello world.")
f.SetCellValue("Sheet1", "B2", 100)
// 设置工作簿的默认工作表
xlsx.SetActiveSheet(index)
f.SetActiveSheet(index)
// 根据指定路径保存文件
err := xlsx.SaveAs("./Book1.xlsx")
err := f.SaveAs("./Book1.xlsx")
if err != nil {
fmt.Println(err)
}
Expand All @@ -67,16 +67,16 @@ import (
)

func main() {
xlsx, err := excelize.OpenFile("./Book1.xlsx")
f, err := excelize.OpenFile("./Book1.xlsx")
if err != nil {
fmt.Println(err)
return
}
// 获取工作表中指定单元格的值
cell := xlsx.GetCellValue("Sheet1", "B2")
cell := f.GetCellValue("Sheet1", "B2")
fmt.Println(cell)
// 获取 Sheet1 上所有单元格
rows := xlsx.GetRows("Sheet1")
rows, err := f.GetRows("Sheet1")
for _, row := range rows {
for _, colCell := range row {
fmt.Print(colCell, "\t")
Expand Down Expand Up @@ -104,16 +104,20 @@ import (
func main() {
categories := map[string]string{"A2": "Small", "A3": "Normal", "A4": "Large", "B1": "Apple", "C1": "Orange", "D1": "Pear"}
values := map[string]int{"B2": 2, "C2": 3, "D2": 3, "B3": 5, "C3": 2, "D3": 4, "B4": 6, "C4": 7, "D4": 8}
xlsx := excelize.NewFile()
f := excelize.NewFile()
for k, v := range categories {
xlsx.SetCellValue("Sheet1", k, v)
f.SetCellValue("Sheet1", k, v)
}
for k, v := range values {
xlsx.SetCellValue("Sheet1", k, v)
f.SetCellValue("Sheet1", k, v)
}
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"}}`)
if err != nil {
fmt.Println(err)
return
}
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"}}`)
// 根据指定路径保存文件
err := xlsx.SaveAs("./Book1.xlsx")
err = f.SaveAs("./Book1.xlsx")
if err != nil {
fmt.Println(err)
}
Expand All @@ -136,28 +140,28 @@ import (
)

func main() {
xlsx, err := excelize.OpenFile("./Book1.xlsx")
f, err := excelize.OpenFile("./Book1.xlsx")
if err != nil {
fmt.Println(err)
return
}
// 插入图片
err = xlsx.AddPicture("Sheet1", "A2", "./image1.png", "")
err = f.AddPicture("Sheet1", "A2", "./image1.png", "")
if err != nil {
fmt.Println(err)
}
// 在工作表中插入图片,并设置图片的缩放比例
err = xlsx.AddPicture("Sheet1", "D2", "./image2.jpg", `{"x_scale": 0.5, "y_scale": 0.5}`)
err = f.AddPicture("Sheet1", "D2", "./image2.jpg", `{"x_scale": 0.5, "y_scale": 0.5}`)
if err != nil {
fmt.Println(err)
}
// 在工作表中插入图片,并设置图片的打印属性
err = xlsx.AddPicture("Sheet1", "H2", "./image3.gif", `{"x_offset": 15, "y_offset": 10, "print_obj": true, "lock_aspect_ratio": false, "locked": false}`)
err = f.AddPicture("Sheet1", "H2", "./image3.gif", `{"x_offset": 15, "y_offset": 10, "print_obj": true, "lock_aspect_ratio": false, "locked": false}`)
if err != nil {
fmt.Println(err)
}
// 保存文件
err = xlsx.Save()
err = f.Save()
if err != nil {
fmt.Println(err)
}
Expand Down
14 changes: 7 additions & 7 deletions cell.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ func (f *File) SetCellFormula(sheet, axis, formula string) error {
// the value of link will be false and the value of the target will be a blank
// string. For example get hyperlink of Sheet1!H6:
//
// link, target, err := xlsx.GetCellHyperLink("Sheet1", "H6")
// link, target, err := f.GetCellHyperLink("Sheet1", "H6")
//
func (f *File) GetCellHyperLink(sheet, axis string) (bool, string, error) {
// Check for correct cell name
Expand Down Expand Up @@ -338,14 +338,14 @@ func (f *File) GetCellHyperLink(sheet, axis string) (bool, string, error) {
// hyperlink "External" for web site or "Location" for moving to one of cell
// in this workbook. The below is example for external link.
//
// err := xlsx.SetCellHyperLink("Sheet1", "A3", "https://github.com/360EntSecGroup-Skylar/excelize", "External")
// err := f.SetCellHyperLink("Sheet1", "A3", "https://github.com/360EntSecGroup-Skylar/excelize", "External")
// // Set underline and font color style for the cell.
// style, err := xlsx.NewStyle(`{"font":{"color":"#1265BE","underline":"single"}}`)
// err = xlsx.SetCellStyle("Sheet1", "A3", "A3", style)
// style, err := f.NewStyle(`{"font":{"color":"#1265BE","underline":"single"}}`)
// err = f.SetCellStyle("Sheet1", "A3", "A3", style)
//
// A this is another example for "Location":
//
// err := xlsx.SetCellHyperLink("Sheet1", "A3", "Sheet1!A40", "Location")
// err := f.SetCellHyperLink("Sheet1", "A3", "Sheet1!A40", "Location")
//
func (f *File) SetCellHyperLink(sheet, axis, link, linkType string) error {
// Check for correct cell name
Expand Down Expand Up @@ -390,7 +390,7 @@ func (f *File) SetCellHyperLink(sheet, axis, link, linkType string) error {
// MergeCell provides a function to merge cells by given coordinate area and
// sheet name. For example create a merged cell of D3:E9 on Sheet1:
//
// err := xlsx.MergeCell("Sheet1", "D3", "E9")
// err := f.MergeCell("Sheet1", "D3", "E9")
//
// If you create a merged cell that overlaps with another existing merged cell,
// those merged cells that already exist will be removed.
Expand Down Expand Up @@ -452,7 +452,7 @@ func (f *File) MergeCell(sheet, hcell, vcell string) error {
// coordinate and a pointer to array type 'slice'. For example, writes an
// array to row 6 start with the cell B6 on Sheet1:
//
// err := xlsx.SetSheetRow("Sheet1", "B6", &[]interface{}{"1", nil, 2})
// err := f.SetSheetRow("Sheet1", "B6", &[]interface{}{"1", nil, 2})
//
func (f *File) SetSheetRow(sheet, axis string, slice interface{}) error {
col, row, err := CellNameToCoordinates(axis)
Expand Down
16 changes: 8 additions & 8 deletions col.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const (
// worksheet name and column name. For example, get visible state of column D
// in Sheet1:
//
// visiable, err := xlsx.GetColVisible("Sheet1", "D")
// visiable, err := f.GetColVisible("Sheet1", "D")
//
func (f *File) GetColVisible(sheet, col string) (bool, error) {
visible := true
Expand Down Expand Up @@ -51,7 +51,7 @@ func (f *File) GetColVisible(sheet, col string) (bool, error) {
// SetColVisible provides a function to set visible of a single column by given
// worksheet name and column name. For example, hide column D in Sheet1:
//
// err := xlsx.SetColVisible("Sheet1", "D", false)
// err := f.SetColVisible("Sheet1", "D", false)
//
func (f *File) SetColVisible(sheet, col string, visible bool) error {
colNum, err := ColumnNameToNumber(col)
Expand Down Expand Up @@ -91,7 +91,7 @@ func (f *File) SetColVisible(sheet, col string, visible bool) error {
// column by given worksheet name and column name. For example, get outline
// level of column D in Sheet1:
//
// level, err := xlsx.GetColOutlineLevel("Sheet1", "D")
// level, err := f.GetColOutlineLevel("Sheet1", "D")
//
func (f *File) GetColOutlineLevel(sheet, col string) (uint8, error) {
level := uint8(0)
Expand Down Expand Up @@ -119,7 +119,7 @@ func (f *File) GetColOutlineLevel(sheet, col string) (uint8, error) {
// column by given worksheet name and column name. For example, set outline
// level of column D in Sheet1 to 2:
//
// err := xlsx.SetColOutlineLevel("Sheet1", "D", 2)
// err := f.SetColOutlineLevel("Sheet1", "D", 2)
//
func (f *File) SetColOutlineLevel(sheet, col string, level uint8) error {
colNum, err := ColumnNameToNumber(col)
Expand Down Expand Up @@ -158,8 +158,8 @@ func (f *File) SetColOutlineLevel(sheet, col string, level uint8) error {
// SetColWidth provides a function to set the width of a single column or
// multiple columns. For example:
//
// xlsx := excelize.NewFile()
// err := xlsx.SetColWidth("Sheet1", "A", "H", 20)
// f := excelize.NewFile()
// err := f.SetColWidth("Sheet1", "A", "H", 20)
//
func (f *File) SetColWidth(sheet, startcol, endcol string, width float64) error {
min, err := ColumnNameToNumber(startcol)
Expand Down Expand Up @@ -348,7 +348,7 @@ func (f *File) GetColWidth(sheet, col string) (float64, error) {
// InsertCol provides a function to insert a new column before given column
// index. For example, create a new column before column C in Sheet1:
//
// err := xlsx.InsertCol("Sheet1", "C")
// err := f.InsertCol("Sheet1", "C")
//
func (f *File) InsertCol(sheet, col string) error {
num, err := ColumnNameToNumber(col)
Expand All @@ -361,7 +361,7 @@ func (f *File) InsertCol(sheet, col string) error {
// RemoveCol provides a function to remove single column by given worksheet
// name and column index. For example, remove column C in Sheet1:
//
// err := xlsx.RemoveCol("Sheet1", "C")
// err := f.RemoveCol("Sheet1", "C")
//
// Use this method with caution, which will affect changes in references such
// as formulas, charts, and so on. If there is any referenced value of the
Expand Down
8 changes: 4 additions & 4 deletions datavalidation.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func (dd *DataValidation) SetRange(f1, f2 int, t DataValidationType, o DataValid
// dvRange := excelize.NewDataValidation(true)
// dvRange.Sqref = "A7:B8"
// dvRange.SetSqrefDropList("E1:E3", true)
// xlsx.AddDataValidation("Sheet1", dvRange)
// f.AddDataValidation("Sheet1", dvRange)
//
func (dd *DataValidation) SetSqrefDropList(sqref string, isCurrentSheet bool) error {
if isCurrentSheet {
Expand Down Expand Up @@ -208,7 +208,7 @@ func convDataValidationOperatior(o DataValidationOperator) string {
// dvRange.Sqref = "A1:B2"
// dvRange.SetRange(10, 20, excelize.DataValidationTypeWhole, excelize.DataValidationOperatorBetween)
// dvRange.SetError(excelize.DataValidationErrorStyleStop, "error title", "error body")
// err := xlsx.AddDataValidation("Sheet1", dvRange)
// err := f.AddDataValidation("Sheet1", dvRange)
//
// Example 2, set data validation on Sheet1!A3:B4 with validation criteria
// settings, and show input message when cell is selected:
Expand All @@ -217,15 +217,15 @@ func convDataValidationOperatior(o DataValidationOperator) string {
// dvRange.Sqref = "A3:B4"
// dvRange.SetRange(10, 20, excelize.DataValidationTypeWhole, excelize.DataValidationOperatorGreaterThan)
// dvRange.SetInput("input title", "input body")
// err = xlsx.AddDataValidation("Sheet1", dvRange)
// err = f.AddDataValidation("Sheet1", dvRange)
//
// Example 3, set data validation on Sheet1!A5:B6 with validation criteria
// settings, create in-cell dropdown by allowing list source:
//
// dvRange = excelize.NewDataValidation(true)
// dvRange.Sqref = "A5:B6"
// dvRange.SetDropList([]string{"1", "2", "3"})
// err = xlsx.AddDataValidation("Sheet1", dvRange)
// err = f.AddDataValidation("Sheet1", dvRange)
//
func (f *File) AddDataValidation(sheet string, dv *DataValidation) error {
xlsx, err := f.workSheetReader(sheet)
Expand Down
3 changes: 2 additions & 1 deletion excelize.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,8 @@ func (f *File) UpdateLinkedValue() error {
return nil
}

// GetMergeCells provides a function to get all merged cells from a worksheet currently.
// GetMergeCells provides a function to get all merged cells from a worksheet
// currently.
func (f *File) GetMergeCells(sheet string) ([]MergeCell, error) {
var mergeCells []MergeCell
xlsx, err := f.workSheetReader(sheet)
Expand Down
Loading

0 comments on commit 0660f30

Please sign in to comment.