forked from p30928647/excelize
godoc update and typo fixed
This commit is contained in:
parent
0f9170a03b
commit
0660f30cdd
42
README.md
42
README.md
|
@ -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)
|
||||
}
|
||||
|
@ -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")
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
|
42
README_zh.md
42
README_zh.md
|
@ -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)
|
||||
}
|
||||
|
@ -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")
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
|
14
cell.go
14
cell.go
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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.
|
||||
|
@ -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)
|
||||
|
|
16
col.go
16
col.go
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
|
@ -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:
|
||||
|
@ -217,7 +217,7 @@ 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:
|
||||
|
@ -225,7 +225,7 @@ func convDataValidationOperatior(o DataValidationOperator) string {
|
|||
// 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)
|
||||
|
|
|
@ -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)
|
||||
|
|
16
lib.go
16
lib.go
|
@ -87,7 +87,7 @@ func SplitCellName(cell string) (string, int, error) {
|
|||
return "", -1, newInvalidCellNameError(cell)
|
||||
}
|
||||
|
||||
// JoinCellName joins cell name from column name and row number
|
||||
// JoinCellName joins cell name from column name and row number.
|
||||
func JoinCellName(col string, row int) (string, error) {
|
||||
normCol := strings.Map(func(rune rune) rune {
|
||||
switch {
|
||||
|
@ -107,9 +107,9 @@ func JoinCellName(col string, row int) (string, error) {
|
|||
return fmt.Sprintf("%s%d", normCol, row), nil
|
||||
}
|
||||
|
||||
// ColumnNameToNumber provides a function to convert Excel sheet
|
||||
// column name to int. Column name case insencitive
|
||||
// Function returns error if column name incorrect.
|
||||
// ColumnNameToNumber provides a function to convert Excel sheet column name
|
||||
// to int. Column name case insensitive. The function returns an error if
|
||||
// column name incorrect.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
|
@ -135,8 +135,8 @@ func ColumnNameToNumber(name string) (int, error) {
|
|||
return col, nil
|
||||
}
|
||||
|
||||
// ColumnNumberToName provides a function to convert integer
|
||||
// to Excel sheet column title.
|
||||
// ColumnNumberToName provides a function to convert the integer to Excel
|
||||
// sheet column title.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
|
@ -154,8 +154,8 @@ func ColumnNumberToName(num int) (string, error) {
|
|||
return col, nil
|
||||
}
|
||||
|
||||
// CellNameToCoordinates converts alpha-numeric cell name
|
||||
// to [X, Y] coordinates or retrusn an error.
|
||||
// CellNameToCoordinates converts alphanumeric cell name to [X, Y] coordinates
|
||||
// or returns an error.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
|
|
25
picture.go
25
picture.go
|
@ -55,23 +55,23 @@ func parseFormatPictureSet(formatSet string) (*formatPicture, error) {
|
|||
// )
|
||||
//
|
||||
// func main() {
|
||||
// xlsx := excelize.NewFile()
|
||||
// f := excelize.NewFile()
|
||||
// // Insert a picture.
|
||||
// err := xlsx.AddPicture("Sheet1", "A2", "./image1.jpg", "")
|
||||
// err := f.AddPicture("Sheet1", "A2", "./image1.jpg", "")
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
// // Insert a picture scaling in the cell with location hyperlink.
|
||||
// err = xlsx.AddPicture("Sheet1", "D2", "./image1.png", `{"x_scale": 0.5, "y_scale": 0.5, "hyperlink": "#Sheet2!D8", "hyperlink_type": "Location"}`)
|
||||
// err = f.AddPicture("Sheet1", "D2", "./image1.png", `{"x_scale": 0.5, "y_scale": 0.5, "hyperlink": "#Sheet2!D8", "hyperlink_type": "Location"}`)
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
// // Insert a picture offset in the cell with external hyperlink, printing and positioning support.
|
||||
// err = xlsx.AddPicture("Sheet1", "H2", "./image3.gif", `{"x_offset": 15, "y_offset": 10, "hyperlink": "https://github.com/360EntSecGroup-Skylar/excelize", "hyperlink_type": "External", "print_obj": true, "lock_aspect_ratio": false, "locked": false, "positioning": "oneCell"}`)
|
||||
// err = f.AddPicture("Sheet1", "H2", "./image3.gif", `{"x_offset": 15, "y_offset": 10, "hyperlink": "https://github.com/360EntSecGroup-Skylar/excelize", "hyperlink_type": "External", "print_obj": true, "lock_aspect_ratio": false, "locked": false, "positioning": "oneCell"}`)
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
// err = xlsx.SaveAs("./Book1.xlsx")
|
||||
// err = f.SaveAs("./Book1.xlsx")
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
|
@ -115,17 +115,17 @@ func (f *File) AddPicture(sheet, cell, picture, format string) error {
|
|||
// )
|
||||
//
|
||||
// func main() {
|
||||
// xlsx := excelize.NewFile()
|
||||
// f := excelize.NewFile()
|
||||
//
|
||||
// file, err := ioutil.ReadFile("./image1.jpg")
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
// err = xlsx.AddPictureFromBytes("Sheet1", "A2", "", "Excel Logo", ".jpg", file)
|
||||
// err = f.AddPictureFromBytes("Sheet1", "A2", "", "Excel Logo", ".jpg", file)
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
// err = xlsx.SaveAs("./Book1.xlsx")
|
||||
// err = f.SaveAs("./Book1.xlsx")
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
|
@ -481,16 +481,17 @@ func (f *File) getSheetRelationshipsTargetByID(sheet, rID string) string {
|
|||
// embed in XLSX by given worksheet and cell name. This function returns the
|
||||
// file name in XLSX and file contents as []byte data types. For example:
|
||||
//
|
||||
// xlsx, err := excelize.OpenFile("./Book1.xlsx")
|
||||
// f, err := excelize.OpenFile("./Book1.xlsx")
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// return
|
||||
// }
|
||||
// file, raw, err := xlsx.GetPicture("Sheet1", "A2")
|
||||
// if file == "" {
|
||||
// file, raw, err := f.GetPicture("Sheet1", "A2")
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// return
|
||||
// }
|
||||
// err := ioutil.WriteFile(file, raw, 0644)
|
||||
// err = ioutil.WriteFile(file, raw, 0644)
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
|
|
24
rows.go
24
rows.go
|
@ -21,7 +21,7 @@ import (
|
|||
// GetRows return all the rows in a sheet by given worksheet name (case
|
||||
// sensitive). For example:
|
||||
//
|
||||
// rows, err := xlsx.GetRows("Sheet1")
|
||||
// rows, err := f.GetRows("Sheet1")
|
||||
// for _, row := range rows {
|
||||
// for _, colCell := range row {
|
||||
// fmt.Print(colCell, "\t")
|
||||
|
@ -158,7 +158,7 @@ func (err ErrSheetNotExist) Error() string {
|
|||
|
||||
// Rows return a rows iterator. For example:
|
||||
//
|
||||
// rows, err := xlsx.Rows("Sheet1")
|
||||
// rows, err := f.Rows("Sheet1")
|
||||
// for rows.Next() {
|
||||
// row, err := rows.Columns()
|
||||
// for _, colCell := range row {
|
||||
|
@ -224,7 +224,7 @@ func (f *File) getTotalRowsCols(name string) (int, int, error) {
|
|||
// SetRowHeight provides a function to set the height of a single row. For
|
||||
// example, set the height of the first row in Sheet1:
|
||||
//
|
||||
// err := xlsx.SetRowHeight("Sheet1", 1, 50)
|
||||
// err := f.SetRowHeight("Sheet1", 1, 50)
|
||||
//
|
||||
func (f *File) SetRowHeight(sheet string, row int, height float64) error {
|
||||
if row < 1 {
|
||||
|
@ -260,7 +260,7 @@ func (f *File) getRowHeight(sheet string, row int) int {
|
|||
// GetRowHeight provides a function to get row height by given worksheet name
|
||||
// and row index. For example, get the height of the first row in Sheet1:
|
||||
//
|
||||
// height, err := xlsx.GetRowHeight("Sheet1", 1)
|
||||
// height, err := f.GetRowHeight("Sheet1", 1)
|
||||
//
|
||||
func (f *File) GetRowHeight(sheet string, row int) (float64, error) {
|
||||
if row < 1 {
|
||||
|
@ -326,7 +326,7 @@ func (xlsx *xlsxC) getValueFrom(f *File, d *xlsxSST) (string, error) {
|
|||
// SetRowVisible provides a function to set visible of a single row by given
|
||||
// worksheet name and Excel row number. For example, hide row 2 in Sheet1:
|
||||
//
|
||||
// err := xlsx.SetRowVisible("Sheet1", 2, false)
|
||||
// err := f.SetRowVisible("Sheet1", 2, false)
|
||||
//
|
||||
func (f *File) SetRowVisible(sheet string, row int, visible bool) error {
|
||||
if row < 1 {
|
||||
|
@ -346,7 +346,7 @@ func (f *File) SetRowVisible(sheet string, row int, visible bool) error {
|
|||
// worksheet name and Excel row number. For example, get visible state of row
|
||||
// 2 in Sheet1:
|
||||
//
|
||||
// visible, err := xlsx.GetRowVisible("Sheet1", 2)
|
||||
// visible, err := f.GetRowVisible("Sheet1", 2)
|
||||
//
|
||||
func (f *File) GetRowVisible(sheet string, row int) (bool, error) {
|
||||
if row < 1 {
|
||||
|
@ -367,7 +367,7 @@ func (f *File) GetRowVisible(sheet string, row int) (bool, error) {
|
|||
// single row by given worksheet name and Excel row number. For example,
|
||||
// outline row 2 in Sheet1 to level 1:
|
||||
//
|
||||
// err := xlsx.SetRowOutlineLevel("Sheet1", 2, 1)
|
||||
// err := f.SetRowOutlineLevel("Sheet1", 2, 1)
|
||||
//
|
||||
func (f *File) SetRowOutlineLevel(sheet string, row int, level uint8) error {
|
||||
if row < 1 {
|
||||
|
@ -386,7 +386,7 @@ func (f *File) SetRowOutlineLevel(sheet string, row int, level uint8) error {
|
|||
// single row by given worksheet name and Excel row number. For example, get
|
||||
// outline number of row 2 in Sheet1:
|
||||
//
|
||||
// level, err := xlsx.GetRowOutlineLevel("Sheet1", 2)
|
||||
// level, err := f.GetRowOutlineLevel("Sheet1", 2)
|
||||
//
|
||||
func (f *File) GetRowOutlineLevel(sheet string, row int) (uint8, error) {
|
||||
if row < 1 {
|
||||
|
@ -405,7 +405,7 @@ func (f *File) GetRowOutlineLevel(sheet string, row int) (uint8, error) {
|
|||
// RemoveRow provides a function to remove single row by given worksheet name
|
||||
// and Excel row number. For example, remove row 3 in Sheet1:
|
||||
//
|
||||
// err := xlsx.RemoveRow("Sheet1", 3)
|
||||
// err := f.RemoveRow("Sheet1", 3)
|
||||
//
|
||||
// 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
|
||||
|
@ -437,7 +437,7 @@ func (f *File) RemoveRow(sheet string, row int) error {
|
|||
// number starting from 1. For example, create a new row before row 3 in
|
||||
// Sheet1:
|
||||
//
|
||||
// err := elsx.InsertRow("Sheet1", 3)
|
||||
// err := f.InsertRow("Sheet1", 3)
|
||||
//
|
||||
func (f *File) InsertRow(sheet string, row int) error {
|
||||
if row < 1 {
|
||||
|
@ -448,7 +448,7 @@ func (f *File) InsertRow(sheet string, row int) error {
|
|||
|
||||
// DuplicateRow inserts a copy of specified row (by its Excel row number) below
|
||||
//
|
||||
// err := xlsx.DuplicateRow("Sheet1", 2)
|
||||
// err := f.DuplicateRow("Sheet1", 2)
|
||||
//
|
||||
// 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
|
||||
|
@ -461,7 +461,7 @@ func (f *File) DuplicateRow(sheet string, row int) error {
|
|||
// DuplicateRowTo inserts a copy of specified row by it Excel number
|
||||
// to specified row position moving down exists rows after target position
|
||||
//
|
||||
// err := xlsx.DuplicateRowTo("Sheet1", 2, 7)
|
||||
// err := f.DuplicateRowTo("Sheet1", 2, 7)
|
||||
//
|
||||
// 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
|
||||
|
|
2
shape.go
2
shape.go
|
@ -40,7 +40,7 @@ func parseFormatShapeSet(formatSet string) (*formatShape, error) {
|
|||
// print settings) and properties set. For example, add text box (rect shape)
|
||||
// in Sheet1:
|
||||
//
|
||||
// xlsx.AddShape("Sheet1", "G6", `{"type":"rect","color":{"line":"#4286F4","fill":"#8eb9ff"},"paragraph":[{"text":"Rectangle Shape","font":{"bold":true,"italic":true,"family":"Berlin Sans FB Demi","size":36,"color":"#777777","underline":"sng"}}],"width":180,"height": 90}`)
|
||||
// f.AddShape("Sheet1", "G6", `{"type":"rect","color":{"line":"#4286F4","fill":"#8eb9ff"},"paragraph":[{"text":"Rectangle Shape","font":{"bold":true,"italic":true,"family":"Berlin Sans FB Demi","size":36,"color":"#777777","underline":"sng"}}],"width":180,"height": 90}`)
|
||||
//
|
||||
// The following shows the type of shape supported by excelize:
|
||||
//
|
||||
|
|
26
sheet.go
26
sheet.go
|
@ -334,11 +334,11 @@ func (f *File) GetSheetIndex(name string) int {
|
|||
// GetSheetMap provides a function to get worksheet name and index map of XLSX.
|
||||
// For example:
|
||||
//
|
||||
// xlsx, err := excelize.OpenFile("./Book1.xlsx")
|
||||
// f, err := excelize.OpenFile("./Book1.xlsx")
|
||||
// if err != nil {
|
||||
// return
|
||||
// }
|
||||
// for index, name := range xlsx.GetSheetMap() {
|
||||
// for index, name := range f.GetSheetMap() {
|
||||
// fmt.Println(index, name)
|
||||
// }
|
||||
//
|
||||
|
@ -443,8 +443,8 @@ func (f *File) deleteSheetFromContentTypes(target string) {
|
|||
// workbooks that contain tables, charts or pictures. For Example:
|
||||
//
|
||||
// // Sheet1 already exists...
|
||||
// index := xlsx.NewSheet("Sheet2")
|
||||
// err := xlsx.CopySheet(1, index)
|
||||
// index := f.NewSheet("Sheet2")
|
||||
// err := f.CopySheet(1, index)
|
||||
// return err
|
||||
//
|
||||
func (f *File) CopySheet(from, to int) error {
|
||||
|
@ -490,7 +490,7 @@ func (f *File) copySheet(from, to int) error {
|
|||
//
|
||||
// For example, hide Sheet1:
|
||||
//
|
||||
// err := xlsx.SetSheetVisible("Sheet1", false)
|
||||
// err := f.SetSheetVisible("Sheet1", false)
|
||||
//
|
||||
func (f *File) SetSheetVisible(name string, visible bool) error {
|
||||
name = trimSheetName(name)
|
||||
|
@ -601,21 +601,21 @@ func parseFormatPanesSet(formatSet string) (*formatPanes, error) {
|
|||
// An example of how to freeze column A in the Sheet1 and set the active cell on
|
||||
// Sheet1!K16:
|
||||
//
|
||||
// xlsx.SetPanes("Sheet1", `{"freeze":true,"split":false,"x_split":1,"y_split":0,"top_left_cell":"B1","active_pane":"topRight","panes":[{"sqref":"K16","active_cell":"K16","pane":"topRight"}]}`)
|
||||
// f.SetPanes("Sheet1", `{"freeze":true,"split":false,"x_split":1,"y_split":0,"top_left_cell":"B1","active_pane":"topRight","panes":[{"sqref":"K16","active_cell":"K16","pane":"topRight"}]}`)
|
||||
//
|
||||
// An example of how to freeze rows 1 to 9 in the Sheet1 and set the active cell
|
||||
// ranges on Sheet1!A11:XFD11:
|
||||
//
|
||||
// xlsx.SetPanes("Sheet1", `{"freeze":true,"split":false,"x_split":0,"y_split":9,"top_left_cell":"A34","active_pane":"bottomLeft","panes":[{"sqref":"A11:XFD11","active_cell":"A11","pane":"bottomLeft"}]}`)
|
||||
// f.SetPanes("Sheet1", `{"freeze":true,"split":false,"x_split":0,"y_split":9,"top_left_cell":"A34","active_pane":"bottomLeft","panes":[{"sqref":"A11:XFD11","active_cell":"A11","pane":"bottomLeft"}]}`)
|
||||
//
|
||||
// An example of how to create split panes in the Sheet1 and set the active cell
|
||||
// on Sheet1!J60:
|
||||
//
|
||||
// xlsx.SetPanes("Sheet1", `{"freeze":false,"split":true,"x_split":3270,"y_split":1800,"top_left_cell":"N57","active_pane":"bottomLeft","panes":[{"sqref":"I36","active_cell":"I36"},{"sqref":"G33","active_cell":"G33","pane":"topRight"},{"sqref":"J60","active_cell":"J60","pane":"bottomLeft"},{"sqref":"O60","active_cell":"O60","pane":"bottomRight"}]}`)
|
||||
// f.SetPanes("Sheet1", `{"freeze":false,"split":true,"x_split":3270,"y_split":1800,"top_left_cell":"N57","active_pane":"bottomLeft","panes":[{"sqref":"I36","active_cell":"I36"},{"sqref":"G33","active_cell":"G33","pane":"topRight"},{"sqref":"J60","active_cell":"J60","pane":"bottomLeft"},{"sqref":"O60","active_cell":"O60","pane":"bottomRight"}]}`)
|
||||
//
|
||||
// An example of how to unfreeze and remove all panes on Sheet1:
|
||||
//
|
||||
// xlsx.SetPanes("Sheet1", `{"freeze":false,"split":false}`)
|
||||
// f.SetPanes("Sheet1", `{"freeze":false,"split":false}`)
|
||||
//
|
||||
func (f *File) SetPanes(sheet, panes string) error {
|
||||
fs, _ := parseFormatPanesSet(panes)
|
||||
|
@ -653,7 +653,7 @@ func (f *File) SetPanes(sheet, panes string) error {
|
|||
// GetSheetVisible provides a function to get worksheet visible by given worksheet
|
||||
// name. For example, get visible state of Sheet1:
|
||||
//
|
||||
// xlsx.GetSheetVisible("Sheet1")
|
||||
// f.GetSheetVisible("Sheet1")
|
||||
//
|
||||
func (f *File) GetSheetVisible(name string) bool {
|
||||
content := f.workbookReader()
|
||||
|
@ -676,12 +676,12 @@ func (f *File) GetSheetVisible(name string) bool {
|
|||
//
|
||||
// An example of search the coordinates of the value of "100" on Sheet1:
|
||||
//
|
||||
// result, err := xlsx.SearchSheet("Sheet1", "100")
|
||||
// result, err := f.SearchSheet("Sheet1", "100")
|
||||
//
|
||||
// An example of search the coordinates where the numerical value in the range
|
||||
// of "0-9" of Sheet1 is described:
|
||||
//
|
||||
// result, err := xlsx.SearchSheet("Sheet1", "[0-9]", true)
|
||||
// result, err := f.SearchSheet("Sheet1", "[0-9]", true)
|
||||
//
|
||||
func (f *File) SearchSheet(sheet, value string, reg ...bool) ([]string, error) {
|
||||
var (
|
||||
|
@ -756,7 +756,7 @@ func (f *File) SearchSheet(sheet, value string, reg ...bool) ([]string, error) {
|
|||
// or deliberately changing, moving, or deleting data in a worksheet. For
|
||||
// example, protect Sheet1 with protection settings:
|
||||
//
|
||||
// err := xlsx.ProtectSheet("Sheet1", &excelize.FormatSheetProtection{
|
||||
// err := f.ProtectSheet("Sheet1", &excelize.FormatSheetProtection{
|
||||
// Password: "password",
|
||||
// EditScenarios: false,
|
||||
// })
|
||||
|
|
74
styles.go
74
styles.go
|
@ -1878,10 +1878,10 @@ func parseFormatStyleSet(style string) (*formatStyle, error) {
|
|||
// Excelize support set custom number format for cell. For example, set number
|
||||
// as date type in Uruguay (Spanish) format for Sheet1!A6:
|
||||
//
|
||||
// xlsx := excelize.NewFile()
|
||||
// xlsx.SetCellValue("Sheet1", "A6", 42920.5)
|
||||
// style, err := xlsx.NewStyle(`{"custom_number_format": "[$-380A]dddd\\,\\ dd\" de \"mmmm\" de \"yyyy;@"}`)
|
||||
// err = xlsx.SetCellStyle("Sheet1", "A6", "A6", style)
|
||||
// f := excelize.NewFile()
|
||||
// f.SetCellValue("Sheet1", "A6", 42920.5)
|
||||
// style, err := f.NewStyle(`{"custom_number_format": "[$-380A]dddd\\,\\ dd\" de \"mmmm\" de \"yyyy;@"}`)
|
||||
// err = f.SetCellStyle("Sheet1", "A6", "A6", style)
|
||||
//
|
||||
// Cell Sheet1!A6 in the Excel Application: martes, 04 de Julio de 2017
|
||||
//
|
||||
|
@ -2284,63 +2284,63 @@ func (f *File) GetCellStyle(sheet, axis string) (int, error) {
|
|||
//
|
||||
// For example create a borders of cell H9 on Sheet1:
|
||||
//
|
||||
// style, err := xlsx.NewStyle(`{"border":[{"type":"left","color":"0000FF","style":3},{"type":"top","color":"00FF00","style":4},{"type":"bottom","color":"FFFF00","style":5},{"type":"right","color":"FF0000","style":6},{"type":"diagonalDown","color":"A020F0","style":7},{"type":"diagonalUp","color":"A020F0","style":8}]}`)
|
||||
// style, err := f.NewStyle(`{"border":[{"type":"left","color":"0000FF","style":3},{"type":"top","color":"00FF00","style":4},{"type":"bottom","color":"FFFF00","style":5},{"type":"right","color":"FF0000","style":6},{"type":"diagonalDown","color":"A020F0","style":7},{"type":"diagonalUp","color":"A020F0","style":8}]}`)
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
// err = xlsx.SetCellStyle("Sheet1", "H9", "H9", style)
|
||||
// err = f.SetCellStyle("Sheet1", "H9", "H9", style)
|
||||
//
|
||||
// Set gradient fill with vertical variants shading styles for cell H9 on
|
||||
// Sheet1:
|
||||
//
|
||||
// style, err := xlsx.NewStyle(`{"fill":{"type":"gradient","color":["#FFFFFF","#E0EBF5"],"shading":1}}`)
|
||||
// style, err := f.NewStyle(`{"fill":{"type":"gradient","color":["#FFFFFF","#E0EBF5"],"shading":1}}`)
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
// err = xlsx.SetCellStyle("Sheet1", "H9", "H9", style)
|
||||
// err = f.SetCellStyle("Sheet1", "H9", "H9", style)
|
||||
//
|
||||
// Set solid style pattern fill for cell H9 on Sheet1:
|
||||
//
|
||||
// style, err := xlsx.NewStyle(`{"fill":{"type":"pattern","color":["#E0EBF5"],"pattern":1}}`)
|
||||
// style, err := f.NewStyle(`{"fill":{"type":"pattern","color":["#E0EBF5"],"pattern":1}}`)
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
// err = xlsx.SetCellStyle("Sheet1", "H9", "H9", style)
|
||||
// err = f.SetCellStyle("Sheet1", "H9", "H9", style)
|
||||
//
|
||||
// Set alignment style for cell H9 on Sheet1:
|
||||
//
|
||||
// style, err := xlsx.NewStyle(`{"alignment":{"horizontal":"center","ident":1,"justify_last_line":true,"reading_order":0,"relative_indent":1,"shrink_to_fit":true,"text_rotation":45,"vertical":"","wrap_text":true}}`)
|
||||
// style, err := f.NewStyle(`{"alignment":{"horizontal":"center","ident":1,"justify_last_line":true,"reading_order":0,"relative_indent":1,"shrink_to_fit":true,"text_rotation":45,"vertical":"","wrap_text":true}}`)
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
// err = xlsx.SetCellStyle("Sheet1", "H9", "H9", style)
|
||||
// err = f.SetCellStyle("Sheet1", "H9", "H9", style)
|
||||
//
|
||||
// Dates and times in Excel are represented by real numbers, for example "Apr 7
|
||||
// 2017 12:00 PM" is represented by the number 42920.5. Set date and time format
|
||||
// for cell H9 on Sheet1:
|
||||
//
|
||||
// xlsx.SetCellValue("Sheet1", "H9", 42920.5)
|
||||
// style, err := xlsx.NewStyle(`{"number_format": 22}`)
|
||||
// f.SetCellValue("Sheet1", "H9", 42920.5)
|
||||
// style, err := f.NewStyle(`{"number_format": 22}`)
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
// err = xlsx.SetCellStyle("Sheet1", "H9", "H9", style)
|
||||
// err = f.SetCellStyle("Sheet1", "H9", "H9", style)
|
||||
//
|
||||
// Set font style for cell H9 on Sheet1:
|
||||
//
|
||||
// style, err := xlsx.NewStyle(`{"font":{"bold":true,"italic":true,"family":"Berlin Sans FB Demi","size":36,"color":"#777777"}}`)
|
||||
// style, err := f.NewStyle(`{"font":{"bold":true,"italic":true,"family":"Berlin Sans FB Demi","size":36,"color":"#777777"}}`)
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
// err = xlsx.SetCellStyle("Sheet1", "H9", "H9", style)
|
||||
// err = f.SetCellStyle("Sheet1", "H9", "H9", style)
|
||||
//
|
||||
// Hide and lock for cell H9 on Sheet1:
|
||||
//
|
||||
// style, err := xlsx.NewStyle(`{"protection":{"hidden":true, "locked":true}}`)
|
||||
// style, err := f.NewStyle(`{"protection":{"hidden":true, "locked":true}}`)
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
// err = xlsx.SetCellStyle("Sheet1", "H9", "H9", style)
|
||||
// err = f.SetCellStyle("Sheet1", "H9", "H9", style)
|
||||
//
|
||||
func (f *File) SetCellStyle(sheet, hcell, vcell string, styleID int) error {
|
||||
hcol, hrow, err := CellNameToCoordinates(hcell)
|
||||
|
@ -2459,22 +2459,22 @@ func (f *File) SetCellStyle(sheet, hcell, vcell string, styleID int) error {
|
|||
// value: The value is generally used along with the criteria parameter to set
|
||||
// the rule by which the cell data will be evaluated:
|
||||
//
|
||||
// xlsx.SetConditionalFormat("Sheet1", "D1:D10", fmt.Sprintf(`[{"type":"cell","criteria":">","format":%d,"value":"6"}]`, format))
|
||||
// f.SetConditionalFormat("Sheet1", "D1:D10", fmt.Sprintf(`[{"type":"cell","criteria":">","format":%d,"value":"6"}]`, format))
|
||||
//
|
||||
// The value property can also be an cell reference:
|
||||
//
|
||||
// xlsx.SetConditionalFormat("Sheet1", "D1:D10", fmt.Sprintf(`[{"type":"cell","criteria":">","format":%d,"value":"$C$1"}]`, format))
|
||||
// f.SetConditionalFormat("Sheet1", "D1:D10", fmt.Sprintf(`[{"type":"cell","criteria":">","format":%d,"value":"$C$1"}]`, format))
|
||||
//
|
||||
// type: format - The format parameter is used to specify the format that will
|
||||
// be applied to the cell when the conditional formatting criterion is met. The
|
||||
// format is created using the NewConditionalStyle() method in the same way as
|
||||
// cell formats:
|
||||
//
|
||||
// format, err = xlsx.NewConditionalStyle(`{"font":{"color":"#9A0511"},"fill":{"type":"pattern","color":["#FEC7CE"],"pattern":1}}`)
|
||||
// format, err = f.NewConditionalStyle(`{"font":{"color":"#9A0511"},"fill":{"type":"pattern","color":["#FEC7CE"],"pattern":1}}`)
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
// xlsx.SetConditionalFormat("Sheet1", "A1:A10", fmt.Sprintf(`[{"type":"cell","criteria":">","format":%d,"value":"6"}]`, format))
|
||||
// f.SetConditionalFormat("Sheet1", "A1:A10", fmt.Sprintf(`[{"type":"cell","criteria":">","format":%d,"value":"6"}]`, format))
|
||||
//
|
||||
// Note: In Excel, a conditional format is superimposed over the existing cell
|
||||
// format and not all cell format properties can be modified. Properties that
|
||||
|
@ -2486,19 +2486,19 @@ func (f *File) SetCellStyle(sheet, hcell, vcell string, styleID int) error {
|
|||
// These can be replicated using the following excelize formats:
|
||||
//
|
||||
// // Rose format for bad conditional.
|
||||
// format1, err = xlsx.NewConditionalStyle(`{"font":{"color":"#9A0511"},"fill":{"type":"pattern","color":["#FEC7CE"],"pattern":1}}`)
|
||||
// format1, err = f.NewConditionalStyle(`{"font":{"color":"#9A0511"},"fill":{"type":"pattern","color":["#FEC7CE"],"pattern":1}}`)
|
||||
//
|
||||
// // Light yellow format for neutral conditional.
|
||||
// format2, err = xlsx.NewConditionalStyle(`{"font":{"color":"#9B5713"},"fill":{"type":"pattern","color":["#FEEAA0"],"pattern":1}}`)
|
||||
// format2, err = f.NewConditionalStyle(`{"font":{"color":"#9B5713"},"fill":{"type":"pattern","color":["#FEEAA0"],"pattern":1}}`)
|
||||
//
|
||||
// // Light green format for good conditional.
|
||||
// format3, err = xlsx.NewConditionalStyle(`{"font":{"color":"#09600B"},"fill":{"type":"pattern","color":["#C7EECF"],"pattern":1}}`)
|
||||
// format3, err = f.NewConditionalStyle(`{"font":{"color":"#09600B"},"fill":{"type":"pattern","color":["#C7EECF"],"pattern":1}}`)
|
||||
//
|
||||
// type: minimum - The minimum parameter is used to set the lower limiting value
|
||||
// when the criteria is either "between" or "not between".
|
||||
//
|
||||
// // Hightlight cells rules: between...
|
||||
// xlsx.SetConditionalFormat("Sheet1", "A1:A10", fmt.Sprintf(`[{"type":"cell","criteria":"between","format":%d,"minimum":"6","maximum":"8"}]`, format))
|
||||
// f.SetConditionalFormat("Sheet1", "A1:A10", fmt.Sprintf(`[{"type":"cell","criteria":"between","format":%d,"minimum":"6","maximum":"8"}]`, format))
|
||||
//
|
||||
// type: maximum - The maximum parameter is used to set the upper limiting value
|
||||
// when the criteria is either "between" or "not between". See the previous
|
||||
|
@ -2508,35 +2508,35 @@ func (f *File) SetCellStyle(sheet, hcell, vcell string, styleID int) error {
|
|||
// conditional format:
|
||||
//
|
||||
// // Top/Bottom rules: Above Average...
|
||||
// xlsx.SetConditionalFormat("Sheet1", "A1:A10", fmt.Sprintf(`[{"type":"average","criteria":"=","format":%d, "above_average": true}]`, format1))
|
||||
// f.SetConditionalFormat("Sheet1", "A1:A10", fmt.Sprintf(`[{"type":"average","criteria":"=","format":%d, "above_average": true}]`, format1))
|
||||
//
|
||||
// // Top/Bottom rules: Below Average...
|
||||
// xlsx.SetConditionalFormat("Sheet1", "B1:B10", fmt.Sprintf(`[{"type":"average","criteria":"=","format":%d, "above_average": false}]`, format2))
|
||||
// f.SetConditionalFormat("Sheet1", "B1:B10", fmt.Sprintf(`[{"type":"average","criteria":"=","format":%d, "above_average": false}]`, format2))
|
||||
//
|
||||
// type: duplicate - The duplicate type is used to highlight duplicate cells in a range:
|
||||
//
|
||||
// // Hightlight cells rules: Duplicate Values...
|
||||
// xlsx.SetConditionalFormat("Sheet1", "A1:A10", fmt.Sprintf(`[{"type":"duplicate","criteria":"=","format":%d}]`, format))
|
||||
// f.SetConditionalFormat("Sheet1", "A1:A10", fmt.Sprintf(`[{"type":"duplicate","criteria":"=","format":%d}]`, format))
|
||||
//
|
||||
// type: unique - The unique type is used to highlight unique cells in a range:
|
||||
//
|
||||
// // Hightlight cells rules: Not Equal To...
|
||||
// xlsx.SetConditionalFormat("Sheet1", "A1:A10", fmt.Sprintf(`[{"type":"unique","criteria":"=","format":%d}]`, format))
|
||||
// f.SetConditionalFormat("Sheet1", "A1:A10", fmt.Sprintf(`[{"type":"unique","criteria":"=","format":%d}]`, format))
|
||||
//
|
||||
// type: top - The top type is used to specify the top n values by number or percentage in a range:
|
||||
//
|
||||
// // Top/Bottom rules: Top 10.
|
||||
// xlsx.SetConditionalFormat("Sheet1", "H1:H10", fmt.Sprintf(`[{"type":"top","criteria":"=","format":%d,"value":"6"}]`, format))
|
||||
// f.SetConditionalFormat("Sheet1", "H1:H10", fmt.Sprintf(`[{"type":"top","criteria":"=","format":%d,"value":"6"}]`, format))
|
||||
//
|
||||
// The criteria can be used to indicate that a percentage condition is required:
|
||||
//
|
||||
// xlsx.SetConditionalFormat("Sheet1", "A1:A10", fmt.Sprintf(`[{"type":"top","criteria":"=","format":%d,"value":"6","percent":true}]`, format))
|
||||
// f.SetConditionalFormat("Sheet1", "A1:A10", fmt.Sprintf(`[{"type":"top","criteria":"=","format":%d,"value":"6","percent":true}]`, format))
|
||||
//
|
||||
// type: 2_color_scale - The 2_color_scale type is used to specify Excel's "2
|
||||
// Color Scale" style conditional format:
|
||||
//
|
||||
// // Color scales: 2 color.
|
||||
// xlsx.SetConditionalFormat("Sheet1", "A1:A10", `[{"type":"2_color_scale","criteria":"=","min_type":"min","max_type":"max","min_color":"#F8696B","max_color":"#63BE7B"}]`)
|
||||
// f.SetConditionalFormat("Sheet1", "A1:A10", `[{"type":"2_color_scale","criteria":"=","min_type":"min","max_type":"max","min_color":"#F8696B","max_color":"#63BE7B"}]`)
|
||||
//
|
||||
// This conditional type can be modified with min_type, max_type, min_value,
|
||||
// max_value, min_color and max_color, see below.
|
||||
|
@ -2545,7 +2545,7 @@ func (f *File) SetCellStyle(sheet, hcell, vcell string, styleID int) error {
|
|||
// Color Scale" style conditional format:
|
||||
//
|
||||
// // Color scales: 3 color.
|
||||
// xlsx.SetConditionalFormat("Sheet1", "A1:A10", `[{"type":"3_color_scale","criteria":"=","min_type":"min","mid_type":"percentile","max_type":"max","min_color":"#F8696B","mid_color":"#FFEB84","max_color":"#63BE7B"}]`)
|
||||
// f.SetConditionalFormat("Sheet1", "A1:A10", `[{"type":"3_color_scale","criteria":"=","min_type":"min","mid_type":"percentile","max_type":"max","min_color":"#F8696B","mid_color":"#FFEB84","max_color":"#63BE7B"}]`)
|
||||
//
|
||||
// This conditional type can be modified with min_type, mid_type, max_type,
|
||||
// min_value, mid_value, max_value, min_color, mid_color and max_color, see
|
||||
|
@ -2557,7 +2557,7 @@ func (f *File) SetCellStyle(sheet, hcell, vcell string, styleID int) error {
|
|||
// min_type - The min_type and max_type properties are available when the conditional formatting type is 2_color_scale, 3_color_scale or data_bar. The mid_type is available for 3_color_scale. The properties are used as follows:
|
||||
//
|
||||
// // Data Bars: Gradient Fill.
|
||||
// xlsx.SetConditionalFormat("Sheet1", "K1:K10", `[{"type":"data_bar", "criteria":"=", "min_type":"min","max_type":"max","bar_color":"#638EC6"}]`)
|
||||
// f.SetConditionalFormat("Sheet1", "K1:K10", `[{"type":"data_bar", "criteria":"=", "min_type":"min","max_type":"max","bar_color":"#638EC6"}]`)
|
||||
//
|
||||
// The available min/mid/max types are:
|
||||
//
|
||||
|
@ -2586,7 +2586,7 @@ func (f *File) SetCellStyle(sheet, hcell, vcell string, styleID int) error {
|
|||
// follows:
|
||||
//
|
||||
// // Color scales: 3 color.
|
||||
// xlsx.SetConditionalFormat("Sheet1", "B1:B10", `[{"type":"3_color_scale","criteria":"=","min_type":"min","mid_type":"percentile","max_type":"max","min_color":"#F8696B","mid_color":"#FFEB84","max_color":"#63BE7B"}]`)
|
||||
// f.SetConditionalFormat("Sheet1", "B1:B10", `[{"type":"3_color_scale","criteria":"=","min_type":"min","mid_type":"percentile","max_type":"max","min_color":"#F8696B","mid_color":"#FFEB84","max_color":"#63BE7B"}]`)
|
||||
//
|
||||
// mid_color - Used for 3_color_scale. Same as min_color, see above.
|
||||
//
|
||||
|
|
8
table.go
8
table.go
|
@ -33,11 +33,11 @@ func parseFormatTableSet(formatSet string) (*formatTable, error) {
|
|||
// name, coordinate area and format set. For example, create a table of A1:D5
|
||||
// on Sheet1:
|
||||
//
|
||||
// err := xlsx.AddTable("Sheet1", "A1", "D5", ``)
|
||||
// err := f.AddTable("Sheet1", "A1", "D5", ``)
|
||||
//
|
||||
// Create a table of F2:H6 on Sheet2 with format set:
|
||||
//
|
||||
// err := xlsx.AddTable("Sheet2", "F2", "H6", `{"table_name":"table","table_style":"TableStyleMedium2", "show_first_column":true,"show_last_column":true,"show_row_stripes":false,"show_column_stripes":true}`)
|
||||
// err := f.AddTable("Sheet2", "F2", "H6", `{"table_name":"table","table_style":"TableStyleMedium2", "show_first_column":true,"show_last_column":true,"show_row_stripes":false,"show_column_stripes":true}`)
|
||||
//
|
||||
// Note that the table at least two lines include string type header. Multiple
|
||||
// tables coordinate areas can't have an intersection.
|
||||
|
@ -197,11 +197,11 @@ func parseAutoFilterSet(formatSet string) (*formatAutoFilter, error) {
|
|||
// way of filtering a 2D range of data based on some simple criteria. For
|
||||
// example applying an autofilter to a cell range A1:D4 in the Sheet1:
|
||||
//
|
||||
// err = xlsx.AutoFilter("Sheet1", "A1", "D4", "")
|
||||
// err := f.AutoFilter("Sheet1", "A1", "D4", "")
|
||||
//
|
||||
// Filter data in an autofilter:
|
||||
//
|
||||
// err = xlsx.AutoFilter("Sheet1", "A1", "D4", `{"column":"B","expression":"x != blanks"}`)
|
||||
// err := f.AutoFilter("Sheet1", "A1", "D4", `{"column":"B","expression":"x != blanks"}`)
|
||||
//
|
||||
// column defines the filter columns in a autofilter range based on simple
|
||||
// criteria
|
||||
|
|
Loading…
Reference in New Issue