This closes #1244 and closes #1314, improving the compatibility with Google Sheet

- Format code with `gofmt`
pull/2/head
xuri 2 years ago
parent 8152bbb2ce
commit 551fb8a9e4
No known key found for this signature in database
GPG Key ID: BA5E5BB1C948EDF7

@ -35,7 +35,6 @@ const (
// offset: Number of rows/column to insert/delete negative values indicate deletion // offset: Number of rows/column to insert/delete negative values indicate deletion
// //
// TODO: adjustPageBreaks, adjustComments, adjustDataValidations, adjustProtectedCells // TODO: adjustPageBreaks, adjustComments, adjustDataValidations, adjustProtectedCells
//
func (f *File) adjustHelper(sheet string, dir adjustDirection, num, offset int) error { func (f *File) adjustHelper(sheet string, dir adjustDirection, num, offset int) error {
ws, err := f.workSheetReader(sheet) ws, err := f.workSheetReader(sheet)
if err != nil { if err != nil {

2184
calc.go

File diff suppressed because it is too large Load Diff

@ -90,24 +90,24 @@ func (f *File) GetCellType(sheet, axis string) (CellType, error) {
// can be set with string text. The following shows the supported data // can be set with string text. The following shows the supported data
// types: // types:
// //
// int // int
// int8 // int8
// int16 // int16
// int32 // int32
// int64 // int64
// uint // uint
// uint8 // uint8
// uint16 // uint16
// uint32 // uint32
// uint64 // uint64
// float32 // float32
// float64 // float64
// string // string
// []byte // []byte
// time.Duration // time.Duration
// time.Time // time.Time
// bool // bool
// nil // nil
// //
// Note that default date format is m/d/yy h:mm of time.Time type value. You // Note that default date format is m/d/yy h:mm of time.Time type value. You
// can set numbers format by SetCellStyle() method. If you need to set the // can set numbers format by SetCellStyle() method. If you need to set the
@ -334,9 +334,8 @@ func setCellBool(value bool) (t string, v string) {
// represent the number. bitSize is 32 or 64 depending on if a float32 or // represent the number. bitSize is 32 or 64 depending on if a float32 or
// float64 was originally used for the value. For Example: // float64 was originally used for the value. For Example:
// //
// var x float32 = 1.325 // var x float32 = 1.325
// f.SetCellFloat("Sheet1", "A1", float64(x), 2, 32) // f.SetCellFloat("Sheet1", "A1", float64(x), 2, 32)
//
func (f *File) SetCellFloat(sheet, axis string, value float64, precision, bitSize int) error { func (f *File) SetCellFloat(sheet, axis string, value float64, precision, bitSize int) error {
ws, err := f.workSheetReader(sheet) ws, err := f.workSheetReader(sheet)
if err != nil { if err != nil {
@ -522,73 +521,72 @@ type FormulaOpts struct {
// //
// Example 1, set normal formula "=SUM(A1,B1)" for the cell "A3" on "Sheet1": // Example 1, set normal formula "=SUM(A1,B1)" for the cell "A3" on "Sheet1":
// //
// err := f.SetCellFormula("Sheet1", "A3", "=SUM(A1,B1)") // err := f.SetCellFormula("Sheet1", "A3", "=SUM(A1,B1)")
// //
// Example 2, set one-dimensional vertical constant array (row array) formula // Example 2, set one-dimensional vertical constant array (row array) formula
// "1,2,3" for the cell "A3" on "Sheet1": // "1,2,3" for the cell "A3" on "Sheet1":
// //
// err := f.SetCellFormula("Sheet1", "A3", "={1,2,3}") // err := f.SetCellFormula("Sheet1", "A3", "={1,2,3}")
// //
// Example 3, set one-dimensional horizontal constant array (column array) // Example 3, set one-dimensional horizontal constant array (column array)
// formula '"a","b","c"' for the cell "A3" on "Sheet1": // formula '"a","b","c"' for the cell "A3" on "Sheet1":
// //
// err := f.SetCellFormula("Sheet1", "A3", "={\"a\",\"b\",\"c\"}") // err := f.SetCellFormula("Sheet1", "A3", "={\"a\",\"b\",\"c\"}")
// //
// Example 4, set two-dimensional constant array formula '{1,2,"a","b"}' for // Example 4, set two-dimensional constant array formula '{1,2,"a","b"}' for
// the cell "A3" on "Sheet1": // the cell "A3" on "Sheet1":
// //
// formulaType, ref := excelize.STCellFormulaTypeArray, "A3:A3" // formulaType, ref := excelize.STCellFormulaTypeArray, "A3:A3"
// err := f.SetCellFormula("Sheet1", "A3", "={1,2,\"a\",\"b\"}", // err := f.SetCellFormula("Sheet1", "A3", "={1,2,\"a\",\"b\"}",
// excelize.FormulaOpts{Ref: &ref, Type: &formulaType}) // excelize.FormulaOpts{Ref: &ref, Type: &formulaType})
// //
// Example 5, set range array formula "A1:A2" for the cell "A3" on "Sheet1": // Example 5, set range array formula "A1:A2" for the cell "A3" on "Sheet1":
// //
// formulaType, ref := excelize.STCellFormulaTypeArray, "A3:A3" // formulaType, ref := excelize.STCellFormulaTypeArray, "A3:A3"
// err := f.SetCellFormula("Sheet1", "A3", "=A1:A2", // err := f.SetCellFormula("Sheet1", "A3", "=A1:A2",
// excelize.FormulaOpts{Ref: &ref, Type: &formulaType}) // excelize.FormulaOpts{Ref: &ref, Type: &formulaType})
// //
// Example 6, set shared formula "=A1+B1" for the cell "C1:C5" // Example 6, set shared formula "=A1+B1" for the cell "C1:C5"
// on "Sheet1", "C1" is the master cell: // on "Sheet1", "C1" is the master cell:
// //
// formulaType, ref := excelize.STCellFormulaTypeShared, "C1:C5" // formulaType, ref := excelize.STCellFormulaTypeShared, "C1:C5"
// err := f.SetCellFormula("Sheet1", "C1", "=A1+B1", // err := f.SetCellFormula("Sheet1", "C1", "=A1+B1",
// excelize.FormulaOpts{Ref: &ref, Type: &formulaType}) // excelize.FormulaOpts{Ref: &ref, Type: &formulaType})
// //
// Example 7, set table formula "=SUM(Table1[[A]:[B]])" for the cell "C2" // Example 7, set table formula "=SUM(Table1[[A]:[B]])" for the cell "C2"
// on "Sheet1": // on "Sheet1":
// //
// package main // package main
//
// import (
// "fmt"
// //
// "github.com/xuri/excelize/v2" // import (
// ) // "fmt"
// //
// func main() { // "github.com/xuri/excelize/v2"
// f := excelize.NewFile() // )
// for idx, row := range [][]interface{}{{"A", "B", "C"}, {1, 2}} {
// if err := f.SetSheetRow("Sheet1", fmt.Sprintf("A%d", idx+1), &row); err != nil {
// fmt.Println(err)
// return
// }
// }
// if err := f.AddTable("Sheet1", "A1", "C2",
// `{"table_name":"Table1","table_style":"TableStyleMedium2"}`); err != nil {
// fmt.Println(err)
// return
// }
// formulaType := excelize.STCellFormulaTypeDataTable
// if err := f.SetCellFormula("Sheet1", "C2", "=SUM(Table1[[A]:[B]])",
// excelize.FormulaOpts{Type: &formulaType}); err != nil {
// fmt.Println(err)
// return
// }
// if err := f.SaveAs("Book1.xlsx"); err != nil {
// fmt.Println(err)
// }
// }
// //
// func main() {
// f := excelize.NewFile()
// for idx, row := range [][]interface{}{{"A", "B", "C"}, {1, 2}} {
// if err := f.SetSheetRow("Sheet1", fmt.Sprintf("A%d", idx+1), &row); err != nil {
// fmt.Println(err)
// return
// }
// }
// if err := f.AddTable("Sheet1", "A1", "C2",
// `{"table_name":"Table1","table_style":"TableStyleMedium2"}`); err != nil {
// fmt.Println(err)
// return
// }
// formulaType := excelize.STCellFormulaTypeDataTable
// if err := f.SetCellFormula("Sheet1", "C2", "=SUM(Table1[[A]:[B]])",
// excelize.FormulaOpts{Type: &formulaType}); err != nil {
// fmt.Println(err)
// return
// }
// if err := f.SaveAs("Book1.xlsx"); err != nil {
// fmt.Println(err)
// }
// }
func (f *File) SetCellFormula(sheet, axis, formula string, opts ...FormulaOpts) error { func (f *File) SetCellFormula(sheet, axis, formula string, opts ...FormulaOpts) error {
ws, err := f.workSheetReader(sheet) ws, err := f.workSheetReader(sheet)
if err != nil { if err != nil {
@ -671,8 +669,7 @@ func (ws *xlsxWorksheet) countSharedFormula() (count int) {
// //
// For example, get a hyperlink to a 'H6' cell on a worksheet named 'Sheet1': // For example, get a hyperlink to a 'H6' cell on a worksheet named 'Sheet1':
// //
// link, target, err := f.GetCellHyperLink("Sheet1", "H6") // link, target, err := f.GetCellHyperLink("Sheet1", "H6")
//
func (f *File) GetCellHyperLink(sheet, axis string) (bool, string, error) { func (f *File) GetCellHyperLink(sheet, axis string) (bool, string, error) {
// Check for correct cell name // Check for correct cell name
if _, _, err := SplitCellName(axis); err != nil { if _, _, err := SplitCellName(axis); err != nil {
@ -714,27 +711,26 @@ type HyperlinkOpts struct {
// the other functions such as `SetCellStyle` or `SetSheetRow`. The below is // the other functions such as `SetCellStyle` or `SetSheetRow`. The below is
// example for external link. // example for external link.
// //
// display, tooltip := "https://github.com/xuri/excelize", "Excelize on GitHub" // display, tooltip := "https://github.com/xuri/excelize", "Excelize on GitHub"
// if err := f.SetCellHyperLink("Sheet1", "A3", // if err := f.SetCellHyperLink("Sheet1", "A3",
// "https://github.com/xuri/excelize", "External", excelize.HyperlinkOpts{ // "https://github.com/xuri/excelize", "External", excelize.HyperlinkOpts{
// Display: &display, // Display: &display,
// Tooltip: &tooltip, // Tooltip: &tooltip,
// }); err != nil { // }); err != nil {
// fmt.Println(err) // fmt.Println(err)
// } // }
// // Set underline and font color style for the cell. // // Set underline and font color style for the cell.
// style, err := f.NewStyle(&excelize.Style{ // style, err := f.NewStyle(&excelize.Style{
// Font: &excelize.Font{Color: "#1265BE", Underline: "single"}, // Font: &excelize.Font{Color: "#1265BE", Underline: "single"},
// }) // })
// if err != nil { // if err != nil {
// fmt.Println(err) // fmt.Println(err)
// } // }
// err = f.SetCellStyle("Sheet1", "A3", "A3", style) // err = f.SetCellStyle("Sheet1", "A3", "A3", style)
// //
// This is another example for "Location": // This is another example for "Location":
// //
// err := f.SetCellHyperLink("Sheet1", "A3", "Sheet1!A40", "Location") // err := f.SetCellHyperLink("Sheet1", "A3", "Sheet1!A40", "Location")
//
func (f *File) SetCellHyperLink(sheet, axis, link, linkType string, opts ...HyperlinkOpts) error { func (f *File) SetCellHyperLink(sheet, axis, link, linkType string, opts ...HyperlinkOpts) error {
// Check for correct cell name // Check for correct cell name
if _, _, err := SplitCellName(axis); err != nil { if _, _, err := SplitCellName(axis); err != nil {
@ -892,121 +888,120 @@ func newRpr(fnt *Font) *xlsxRPr {
// worksheet. For example, set rich text on the A1 cell of the worksheet named // worksheet. For example, set rich text on the A1 cell of the worksheet named
// Sheet1: // Sheet1:
// //
// package main // package main
//
// import (
// "fmt"
// //
// "github.com/xuri/excelize/v2" // import (
// ) // "fmt"
// //
// func main() { // "github.com/xuri/excelize/v2"
// f := excelize.NewFile() // )
// if err := f.SetRowHeight("Sheet1", 1, 35); err != nil {
// fmt.Println(err)
// return
// }
// if err := f.SetColWidth("Sheet1", "A", "A", 44); err != nil {
// fmt.Println(err)
// return
// }
// if err := f.SetCellRichText("Sheet1", "A1", []excelize.RichTextRun{
// {
// Text: "bold",
// Font: &excelize.Font{
// Bold: true,
// Color: "2354e8",
// Family: "Times New Roman",
// },
// },
// {
// Text: " and ",
// Font: &excelize.Font{
// Family: "Times New Roman",
// },
// },
// {
// Text: "italic ",
// Font: &excelize.Font{
// Bold: true,
// Color: "e83723",
// Italic: true,
// Family: "Times New Roman",
// },
// },
// {
// Text: "text with color and font-family,",
// Font: &excelize.Font{
// Bold: true,
// Color: "2354e8",
// Family: "Times New Roman",
// },
// },
// {
// Text: "\r\nlarge text with ",
// Font: &excelize.Font{
// Size: 14,
// Color: "ad23e8",
// },
// },
// {
// Text: "strike",
// Font: &excelize.Font{
// Color: "e89923",
// Strike: true,
// },
// },
// {
// Text: " superscript",
// Font: &excelize.Font{
// Color: "dbc21f",
// VertAlign: "superscript",
// },
// },
// {
// Text: " and ",
// Font: &excelize.Font{
// Size: 14,
// Color: "ad23e8",
// VertAlign: "baseline",
// },
// },
// {
// Text: "underline",
// Font: &excelize.Font{
// Color: "23e833",
// Underline: "single",
// },
// },
// {
// Text: " subscript.",
// Font: &excelize.Font{
// Color: "017505",
// VertAlign: "subscript",
// },
// },
// }); err != nil {
// fmt.Println(err)
// return
// }
// style, err := f.NewStyle(&excelize.Style{
// Alignment: &excelize.Alignment{
// WrapText: true,
// },
// })
// if err != nil {
// fmt.Println(err)
// return
// }
// if err := f.SetCellStyle("Sheet1", "A1", "A1", style); err != nil {
// fmt.Println(err)
// return
// }
// if err := f.SaveAs("Book1.xlsx"); err != nil {
// fmt.Println(err)
// }
// }
// //
// func main() {
// f := excelize.NewFile()
// if err := f.SetRowHeight("Sheet1", 1, 35); err != nil {
// fmt.Println(err)
// return
// }
// if err := f.SetColWidth("Sheet1", "A", "A", 44); err != nil {
// fmt.Println(err)
// return
// }
// if err := f.SetCellRichText("Sheet1", "A1", []excelize.RichTextRun{
// {
// Text: "bold",
// Font: &excelize.Font{
// Bold: true,
// Color: "2354e8",
// Family: "Times New Roman",
// },
// },
// {
// Text: " and ",
// Font: &excelize.Font{
// Family: "Times New Roman",
// },
// },
// {
// Text: "italic ",
// Font: &excelize.Font{
// Bold: true,
// Color: "e83723",
// Italic: true,
// Family: "Times New Roman",
// },
// },
// {
// Text: "text with color and font-family,",
// Font: &excelize.Font{
// Bold: true,
// Color: "2354e8",
// Family: "Times New Roman",
// },
// },
// {
// Text: "\r\nlarge text with ",
// Font: &excelize.Font{
// Size: 14,
// Color: "ad23e8",
// },
// },
// {
// Text: "strike",
// Font: &excelize.Font{
// Color: "e89923",
// Strike: true,
// },
// },
// {
// Text: " superscript",
// Font: &excelize.Font{
// Color: "dbc21f",
// VertAlign: "superscript",
// },
// },
// {
// Text: " and ",
// Font: &excelize.Font{
// Size: 14,
// Color: "ad23e8",
// VertAlign: "baseline",
// },
// },
// {
// Text: "underline",
// Font: &excelize.Font{
// Color: "23e833",
// Underline: "single",
// },
// },
// {
// Text: " subscript.",
// Font: &excelize.Font{
// Color: "017505",
// VertAlign: "subscript",
// },
// },
// }); err != nil {
// fmt.Println(err)
// return
// }
// style, err := f.NewStyle(&excelize.Style{
// Alignment: &excelize.Alignment{
// WrapText: true,
// },
// })
// if err != nil {
// fmt.Println(err)
// return
// }
// if err := f.SetCellStyle("Sheet1", "A1", "A1", style); err != nil {
// fmt.Println(err)
// return
// }
// if err := f.SaveAs("Book1.xlsx"); err != nil {
// fmt.Println(err)
// }
// }
func (f *File) SetCellRichText(sheet, cell string, runs []RichTextRun) error { func (f *File) SetCellRichText(sheet, cell string, runs []RichTextRun) error {
ws, err := f.workSheetReader(sheet) ws, err := f.workSheetReader(sheet)
if err != nil { if err != nil {
@ -1055,8 +1050,7 @@ func (f *File) SetCellRichText(sheet, cell string, runs []RichTextRun) error {
// coordinate and a pointer to array type 'slice'. For example, writes an // coordinate and a pointer to array type 'slice'. For example, writes an
// array to row 6 start with the cell B6 on Sheet1: // array to row 6 start with the cell B6 on Sheet1:
// //
// err := f.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 { func (f *File) SetSheetRow(sheet, axis string, slice interface{}) error {
col, row, err := CellNameToCoordinates(axis) col, row, err := CellNameToCoordinates(axis)
if err != nil { if err != nil {

@ -500,152 +500,152 @@ func parseFormatChartSet(formatSet string) (*formatChart, error) {
// properties set. For example, create 3D clustered column chart with data // properties set. For example, create 3D clustered column chart with data
// Sheet1!$E$1:$L$15: // Sheet1!$E$1:$L$15:
// //
// package main // package main
// //
// import ( // import (
// "fmt" // "fmt"
// //
// "github.com/xuri/excelize/v2" // "github.com/xuri/excelize/v2"
// ) // )
// //
// func main() { // func main() {
// categories := map[string]string{ // categories := map[string]string{
// "A2": "Small", "A3": "Normal", "A4": "Large", // "A2": "Small", "A3": "Normal", "A4": "Large",
// "B1": "Apple", "C1": "Orange", "D1": "Pear"} // "B1": "Apple", "C1": "Orange", "D1": "Pear"}
// values := map[string]int{ // values := map[string]int{
// "B2": 2, "C2": 3, "D2": 3, "B3": 5, "C3": 2, "D3": 4, "B4": 6, "C4": 7, "D4": 8} // "B2": 2, "C2": 3, "D2": 3, "B3": 5, "C3": 2, "D3": 4, "B4": 6, "C4": 7, "D4": 8}
// f := excelize.NewFile() // f := excelize.NewFile()
// for k, v := range categories { // for k, v := range categories {
// f.SetCellValue("Sheet1", k, v) // f.SetCellValue("Sheet1", k, v)
// } // }
// for k, v := range values { // for k, v := range values {
// f.SetCellValue("Sheet1", k, v) // f.SetCellValue("Sheet1", k, v)
// } // }
// if err := f.AddChart("Sheet1", "E1", `{ // if err := f.AddChart("Sheet1", "E1", `{
// "type": "col3DClustered", // "type": "col3DClustered",
// "series": [ // "series": [
// { // {
// "name": "Sheet1!$A$2", // "name": "Sheet1!$A$2",
// "categories": "Sheet1!$B$1:$D$1", // "categories": "Sheet1!$B$1:$D$1",
// "values": "Sheet1!$B$2:$D$2" // "values": "Sheet1!$B$2:$D$2"
// }, // },
// { // {
// "name": "Sheet1!$A$3", // "name": "Sheet1!$A$3",
// "categories": "Sheet1!$B$1:$D$1", // "categories": "Sheet1!$B$1:$D$1",
// "values": "Sheet1!$B$3:$D$3" // "values": "Sheet1!$B$3:$D$3"
// }, // },
// { // {
// "name": "Sheet1!$A$4", // "name": "Sheet1!$A$4",
// "categories": "Sheet1!$B$1:$D$1", // "categories": "Sheet1!$B$1:$D$1",
// "values": "Sheet1!$B$4:$D$4" // "values": "Sheet1!$B$4:$D$4"
// }], // }],
// "title": // "title":
// { // {
// "name": "Fruit 3D Clustered Column Chart" // "name": "Fruit 3D Clustered Column Chart"
// }, // },
// "legend": // "legend":
// { // {
// "none": false, // "none": false,
// "position": "bottom", // "position": "bottom",
// "show_legend_key": false // "show_legend_key": false
// }, // },
// "plotarea": // "plotarea":
// { // {
// "show_bubble_size": true, // "show_bubble_size": true,
// "show_cat_name": false, // "show_cat_name": false,
// "show_leader_lines": false, // "show_leader_lines": false,
// "show_percent": true, // "show_percent": true,
// "show_series_name": true, // "show_series_name": true,
// "show_val": true // "show_val": true
// }, // },
// "show_blanks_as": "zero", // "show_blanks_as": "zero",
// "x_axis": // "x_axis":
// { // {
// "reverse_order": true // "reverse_order": true
// }, // },
// "y_axis": // "y_axis":
// { // {
// "maximum": 7.5, // "maximum": 7.5,
// "minimum": 0.5 // "minimum": 0.5
// } // }
// }`); err != nil { // }`); err != nil {
// fmt.Println(err) // fmt.Println(err)
// return // return
// } // }
// // Save spreadsheet by the given path. // // Save spreadsheet by the given path.
// if err := f.SaveAs("Book1.xlsx"); err != nil { // if err := f.SaveAs("Book1.xlsx"); err != nil {
// fmt.Println(err) // fmt.Println(err)
// } // }
// } // }
// //
// The following shows the type of chart supported by excelize: // The following shows the type of chart supported by excelize:
// //
// Type | Chart // Type | Chart
// -----------------------------+------------------------------ // -----------------------------+------------------------------
// area | 2D area chart // area | 2D area chart
// areaStacked | 2D stacked area chart // areaStacked | 2D stacked area chart
// areaPercentStacked | 2D 100% stacked area chart // areaPercentStacked | 2D 100% stacked area chart
// area3D | 3D area chart // area3D | 3D area chart
// area3DStacked | 3D stacked area chart // area3DStacked | 3D stacked area chart
// area3DPercentStacked | 3D 100% stacked area chart // area3DPercentStacked | 3D 100% stacked area chart
// bar | 2D clustered bar chart // bar | 2D clustered bar chart
// barStacked | 2D stacked bar chart // barStacked | 2D stacked bar chart
// barPercentStacked | 2D 100% stacked bar chart // barPercentStacked | 2D 100% stacked bar chart
// bar3DClustered | 3D clustered bar chart // bar3DClustered | 3D clustered bar chart
// bar3DStacked | 3D stacked bar chart // bar3DStacked | 3D stacked bar chart
// bar3DPercentStacked | 3D 100% stacked bar chart // bar3DPercentStacked | 3D 100% stacked bar chart
// bar3DConeClustered | 3D cone clustered bar chart // bar3DConeClustered | 3D cone clustered bar chart
// bar3DConeStacked | 3D cone stacked bar chart // bar3DConeStacked | 3D cone stacked bar chart
// bar3DConePercentStacked | 3D cone percent bar chart // bar3DConePercentStacked | 3D cone percent bar chart
// bar3DPyramidClustered | 3D pyramid clustered bar chart // bar3DPyramidClustered | 3D pyramid clustered bar chart
// bar3DPyramidStacked | 3D pyramid stacked bar chart // bar3DPyramidStacked | 3D pyramid stacked bar chart
// bar3DPyramidPercentStacked | 3D pyramid percent stacked bar chart // bar3DPyramidPercentStacked | 3D pyramid percent stacked bar chart
// bar3DCylinderClustered | 3D cylinder clustered bar chart // bar3DCylinderClustered | 3D cylinder clustered bar chart
// bar3DCylinderStacked | 3D cylinder stacked bar chart // bar3DCylinderStacked | 3D cylinder stacked bar chart
// bar3DCylinderPercentStacked | 3D cylinder percent stacked bar chart // bar3DCylinderPercentStacked | 3D cylinder percent stacked bar chart
// col | 2D clustered column chart // col | 2D clustered column chart
// colStacked | 2D stacked column chart // colStacked | 2D stacked column chart
// colPercentStacked | 2D 100% stacked column chart // colPercentStacked | 2D 100% stacked column chart
// col3DClustered | 3D clustered column chart // col3DClustered | 3D clustered column chart
// col3D | 3D column chart // col3D | 3D column chart
// col3DStacked | 3D stacked column chart // col3DStacked | 3D stacked column chart
// col3DPercentStacked | 3D 100% stacked column chart // col3DPercentStacked | 3D 100% stacked column chart
// col3DCone | 3D cone column chart // col3DCone | 3D cone column chart
// col3DConeClustered | 3D cone clustered column chart // col3DConeClustered | 3D cone clustered column chart
// col3DConeStacked | 3D cone stacked column chart // col3DConeStacked | 3D cone stacked column chart
// col3DConePercentStacked | 3D cone percent stacked column chart // col3DConePercentStacked | 3D cone percent stacked column chart
// col3DPyramid | 3D pyramid column chart // col3DPyramid | 3D pyramid column chart
// col3DPyramidClustered | 3D pyramid clustered column chart // col3DPyramidClustered | 3D pyramid clustered column chart
// col3DPyramidStacked | 3D pyramid stacked column chart // col3DPyramidStacked | 3D pyramid stacked column chart
// col3DPyramidPercentStacked | 3D pyramid percent stacked column chart // col3DPyramidPercentStacked | 3D pyramid percent stacked column chart
// col3DCylinder | 3D cylinder column chart // col3DCylinder | 3D cylinder column chart
// col3DCylinderClustered | 3D cylinder clustered column chart // col3DCylinderClustered | 3D cylinder clustered column chart
// col3DCylinderStacked | 3D cylinder stacked column chart // col3DCylinderStacked | 3D cylinder stacked column chart
// col3DCylinderPercentStacked | 3D cylinder percent stacked column chart // col3DCylinderPercentStacked | 3D cylinder percent stacked column chart
// doughnut | doughnut chart // doughnut | doughnut chart
// line | line chart // line | line chart
// pie | pie chart // pie | pie chart
// pie3D | 3D pie chart // pie3D | 3D pie chart
// pieOfPie | pie of pie chart // pieOfPie | pie of pie chart
// barOfPie | bar of pie chart // barOfPie | bar of pie chart
// radar | radar chart // radar | radar chart
// scatter | scatter chart // scatter | scatter chart
// surface3D | 3D surface chart // surface3D | 3D surface chart
// wireframeSurface3D | 3D wireframe surface chart // wireframeSurface3D | 3D wireframe surface chart
// contour | contour chart // contour | contour chart
// wireframeContour | wireframe contour chart // wireframeContour | wireframe contour chart
// bubble | bubble chart // bubble | bubble chart
// bubble3D | 3D bubble chart // bubble3D | 3D bubble chart
// //
// In Excel a chart series is a collection of information that defines which data is plotted such as values, axis labels and formatting. // In Excel a chart series is a collection of information that defines which data is plotted such as values, axis labels and formatting.
// //
// The series options that can be set are: // The series options that can be set are:
// //
// name // name
// categories // categories
// values // values
// line // line
// marker // marker
// //
// name: Set the name for the series. The name is displayed in the chart legend and in the formula bar. The name property is optional and if it isn't supplied it will default to Series 1..n. The name can also be a formula such as Sheet1!$A$1 // name: Set the name for the series. The name is displayed in the chart legend and in the formula bar. The name property is optional and if it isn't supplied it will default to Series 1..n. The name can also be a formula such as Sheet1!$A$1
// //
@ -657,48 +657,48 @@ func parseFormatChartSet(formatSet string) (*formatChart, error) {
// //
// marker: This sets the marker of the line chart and scatter chart. The range of optional field 'size' is 2-72 (default value is 5). The enumeration value of optional field 'symbol' are (default value is 'auto'): // marker: This sets the marker of the line chart and scatter chart. The range of optional field 'size' is 2-72 (default value is 5). The enumeration value of optional field 'symbol' are (default value is 'auto'):
// //
// circle // circle
// dash // dash
// diamond // diamond
// dot // dot
// none // none
// picture // picture
// plus // plus
// square // square
// star // star
// triangle // triangle
// x // x
// auto // auto
// //
// Set properties of the chart legend. The options that can be set are: // Set properties of the chart legend. The options that can be set are:
// //
// none // none
// position // position
// show_legend_key // show_legend_key
// //
// none: Specified if show the legend without overlapping the chart. The default value is 'false'. // none: Specified if show the legend without overlapping the chart. The default value is 'false'.
// //
// position: Set the position of the chart legend. The default legend position is right. This parameter only takes effect when 'none' is false. The available positions are: // position: Set the position of the chart legend. The default legend position is right. This parameter only takes effect when 'none' is false. The available positions are:
// //
// top // top
// bottom // bottom
// left // left
// right // right
// top_right // top_right
// //
// show_legend_key: Set the legend keys shall be shown in data labels. The default value is false. // show_legend_key: Set the legend keys shall be shown in data labels. The default value is false.
// //
// Set properties of the chart title. The properties that can be set are: // Set properties of the chart title. The properties that can be set are:
// //
// title // title
// //
// name: Set the name (title) for the chart. The name is displayed above the chart. The name can also be a formula such as Sheet1!$A$1 or a list with a sheetname. The name property is optional. The default is to have no chart title. // name: Set the name (title) for the chart. The name is displayed above the chart. The name can also be a formula such as Sheet1!$A$1 or a list with a sheetname. The name property is optional. The default is to have no chart title.
// //
// Specifies how blank cells are plotted on the chart by show_blanks_as. The default value is gap. The options that can be set are: // Specifies how blank cells are plotted on the chart by show_blanks_as. The default value is gap. The options that can be set are:
// //
// gap // gap
// span // span
// zero // zero
// //
// gap: Specifies that blank values shall be left as a gap. // gap: Specifies that blank values shall be left as a gap.
// //
@ -712,12 +712,12 @@ func parseFormatChartSet(formatSet string) (*formatChart, error) {
// //
// Set the position of the chart plot area by plotarea. The properties that can be set are: // Set the position of the chart plot area by plotarea. The properties that can be set are:
// //
// show_bubble_size // show_bubble_size
// show_cat_name // show_cat_name
// show_leader_lines // show_leader_lines
// show_percent // show_percent
// show_series_name // show_series_name
// show_val // show_val
// //
// show_bubble_size: Specifies the bubble size shall be shown in a data label. The show_bubble_size property is optional. The default value is false. // show_bubble_size: Specifies the bubble size shall be shown in a data label. The show_bubble_size property is optional. The default value is false.
// //
@ -733,23 +733,23 @@ func parseFormatChartSet(formatSet string) (*formatChart, error) {
// //
// Set the primary horizontal and vertical axis options by x_axis and y_axis. The properties of x_axis that can be set are: // Set the primary horizontal and vertical axis options by x_axis and y_axis. The properties of x_axis that can be set are:
// //
// none // none
// major_grid_lines // major_grid_lines
// minor_grid_lines // minor_grid_lines
// tick_label_skip // tick_label_skip
// reverse_order // reverse_order
// maximum // maximum
// minimum // minimum
// //
// The properties of y_axis that can be set are: // The properties of y_axis that can be set are:
// //
// none // none
// major_grid_lines // major_grid_lines
// minor_grid_lines // minor_grid_lines
// major_unit // major_unit
// reverse_order // reverse_order
// maximum // maximum
// minimum // minimum
// //
// none: Disable axes. // none: Disable axes.
// //
@ -773,115 +773,114 @@ func parseFormatChartSet(formatSet string) (*formatChart, error) {
// in a single chart. For example, create a clustered column - line chart with // in a single chart. For example, create a clustered column - line chart with
// data Sheet1!$E$1:$L$15: // data Sheet1!$E$1:$L$15:
// //
// package main // package main
// //
// import ( // import (
// "fmt" // "fmt"
// //
// "github.com/xuri/excelize/v2" // "github.com/xuri/excelize/v2"
// ) // )
//
// 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}
// f := excelize.NewFile()
// for k, v := range categories {
// f.SetCellValue("Sheet1", k, v)
// }
// for k, v := range values {
// f.SetCellValue("Sheet1", k, v)
// }
// if err := f.AddChart("Sheet1", "E1", `{
// "type": "col",
// "series": [
// {
// "name": "Sheet1!$A$2",
// "categories": "",
// "values": "Sheet1!$B$2:$D$2"
// },
// {
// "name": "Sheet1!$A$3",
// "categories": "Sheet1!$B$1:$D$1",
// "values": "Sheet1!$B$3:$D$3"
// }],
// "format":
// {
// "x_scale": 1.0,
// "y_scale": 1.0,
// "x_offset": 15,
// "y_offset": 10,
// "print_obj": true,
// "lock_aspect_ratio": false,
// "locked": false
// },
// "title":
// {
// "name": "Clustered Column - Line Chart"
// },
// "legend":
// {
// "position": "left",
// "show_legend_key": false
// },
// "plotarea":
// {
// "show_bubble_size": true,
// "show_cat_name": false,
// "show_leader_lines": false,
// "show_percent": true,
// "show_series_name": true,
// "show_val": true
// }
// }`, `{
// "type": "line",
// "series": [
// {
// "name": "Sheet1!$A$4",
// "categories": "Sheet1!$B$1:$D$1",
// "values": "Sheet1!$B$4:$D$4",
// "marker":
// {
// "symbol": "none",
// "size": 10
// }
// }],
// "format":
// {
// "x_scale": 1,
// "y_scale": 1,
// "x_offset": 15,
// "y_offset": 10,
// "print_obj": true,
// "lock_aspect_ratio": false,
// "locked": false
// },
// "legend":
// {
// "position": "right",
// "show_legend_key": false
// },
// "plotarea":
// {
// "show_bubble_size": true,
// "show_cat_name": false,
// "show_leader_lines": false,
// "show_percent": true,
// "show_series_name": true,
// "show_val": true
// }
// }`); err != nil {
// fmt.Println(err)
// return
// }
// // Save spreadsheet file by the given path.
// if err := f.SaveAs("Book1.xlsx"); err != nil {
// fmt.Println(err)
// }
// }
// //
// 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}
// f := excelize.NewFile()
// for k, v := range categories {
// f.SetCellValue("Sheet1", k, v)
// }
// for k, v := range values {
// f.SetCellValue("Sheet1", k, v)
// }
// if err := f.AddChart("Sheet1", "E1", `{
// "type": "col",
// "series": [
// {
// "name": "Sheet1!$A$2",
// "categories": "",
// "values": "Sheet1!$B$2:$D$2"
// },
// {
// "name": "Sheet1!$A$3",
// "categories": "Sheet1!$B$1:$D$1",
// "values": "Sheet1!$B$3:$D$3"
// }],
// "format":
// {
// "x_scale": 1.0,
// "y_scale": 1.0,
// "x_offset": 15,
// "y_offset": 10,
// "print_obj": true,
// "lock_aspect_ratio": false,
// "locked": false
// },
// "title":
// {
// "name": "Clustered Column - Line Chart"
// },
// "legend":
// {
// "position": "left",
// "show_legend_key": false
// },
// "plotarea":
// {
// "show_bubble_size": true,
// "show_cat_name": false,
// "show_leader_lines": false,
// "show_percent": true,
// "show_series_name": true,
// "show_val": true
// }
// }`, `{
// "type": "line",
// "series": [
// {
// "name": "Sheet1!$A$4",
// "categories": "Sheet1!$B$1:$D$1",
// "values": "Sheet1!$B$4:$D$4",
// "marker":
// {
// "symbol": "none",
// "size": 10
// }
// }],
// "format":
// {
// "x_scale": 1,
// "y_scale": 1,
// "x_offset": 15,
// "y_offset": 10,
// "print_obj": true,
// "lock_aspect_ratio": false,
// "locked": false
// },
// "legend":
// {
// "position": "right",
// "show_legend_key": false
// },
// "plotarea":
// {
// "show_bubble_size": true,
// "show_cat_name": false,
// "show_leader_lines": false,
// "show_percent": true,
// "show_series_name": true,
// "show_val": true
// }
// }`); err != nil {
// fmt.Println(err)
// return
// }
// // Save spreadsheet file by the given path.
// if err := f.SaveAs("Book1.xlsx"); err != nil {
// fmt.Println(err)
// }
// }
func (f *File) AddChart(sheet, cell, format string, combo ...string) error { func (f *File) AddChart(sheet, cell, format string, combo ...string) error {
// Read sheet data. // Read sheet data.
ws, err := f.workSheetReader(sheet) ws, err := f.workSheetReader(sheet)

132
col.go

@ -50,18 +50,17 @@ type Cols struct {
// worksheet named // worksheet named
// 'Sheet1': // 'Sheet1':
// //
// cols, err := f.GetCols("Sheet1") // cols, err := f.GetCols("Sheet1")
// if err != nil { // if err != nil {
// fmt.Println(err) // fmt.Println(err)
// return // return
// } // }
// for _, col := range cols { // for _, col := range cols {
// for _, rowCell := range col { // for _, rowCell := range col {
// fmt.Print(rowCell, "\t") // fmt.Print(rowCell, "\t")
// } // }
// fmt.Println() // fmt.Println()
// } // }
//
func (f *File) GetCols(sheet string, opts ...Options) ([][]string, error) { func (f *File) GetCols(sheet string, opts ...Options) ([][]string, error) {
cols, err := f.Cols(sheet) cols, err := f.Cols(sheet)
if err != nil { if err != nil {
@ -187,22 +186,21 @@ func columnXMLHandler(colIterator *columnXMLIterator, xmlElement *xml.StartEleme
// Cols returns a columns iterator, used for streaming reading data for a // Cols returns a columns iterator, used for streaming reading data for a
// worksheet with a large data. For example: // worksheet with a large data. For example:
// //
// cols, err := f.Cols("Sheet1") // cols, err := f.Cols("Sheet1")
// if err != nil { // if err != nil {
// fmt.Println(err) // fmt.Println(err)
// return // return
// } // }
// for cols.Next() { // for cols.Next() {
// col, err := cols.Rows() // col, err := cols.Rows()
// if err != nil { // if err != nil {
// fmt.Println(err) // fmt.Println(err)
// } // }
// for _, rowCell := range col { // for _, rowCell := range col {
// fmt.Print(rowCell, "\t") // fmt.Print(rowCell, "\t")
// } // }
// fmt.Println() // fmt.Println()
// } // }
//
func (f *File) Cols(sheet string) (*Cols, error) { func (f *File) Cols(sheet string) (*Cols, error) {
name, ok := f.getSheetXMLPath(sheet) name, ok := f.getSheetXMLPath(sheet)
if !ok { if !ok {
@ -244,8 +242,7 @@ func (f *File) Cols(sheet string) (*Cols, error) {
// worksheet name and column name. For example, get visible state of column D // worksheet name and column name. For example, get visible state of column D
// in Sheet1: // in Sheet1:
// //
// visible, err := f.GetColVisible("Sheet1", "D") // visible, err := f.GetColVisible("Sheet1", "D")
//
func (f *File) GetColVisible(sheet, col string) (bool, error) { func (f *File) GetColVisible(sheet, col string) (bool, error) {
colNum, err := ColumnNameToNumber(col) colNum, err := ColumnNameToNumber(col)
if err != nil { if err != nil {
@ -273,12 +270,11 @@ func (f *File) GetColVisible(sheet, col string) (bool, error) {
// //
// For example hide column D on Sheet1: // For example hide column D on Sheet1:
// //
// err := f.SetColVisible("Sheet1", "D", false) // err := f.SetColVisible("Sheet1", "D", false)
// //
// Hide the columns from D to F (included): // Hide the columns from D to F (included):
// //
// err := f.SetColVisible("Sheet1", "D:F", false) // err := f.SetColVisible("Sheet1", "D:F", false)
//
func (f *File) SetColVisible(sheet, columns string, visible bool) error { func (f *File) SetColVisible(sheet, columns string, visible bool) error {
start, end, err := f.parseColRange(columns) start, end, err := f.parseColRange(columns)
if err != nil { if err != nil {
@ -318,8 +314,7 @@ func (f *File) SetColVisible(sheet, columns string, visible bool) error {
// column by given worksheet name and column name. For example, get outline // column by given worksheet name and column name. For example, get outline
// level of column D in Sheet1: // level of column D in Sheet1:
// //
// level, err := f.GetColOutlineLevel("Sheet1", "D") // level, err := f.GetColOutlineLevel("Sheet1", "D")
//
func (f *File) GetColOutlineLevel(sheet, col string) (uint8, error) { func (f *File) GetColOutlineLevel(sheet, col string) (uint8, error) {
level := uint8(0) level := uint8(0)
colNum, err := ColumnNameToNumber(col) colNum, err := ColumnNameToNumber(col)
@ -365,8 +360,7 @@ func (f *File) parseColRange(columns string) (start, end int, err error) {
// column by given worksheet name and column name. The value of parameter // column by given worksheet name and column name. The value of parameter
// 'level' is 1-7. For example, set outline level of column D in Sheet1 to 2: // 'level' is 1-7. For example, set outline level of column D in Sheet1 to 2:
// //
// err := f.SetColOutlineLevel("Sheet1", "D", 2) // err := f.SetColOutlineLevel("Sheet1", "D", 2)
//
func (f *File) SetColOutlineLevel(sheet, col string, level uint8) error { func (f *File) SetColOutlineLevel(sheet, col string, level uint8) error {
if level > 7 || level < 1 { if level > 7 || level < 1 {
return ErrOutlineLevel return ErrOutlineLevel
@ -411,12 +405,11 @@ func (f *File) SetColOutlineLevel(sheet, col string, level uint8) error {
// //
// For example set style of column H on Sheet1: // For example set style of column H on Sheet1:
// //
// err = f.SetColStyle("Sheet1", "H", style) // err = f.SetColStyle("Sheet1", "H", style)
// //
// Set style of columns C:F on Sheet1: // Set style of columns C:F on Sheet1:
// //
// err = f.SetColStyle("Sheet1", "C:F", style) // err = f.SetColStyle("Sheet1", "C:F", style)
//
func (f *File) SetColStyle(sheet, columns string, styleID int) error { func (f *File) SetColStyle(sheet, columns string, styleID int) error {
start, end, err := f.parseColRange(columns) start, end, err := f.parseColRange(columns)
if err != nil { if err != nil {
@ -457,9 +450,8 @@ func (f *File) SetColStyle(sheet, columns string, styleID int) error {
// SetColWidth provides a function to set the width of a single column or // SetColWidth provides a function to set the width of a single column or
// multiple columns. For example: // multiple columns. For example:
// //
// f := excelize.NewFile() // f := excelize.NewFile()
// err := f.SetColWidth("Sheet1", "A", "H", 20) // err := f.SetColWidth("Sheet1", "A", "H", 20)
//
func (f *File) SetColWidth(sheet, startCol, endCol string, width float64) error { func (f *File) SetColWidth(sheet, startCol, endCol string, width float64) error {
min, err := ColumnNameToNumber(startCol) min, err := ColumnNameToNumber(startCol)
if err != nil { if err != nil {
@ -538,25 +530,25 @@ func flatCols(col xlsxCol, cols []xlsxCol, replacer func(fc, c xlsxCol) xlsxCol)
// positionObjectPixels calculate the vertices that define the position of a // positionObjectPixels calculate the vertices that define the position of a
// graphical object within the worksheet in pixels. // graphical object within the worksheet in pixels.
// //
// +------------+------------+ // +------------+------------+
// | A | B | // | A | B |
// +-----+------------+------------+ // +-----+------------+------------+
// | |(x1,y1) | | // | |(x1,y1) | |
// | 1 |(A1)._______|______ | // | 1 |(A1)._______|______ |
// | | | | | // | | | | |
// | | | | | // | | | | |
// +-----+----| OBJECT |-----+ // +-----+----| OBJECT |-----+
// | | | | | // | | | | |
// | 2 | |______________. | // | 2 | |______________. |
// | | | (B2)| // | | | (B2)|
// | | | (x2,y2)| // | | | (x2,y2)|
// +-----+------------+------------+ // +-----+------------+------------+
// //
// Example of an object that covers some area from cell A1 to B2. // Example of an object that covers some area from cell A1 to B2.
// //
// Based on the width and height of the object we need to calculate 8 vars: // Based on the width and height of the object we need to calculate 8 vars:
// //
// colStart, rowStart, colEnd, rowEnd, x1, y1, x2, y2. // colStart, rowStart, colEnd, rowEnd, x1, y1, x2, y2.
// //
// We also calculate the absolute x and y position of the top left vertex of // We also calculate the absolute x and y position of the top left vertex of
// the object. This is required for images. // the object. This is required for images.
@ -569,21 +561,20 @@ func flatCols(col xlsxCol, cols []xlsxCol, replacer func(fc, c xlsxCol) xlsxCol)
// subtracting the width and height of the object from the width and // subtracting the width and height of the object from the width and
// height of the underlying cells. // height of the underlying cells.
// //
// colStart # Col containing upper left corner of object. // colStart # Col containing upper left corner of object.
// x1 # Distance to left side of object. // x1 # Distance to left side of object.
// //
// rowStart # Row containing top left corner of object. // rowStart # Row containing top left corner of object.
// y1 # Distance to top of object. // y1 # Distance to top of object.
// //
// colEnd # Col containing lower right corner of object. // colEnd # Col containing lower right corner of object.
// x2 # Distance to right side of object. // x2 # Distance to right side of object.
// //
// rowEnd # Row containing bottom right corner of object. // rowEnd # Row containing bottom right corner of object.
// y2 # Distance to bottom of object. // y2 # Distance to bottom of object.
//
// width # Width of object frame.
// height # Height of object frame.
// //
// width # Width of object frame.
// height # Height of object frame.
func (f *File) positionObjectPixels(sheet string, col, row, x1, y1, width, height int) (int, int, int, int, int, int) { func (f *File) positionObjectPixels(sheet string, col, row, x1, y1, width, height int) (int, int, int, int, int, int) {
// Adjust start column for offsets that are greater than the col width. // Adjust start column for offsets that are greater than the col width.
for x1 >= f.getColWidth(sheet, col) { for x1 >= f.getColWidth(sheet, col) {
@ -669,8 +660,7 @@ func (f *File) GetColWidth(sheet, col string) (float64, error) {
// InsertCol provides a function to insert a new column before given column // InsertCol provides a function to insert a new column before given column
// index. For example, create a new column before column C in Sheet1: // index. For example, create a new column before column C in Sheet1:
// //
// err := f.InsertCol("Sheet1", "C") // err := f.InsertCol("Sheet1", "C")
//
func (f *File) InsertCol(sheet, col string) error { func (f *File) InsertCol(sheet, col string) error {
num, err := ColumnNameToNumber(col) num, err := ColumnNameToNumber(col)
if err != nil { if err != nil {
@ -682,7 +672,7 @@ func (f *File) InsertCol(sheet, col string) error {
// RemoveCol provides a function to remove single column by given worksheet // RemoveCol provides a function to remove single column by given worksheet
// name and column index. For example, remove column C in Sheet1: // name and column index. For example, remove column C in Sheet1:
// //
// err := f.RemoveCol("Sheet1", "C") // err := f.RemoveCol("Sheet1", "C")
// //
// Use this method with caution, which will affect changes in references such // 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 // as formulas, charts, and so on. If there is any referenced value of the

@ -92,8 +92,7 @@ func (f *File) getSheetComments(sheetFile string) string {
// author length is 255 and the max text length is 32512. For example, add a // author length is 255 and the max text length is 32512. For example, add a
// comment in Sheet1!$A$30: // comment in Sheet1!$A$30:
// //
// err := f.AddComment("Sheet1", "A30", `{"author":"Excelize: ","text":"This is a comment."}`) // err := f.AddComment("Sheet1", "A30", `{"author":"Excelize: ","text":"This is a comment."}`)
//
func (f *File) AddComment(sheet, cell, format string) error { func (f *File) AddComment(sheet, cell, format string) error {
formatSet, err := parseFormatCommentsSet(format) formatSet, err := parseFormatCommentsSet(format)
if err != nil { if err != nil {

@ -1175,10 +1175,9 @@ func (c *cfb) writeSAT(MSATBlocks, SATBlocks, SSATBlocks, directoryBlocks, fileB
// Writer provides a function to create compound file with given info stream // Writer provides a function to create compound file with given info stream
// and package stream. // and package stream.
// //
// MSAT - The master sector allocation table // MSAT - The master sector allocation table
// SSAT - The short sector allocation table // SSAT - The short sector allocation table
// SAT - The sector allocation table // SAT - The sector allocation table
//
func (c *cfb) Writer(encryptionInfoBuffer, encryptedPackage []byte) []byte { func (c *cfb) Writer(encryptionInfoBuffer, encryptedPackage []byte) []byte {
var ( var (
storage cfb storage cfb

@ -166,11 +166,10 @@ func (dd *DataValidation) SetRange(f1, f2 interface{}, t DataValidationType, o D
// Sheet1!A7:B8 with validation criteria source Sheet1!E1:E3 settings, create // Sheet1!A7:B8 with validation criteria source Sheet1!E1:E3 settings, create
// in-cell dropdown by allowing list source: // in-cell dropdown by allowing list source:
// //
// dvRange := excelize.NewDataValidation(true) // dvRange := excelize.NewDataValidation(true)
// dvRange.Sqref = "A7:B8" // dvRange.Sqref = "A7:B8"
// dvRange.SetSqrefDropList("$E$1:$E$3") // dvRange.SetSqrefDropList("$E$1:$E$3")
// f.AddDataValidation("Sheet1", dvRange) // f.AddDataValidation("Sheet1", dvRange)
//
func (dd *DataValidation) SetSqrefDropList(sqref string) { func (dd *DataValidation) SetSqrefDropList(sqref string) {
dd.Formula1 = fmt.Sprintf("<formula1>%s</formula1>", sqref) dd.Formula1 = fmt.Sprintf("<formula1>%s</formula1>", sqref)
dd.Type = convDataValidationType(typeList) dd.Type = convDataValidationType(typeList)
@ -225,29 +224,28 @@ func convDataValidationOperator(o DataValidationOperator) string {
// settings, show error alert after invalid data is entered with "Stop" style // settings, show error alert after invalid data is entered with "Stop" style
// and custom title "error body": // and custom title "error body":
// //
// dvRange := excelize.NewDataValidation(true) // dvRange := excelize.NewDataValidation(true)
// dvRange.Sqref = "A1:B2" // dvRange.Sqref = "A1:B2"
// dvRange.SetRange(10, 20, excelize.DataValidationTypeWhole, excelize.DataValidationOperatorBetween) // dvRange.SetRange(10, 20, excelize.DataValidationTypeWhole, excelize.DataValidationOperatorBetween)
// dvRange.SetError(excelize.DataValidationErrorStyleStop, "error title", "error body") // dvRange.SetError(excelize.DataValidationErrorStyleStop, "error title", "error body")
// err := f.AddDataValidation("Sheet1", dvRange) // err := f.AddDataValidation("Sheet1", dvRange)
// //
// Example 2, set data validation on Sheet1!A3:B4 with validation criteria // Example 2, set data validation on Sheet1!A3:B4 with validation criteria
// settings, and show input message when cell is selected: // settings, and show input message when cell is selected:
// //
// dvRange = excelize.NewDataValidation(true) // dvRange = excelize.NewDataValidation(true)
// dvRange.Sqref = "A3:B4" // dvRange.Sqref = "A3:B4"
// dvRange.SetRange(10, 20, excelize.DataValidationTypeWhole, excelize.DataValidationOperatorGreaterThan) // dvRange.SetRange(10, 20, excelize.DataValidationTypeWhole, excelize.DataValidationOperatorGreaterThan)
// dvRange.SetInput("input title", "input body") // dvRange.SetInput("input title", "input body")
// err = f.AddDataValidation("Sheet1", dvRange) // err = f.AddDataValidation("Sheet1", dvRange)
// //
// Example 3, set data validation on Sheet1!A5:B6 with validation criteria // Example 3, set data validation on Sheet1!A5:B6 with validation criteria
// settings, create in-cell dropdown by allowing list source: // settings, create in-cell dropdown by allowing list source:
// //
// dvRange = excelize.NewDataValidation(true) // dvRange = excelize.NewDataValidation(true)
// dvRange.Sqref = "A5:B6" // dvRange.Sqref = "A5:B6"
// dvRange.SetDropList([]string{"1", "2", "3"}) // dvRange.SetDropList([]string{"1", "2", "3"})
// err = f.AddDataValidation("Sheet1", dvRange) // err = f.AddDataValidation("Sheet1", dvRange)
//
func (f *File) AddDataValidation(sheet string, dv *DataValidation) error { func (f *File) AddDataValidation(sheet string, dv *DataValidation) error {
ws, err := f.workSheetReader(sheet) ws, err := f.workSheetReader(sheet)
if err != nil { if err != nil {

@ -22,50 +22,49 @@ import (
// SetAppProps provides a function to set document application properties. The // SetAppProps provides a function to set document application properties. The
// properties that can be set are: // properties that can be set are:
// //
// Property | Description // Property | Description
// -------------------+-------------------------------------------------------------------------- // -------------------+--------------------------------------------------------------------------
// Application | The name of the application that created this document. // Application | The name of the application that created this document.
// | // |
// ScaleCrop | Indicates the display mode of the document thumbnail. Set this element // ScaleCrop | Indicates the display mode of the document thumbnail. Set this element
// | to 'true' to enable scaling of the document thumbnail to the display. Set // | to 'true' to enable scaling of the document thumbnail to the display. Set
// | this element to 'false' to enable cropping of the document thumbnail to // | this element to 'false' to enable cropping of the document thumbnail to
// | show only sections that will fit the display. // | show only sections that will fit the display.
// | // |
// DocSecurity | Security level of a document as a numeric value. Document security is // DocSecurity | Security level of a document as a numeric value. Document security is
// | defined as: // | defined as:
// | 1 - Document is password protected. // | 1 - Document is password protected.
// | 2 - Document is recommended to be opened as read-only. // | 2 - Document is recommended to be opened as read-only.
// | 3 - Document is enforced to be opened as read-only. // | 3 - Document is enforced to be opened as read-only.
// | 4 - Document is locked for annotation. // | 4 - Document is locked for annotation.
// | // |
// Company | The name of a company associated with the document. // Company | The name of a company associated with the document.
// | // |
// LinksUpToDate | Indicates whether hyperlinks in a document are up-to-date. Set this // LinksUpToDate | Indicates whether hyperlinks in a document are up-to-date. Set this
// | element to 'true' to indicate that hyperlinks are updated. Set this // | element to 'true' to indicate that hyperlinks are updated. Set this
// | element to 'false' to indicate that hyperlinks are outdated. // | element to 'false' to indicate that hyperlinks are outdated.
// | // |
// HyperlinksChanged | Specifies that one or more hyperlinks in this part were updated // HyperlinksChanged | Specifies that one or more hyperlinks in this part were updated
// | exclusively in this part by a producer. The next producer to open this // | exclusively in this part by a producer. The next producer to open this
// | document shall update the hyperlink relationships with the new // | document shall update the hyperlink relationships with the new
// | hyperlinks specified in this part. // | hyperlinks specified in this part.
// | // |
// AppVersion | Specifies the version of the application which produced this document. // AppVersion | Specifies the version of the application which produced this document.
// | The content of this element shall be of the form XX.YYYY where X and Y // | The content of this element shall be of the form XX.YYYY where X and Y
// | represent numerical values, or the document shall be considered // | represent numerical values, or the document shall be considered
// | non-conformant. // | non-conformant.
// //
// For example: // For example:
// //
// err := f.SetAppProps(&excelize.AppProperties{ // err := f.SetAppProps(&excelize.AppProperties{
// Application: "Microsoft Excel", // Application: "Microsoft Excel",
// ScaleCrop: true, // ScaleCrop: true,
// DocSecurity: 3, // DocSecurity: 3,
// Company: "Company Name", // Company: "Company Name",
// LinksUpToDate: true, // LinksUpToDate: true,
// HyperlinksChanged: true, // HyperlinksChanged: true,
// AppVersion: "16.0000", // AppVersion: "16.0000",
// }) // })
//
func (f *File) SetAppProps(appProperties *AppProperties) (err error) { func (f *File) SetAppProps(appProperties *AppProperties) (err error) {
var ( var (
app *xlsxProperties app *xlsxProperties
@ -122,54 +121,53 @@ func (f *File) GetAppProps() (ret *AppProperties, err error) {
// SetDocProps provides a function to set document core properties. The // SetDocProps provides a function to set document core properties. The
// properties that can be set are: // properties that can be set are:
// //
// Property | Description // Property | Description
// ----------------+----------------------------------------------------------------------------- // ----------------+-----------------------------------------------------------------------------
// Title | The name given to the resource. // Title | The name given to the resource.
// | // |
// Subject | The topic of the content of the resource. // Subject | The topic of the content of the resource.
// | // |
// Creator | An entity primarily responsible for making the content of the resource. // Creator | An entity primarily responsible for making the content of the resource.
// | // |
// Keywords | A delimited set of keywords to support searching and indexing. This is // Keywords | A delimited set of keywords to support searching and indexing. This is
// | typically a list of terms that are not available elsewhere in the properties. // | typically a list of terms that are not available elsewhere in the properties.
// | // |
// Description | An explanation of the content of the resource. // Description | An explanation of the content of the resource.
// | // |
// LastModifiedBy | The user who performed the last modification. The identification is // LastModifiedBy | The user who performed the last modification. The identification is
// | environment-specific. // | environment-specific.
// | // |
// Language | The language of the intellectual content of the resource. // Language | The language of the intellectual content of the resource.
// | // |
// Identifier | An unambiguous reference to the resource within a given context. // Identifier | An unambiguous reference to the resource within a given context.
// | // |
// Revision | The topic of the content of the resource. // Revision | The topic of the content of the resource.
// | // |
// ContentStatus | The status of the content. For example: Values might include "Draft", // ContentStatus | The status of the content. For example: Values might include "Draft",
// | "Reviewed" and "Final" // | "Reviewed" and "Final"
// | // |
// Category | A categorization of the content of this package. // Category | A categorization of the content of this package.
// | // |
// Version | The version number. This value is set by the user or by the application. // Version | The version number. This value is set by the user or by the application.
// //
// For example: // For example:
// //
// err := f.SetDocProps(&excelize.DocProperties{ // err := f.SetDocProps(&excelize.DocProperties{
// Category: "category", // Category: "category",
// ContentStatus: "Draft", // ContentStatus: "Draft",
// Created: "2019-06-04T22:00:10Z", // Created: "2019-06-04T22:00:10Z",
// Creator: "Go Excelize", // Creator: "Go Excelize",
// Description: "This file created by Go Excelize", // Description: "This file created by Go Excelize",
// Identifier: "xlsx", // Identifier: "xlsx",
// Keywords: "Spreadsheet", // Keywords: "Spreadsheet",
// LastModifiedBy: "Go Author", // LastModifiedBy: "Go Author",
// Modified: "2019-06-04T22:00:10Z", // Modified: "2019-06-04T22:00:10Z",
// Revision: "0", // Revision: "0",
// Subject: "Test Subject", // Subject: "Test Subject",
// Title: "Test Title", // Title: "Test Title",
// Language: "en-US", // Language: "en-US",
// Version: "1.0.0", // Version: "1.0.0",
// }) // })
//
func (f *File) SetDocProps(docProperties *DocProperties) (err error) { func (f *File) SetDocProps(docProperties *DocProperties) (err error) {
var ( var (
core *decodeCoreProperties core *decodeCoreProperties

@ -92,10 +92,10 @@ type Options struct {
// spreadsheet file struct for it. For example, open spreadsheet with // spreadsheet file struct for it. For example, open spreadsheet with
// password protection: // password protection:
// //
// f, err := excelize.OpenFile("Book1.xlsx", excelize.Options{Password: "password"}) // f, err := excelize.OpenFile("Book1.xlsx", excelize.Options{Password: "password"})
// if err != nil { // if err != nil {
// return // return
// } // }
// //
// Close the file by Close function after opening the spreadsheet. // Close the file by Close function after opening the spreadsheet.
func OpenFile(filename string, opt ...Options) (*File, error) { func OpenFile(filename string, opt ...Options) (*File, error) {
@ -403,21 +403,20 @@ func (f *File) addRels(relPath, relType, target, targetMode string) int {
// //
// For example: // For example:
// //
// <row r="19" spans="2:2"> // <row r="19" spans="2:2">
// <c r="B19"> // <c r="B19">
// <f>SUM(Sheet2!D2,Sheet2!D11)</f> // <f>SUM(Sheet2!D2,Sheet2!D11)</f>
// <v>100</v> // <v>100</v>
// </c> // </c>
// </row> // </row>
// //
// to // to
// //
// <row r="19" spans="2:2"> // <row r="19" spans="2:2">
// <c r="B19"> // <c r="B19">
// <f>SUM(Sheet2!D2,Sheet2!D11)</f> // <f>SUM(Sheet2!D2,Sheet2!D11)</f>
// </c> // </c>
// </row> // </row>
//
func (f *File) UpdateLinkedValue() error { func (f *File) UpdateLinkedValue() error {
wb := f.workbookReader() wb := f.workbookReader()
// recalculate formulas // recalculate formulas
@ -445,16 +444,15 @@ func (f *File) UpdateLinkedValue() error {
// AddVBAProject provides the method to add vbaProject.bin file which contains // AddVBAProject provides the method to add vbaProject.bin file which contains
// functions and/or macros. The file extension should be .xlsm. For example: // functions and/or macros. The file extension should be .xlsm. For example:
// //
// if err := f.SetSheetPrOptions("Sheet1", excelize.CodeName("Sheet1")); err != nil { // if err := f.SetSheetPrOptions("Sheet1", excelize.CodeName("Sheet1")); err != nil {
// fmt.Println(err) // fmt.Println(err)
// } // }
// if err := f.AddVBAProject("vbaProject.bin"); err != nil { // if err := f.AddVBAProject("vbaProject.bin"); err != nil {
// fmt.Println(err) // fmt.Println(err)
// } // }
// if err := f.SaveAs("macros.xlsm"); err != nil { // if err := f.SaveAs("macros.xlsm"); err != nil {
// fmt.Println(err) // fmt.Println(err)
// } // }
//
func (f *File) AddVBAProject(bin string) error { func (f *File) AddVBAProject(bin string) error {
var err error var err error
// Check vbaProject.bin exists first. // Check vbaProject.bin exists first.

@ -24,8 +24,7 @@ import (
// NewFile provides a function to create new file by default template. // NewFile provides a function to create new file by default template.
// For example: // For example:
// //
// f := NewFile() // f := NewFile()
//
func NewFile() *File { func NewFile() *File {
f := newFile() f := newFile()
f.Pkg.Store("_rels/.rels", []byte(xml.Header+templateRels)) f.Pkg.Store("_rels/.rels", []byte(xml.Header+templateRels))

@ -148,8 +148,7 @@ func readFile(file *zip.File) ([]byte, error) {
// //
// Example: // Example:
// //
// excelize.SplitCellName("AK74") // return "AK", 74, nil // excelize.SplitCellName("AK74") // return "AK", 74, nil
//
func SplitCellName(cell string) (string, int, error) { func SplitCellName(cell string) (string, int, error) {
alpha := func(r rune) bool { alpha := func(r rune) bool {
return ('A' <= r && r <= 'Z') || ('a' <= r && r <= 'z') || (r == 36) return ('A' <= r && r <= 'Z') || ('a' <= r && r <= 'z') || (r == 36)
@ -192,8 +191,7 @@ func JoinCellName(col string, row int) (string, error) {
// //
// Example: // Example:
// //
// excelize.ColumnNameToNumber("AK") // returns 37, nil // excelize.ColumnNameToNumber("AK") // returns 37, nil
//
func ColumnNameToNumber(name string) (int, error) { func ColumnNameToNumber(name string) (int, error) {
if len(name) == 0 { if len(name) == 0 {
return -1, newInvalidColumnNameError(name) return -1, newInvalidColumnNameError(name)
@ -222,8 +220,7 @@ func ColumnNameToNumber(name string) (int, error) {
// //
// Example: // Example:
// //
// excelize.ColumnNumberToName(37) // returns "AK", nil // excelize.ColumnNumberToName(37) // returns "AK", nil
//
func ColumnNumberToName(num int) (string, error) { func ColumnNumberToName(num int) (string, error) {
if num < MinColumns || num > MaxColumns { if num < MinColumns || num > MaxColumns {
return "", ErrColumnNumber return "", ErrColumnNumber
@ -241,9 +238,8 @@ func ColumnNumberToName(num int) (string, error) {
// //
// Example: // Example:
// //
// excelize.CellNameToCoordinates("A1") // returns 1, 1, nil // excelize.CellNameToCoordinates("A1") // returns 1, 1, nil
// excelize.CellNameToCoordinates("Z3") // returns 26, 3, nil // excelize.CellNameToCoordinates("Z3") // returns 26, 3, nil
//
func CellNameToCoordinates(cell string) (int, int, error) { func CellNameToCoordinates(cell string) (int, int, error) {
colName, row, err := SplitCellName(cell) colName, row, err := SplitCellName(cell)
if err != nil { if err != nil {
@ -261,9 +257,8 @@ func CellNameToCoordinates(cell string) (int, int, error) {
// //
// Example: // Example:
// //
// excelize.CoordinatesToCellName(1, 1) // returns "A1", nil // excelize.CoordinatesToCellName(1, 1) // returns "A1", nil
// excelize.CoordinatesToCellName(1, 1, true) // returns "$A$1", nil // excelize.CoordinatesToCellName(1, 1, true) // returns "$A$1", nil
//
func CoordinatesToCellName(col, row int, abs ...bool) (string, error) { func CoordinatesToCellName(col, row int, abs ...bool) (string, error) {
if col < 1 || row < 1 { if col < 1 || row < 1 {
return "", fmt.Errorf("invalid cell coordinates [%d, %d]", col, row) return "", fmt.Errorf("invalid cell coordinates [%d, %d]", col, row)
@ -641,7 +636,7 @@ func (f *File) replaceNameSpaceBytes(path string, contentMarshal []byte) []byte
if attr, ok := f.xmlAttr[path]; ok { if attr, ok := f.xmlAttr[path]; ok {
newXmlns = []byte(genXMLNamespace(attr)) newXmlns = []byte(genXMLNamespace(attr))
} }
return bytesReplace(contentMarshal, oldXmlns, newXmlns, -1) return bytesReplace(contentMarshal, oldXmlns, bytes.ReplaceAll(newXmlns, []byte(" mc:Ignorable=\"r\""), []byte{}), -1)
} }
// addNameSpaces provides a function to add an XML attribute by the given // addNameSpaces provides a function to add an XML attribute by the given

@ -27,25 +27,24 @@ func (mc *xlsxMergeCell) Rect() ([]int, error) {
// discards the other values. For example create a merged cell of D3:E9 on // discards the other values. For example create a merged cell of D3:E9 on
// Sheet1: // Sheet1:
// //
// err := f.MergeCell("Sheet1", "D3", "E9") // err := f.MergeCell("Sheet1", "D3", "E9")
// //
// If you create a merged cell that overlaps with another existing merged cell, // If you create a merged cell that overlaps with another existing merged cell,
// those merged cells that already exist will be removed. The cell coordinates // those merged cells that already exist will be removed. The cell coordinates
// tuple after merging in the following range will be: A1(x3,y1) D1(x2,y1) // tuple after merging in the following range will be: A1(x3,y1) D1(x2,y1)
// A8(x3,y4) D8(x2,y4) // A8(x3,y4) D8(x2,y4)
// //
// B1(x1,y1) D1(x2,y1) // B1(x1,y1) D1(x2,y1)
// +------------------------+ // +------------------------+
// | | // | |
// A4(x3,y3) | C4(x4,y3) | // A4(x3,y3) | C4(x4,y3) |
// +------------------------+ | // +------------------------+ |
// | | | | // | | | |
// | |B5(x1,y2) | D5(x2,y2)| // | |B5(x1,y2) | D5(x2,y2)|
// | +------------------------+ // | +------------------------+
// | | // | |
// |A8(x3,y4) C8(x4,y4)| // |A8(x3,y4) C8(x4,y4)|
// +------------------------+ // +------------------------+
//
func (f *File) MergeCell(sheet, hCell, vCell string) error { func (f *File) MergeCell(sheet, hCell, vCell string) error {
rect, err := areaRefToCoordinates(hCell + ":" + vCell) rect, err := areaRefToCoordinates(hCell + ":" + vCell)
if err != nil { if err != nil {
@ -74,7 +73,7 @@ func (f *File) MergeCell(sheet, hCell, vCell string) error {
// UnmergeCell provides a function to unmerge a given coordinate area. // UnmergeCell provides a function to unmerge a given coordinate area.
// For example unmerge area D3:E9 on Sheet1: // For example unmerge area D3:E9 on Sheet1:
// //
// err := f.UnmergeCell("Sheet1", "D3", "E9") // err := f.UnmergeCell("Sheet1", "D3", "E9")
// //
// Attention: overlapped areas will also be unmerged. // Attention: overlapped areas will also be unmerged.
func (f *File) UnmergeCell(sheet string, hCell, vCell string) error { func (f *File) UnmergeCell(sheet string, hCell, vCell string) error {

@ -42,34 +42,34 @@ func parseFormatPictureSet(formatSet string) (*formatPicture, error) {
// format set (such as offset, scale, aspect ratio setting and print settings) // format set (such as offset, scale, aspect ratio setting and print settings)
// and file path. For example: // and file path. For example:
// //
// package main // package main
// //
// import ( // import (
// _ "image/gif" // _ "image/gif"
// _ "image/jpeg" // _ "image/jpeg"
// _ "image/png" // _ "image/png"
// //
// "github.com/xuri/excelize/v2" // "github.com/xuri/excelize/v2"
// ) // )
// //
// func main() { // func main() {
// f := excelize.NewFile() // f := excelize.NewFile()
// // Insert a picture. // // Insert a picture.
// if err := f.AddPicture("Sheet1", "A2", "image.jpg", ""); err != nil { // if err := f.AddPicture("Sheet1", "A2", "image.jpg", ""); err != nil {
// fmt.Println(err) // fmt.Println(err)
// } // }
// // Insert a picture scaling in the cell with location hyperlink. // // Insert a picture scaling in the cell with location hyperlink.
// if err := f.AddPicture("Sheet1", "D2", "image.png", `{"x_scale": 0.5, "y_scale": 0.5, "hyperlink": "#Sheet2!D8", "hyperlink_type": "Location"}`); err != nil { // if err := f.AddPicture("Sheet1", "D2", "image.png", `{"x_scale": 0.5, "y_scale": 0.5, "hyperlink": "#Sheet2!D8", "hyperlink_type": "Location"}`); err != nil {
// fmt.Println(err) // fmt.Println(err)
// } // }
// // Insert a picture offset in the cell with external hyperlink, printing and positioning support. // // Insert a picture offset in the cell with external hyperlink, printing and positioning support.
// if err := f.AddPicture("Sheet1", "H2", "image.gif", `{"x_offset": 15, "y_offset": 10, "hyperlink": "https://github.com/xuri/excelize", "hyperlink_type": "External", "print_obj": true, "lock_aspect_ratio": false, "locked": false, "positioning": "oneCell"}`); err != nil { // if err := f.AddPicture("Sheet1", "H2", "image.gif", `{"x_offset": 15, "y_offset": 10, "hyperlink": "https://github.com/xuri/excelize", "hyperlink_type": "External", "print_obj": true, "lock_aspect_ratio": false, "locked": false, "positioning": "oneCell"}`); err != nil {
// fmt.Println(err) // fmt.Println(err)
// } // }
// if err := f.SaveAs("Book1.xlsx"); err != nil { // if err := f.SaveAs("Book1.xlsx"); err != nil {
// fmt.Println(err) // fmt.Println(err)
// } // }
// } // }
// //
// The optional parameter "autofit" specifies if you make image size auto-fits the // The optional parameter "autofit" specifies if you make image size auto-fits the
// cell, the default value of that is 'false'. // cell, the default value of that is 'false'.
@ -106,7 +106,6 @@ func parseFormatPictureSet(formatSet string) (*formatPicture, error) {
// //
// The optional parameter "y_scale" specifies the vertical scale of images, // The optional parameter "y_scale" specifies the vertical scale of images,
// the default value of that is 1.0 which presents 100%. // the default value of that is 1.0 which presents 100%.
//
func (f *File) AddPicture(sheet, cell, picture, format string) error { func (f *File) AddPicture(sheet, cell, picture, format string) error {
var err error var err error
// Check picture exists first. // Check picture exists first.
@ -126,31 +125,30 @@ func (f *File) AddPicture(sheet, cell, picture, format string) error {
// picture format set (such as offset, scale, aspect ratio setting and print // picture format set (such as offset, scale, aspect ratio setting and print
// settings), file base name, extension name and file bytes. For example: // settings), file base name, extension name and file bytes. For example:
// //
// package main // package main
//
// import (
// "fmt"
// _ "image/jpeg"
// "io/ioutil"
// //
// "github.com/xuri/excelize/v2" // import (
// ) // "fmt"
// _ "image/jpeg"
// "io/ioutil"
// //
// func main() { // "github.com/xuri/excelize/v2"
// f := excelize.NewFile() // )
// //
// file, err := ioutil.ReadFile("image.jpg") // func main() {
// if err != nil { // f := excelize.NewFile()
// fmt.Println(err)
// }
// if err := f.AddPictureFromBytes("Sheet1", "A2", "", "Excel Logo", ".jpg", file); err != nil {
// fmt.Println(err)
// }
// if err := f.SaveAs("Book1.xlsx"); err != nil {
// fmt.Println(err)
// }
// }
// //
// file, err := ioutil.ReadFile("image.jpg")
// if err != nil {
// fmt.Println(err)
// }
// if err := f.AddPictureFromBytes("Sheet1", "A2", "", "Excel Logo", ".jpg", file); err != nil {
// fmt.Println(err)
// }
// if err := f.SaveAs("Book1.xlsx"); err != nil {
// fmt.Println(err)
// }
// }
func (f *File) AddPictureFromBytes(sheet, cell, format, name, extension string, file []byte) error { func (f *File) AddPictureFromBytes(sheet, cell, format, name, extension string, file []byte) error {
var drawingHyperlinkRID int var drawingHyperlinkRID int
var hyperlinkType string var hyperlinkType string
@ -474,25 +472,24 @@ func (f *File) getSheetRelationshipsTargetByID(sheet, rID string) string {
// returns the file name in spreadsheet and file contents as []byte data // returns the file name in spreadsheet and file contents as []byte data
// types. For example: // types. For example:
// //
// f, err := excelize.OpenFile("Book1.xlsx") // f, err := excelize.OpenFile("Book1.xlsx")
// if err != nil { // if err != nil {
// fmt.Println(err) // fmt.Println(err)
// return // return
// } // }
// defer func() { // defer func() {
// if err := f.Close(); err != nil { // if err := f.Close(); err != nil {
// fmt.Println(err) // fmt.Println(err)
// } // }
// }() // }()
// file, raw, err := f.GetPicture("Sheet1", "A2") // file, raw, err := f.GetPicture("Sheet1", "A2")
// if err != nil { // if err != nil {
// fmt.Println(err) // fmt.Println(err)
// return // return
// } // }
// if err := ioutil.WriteFile(file, raw, 0644); err != nil { // if err := ioutil.WriteFile(file, raw, 0644); err != nil {
// fmt.Println(err) // fmt.Println(err)
// } // }
//
func (f *File) GetPicture(sheet, cell string) (string, []byte, error) { func (f *File) GetPicture(sheet, cell string) (string, []byte, error) {
col, row, err := CellNameToCoordinates(cell) col, row, err := CellNameToCoordinates(cell)
if err != nil { if err != nil {

@ -22,10 +22,9 @@ import (
// //
// PivotTableStyleName: The built-in pivot table style names // PivotTableStyleName: The built-in pivot table style names
// //
// PivotStyleLight1 - PivotStyleLight28 // PivotStyleLight1 - PivotStyleLight28
// PivotStyleMedium1 - PivotStyleMedium28 // PivotStyleMedium1 - PivotStyleMedium28
// PivotStyleDark1 - PivotStyleDark28 // PivotStyleDark1 - PivotStyleDark28
//
type PivotTableOption struct { type PivotTableOption struct {
pivotTableSheetName string pivotTableSheetName string
DataRange string DataRange string
@ -55,17 +54,17 @@ type PivotTableOption struct {
// field. The default value is sum. The possible values for this attribute // field. The default value is sum. The possible values for this attribute
// are: // are:
// //
// Average // Average
// Count // Count
// CountNums // CountNums
// Max // Max
// Min // Min
// Product // Product
// StdDev // StdDev
// StdDevp // StdDevp
// Sum // Sum
// Var // Var
// Varp // Varp
// //
// Name specifies the name of the data field. Maximum 255 characters // Name specifies the name of the data field. Maximum 255 characters
// are allowed in data field name, excess characters will be truncated. // are allowed in data field name, excess characters will be truncated.
@ -85,51 +84,50 @@ type PivotTableField struct {
// For example, create a pivot table on the Sheet1!$G$2:$M$34 area with the // For example, create a pivot table on the Sheet1!$G$2:$M$34 area with the
// region Sheet1!$A$1:$E$31 as the data source, summarize by sum for sales: // region Sheet1!$A$1:$E$31 as the data source, summarize by sum for sales:
// //
// package main // package main
//
// import (
// "fmt"
// "math/rand"
// //
// "github.com/xuri/excelize/v2" // import (
// ) // "fmt"
// "math/rand"
// //
// func main() { // "github.com/xuri/excelize/v2"
// f := excelize.NewFile() // )
// // Create some data in a sheet
// month := []string{"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}
// year := []int{2017, 2018, 2019}
// types := []string{"Meat", "Dairy", "Beverages", "Produce"}
// region := []string{"East", "West", "North", "South"}
// f.SetSheetRow("Sheet1", "A1", &[]string{"Month", "Year", "Type", "Sales", "Region"})
// for row := 2; row < 32; row++ {
// f.SetCellValue("Sheet1", fmt.Sprintf("A%d", row), month[rand.Intn(12)])
// f.SetCellValue("Sheet1", fmt.Sprintf("B%d", row), year[rand.Intn(3)])
// f.SetCellValue("Sheet1", fmt.Sprintf("C%d", row), types[rand.Intn(4)])
// f.SetCellValue("Sheet1", fmt.Sprintf("D%d", row), rand.Intn(5000))
// f.SetCellValue("Sheet1", fmt.Sprintf("E%d", row), region[rand.Intn(4)])
// }
// if err := f.AddPivotTable(&excelize.PivotTableOption{
// DataRange: "Sheet1!$A$1:$E$31",
// PivotTableRange: "Sheet1!$G$2:$M$34",
// Rows: []excelize.PivotTableField{{Data: "Month", DefaultSubtotal: true}, {Data: "Year"}},
// Filter: []excelize.PivotTableField{{Data: "Region"}},
// Columns: []excelize.PivotTableField{{Data: "Type", DefaultSubtotal: true}},
// Data: []excelize.PivotTableField{{Data: "Sales", Name: "Summarize", Subtotal: "Sum"}},
// RowGrandTotals: true,
// ColGrandTotals: true,
// ShowDrill: true,
// ShowRowHeaders: true,
// ShowColHeaders: true,
// ShowLastColumn: true,
// }); err != nil {
// fmt.Println(err)
// }
// if err := f.SaveAs("Book1.xlsx"); err != nil {
// fmt.Println(err)
// }
// }
// //
// func main() {
// f := excelize.NewFile()
// // Create some data in a sheet
// month := []string{"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}
// year := []int{2017, 2018, 2019}
// types := []string{"Meat", "Dairy", "Beverages", "Produce"}
// region := []string{"East", "West", "North", "South"}
// f.SetSheetRow("Sheet1", "A1", &[]string{"Month", "Year", "Type", "Sales", "Region"})
// for row := 2; row < 32; row++ {
// f.SetCellValue("Sheet1", fmt.Sprintf("A%d", row), month[rand.Intn(12)])
// f.SetCellValue("Sheet1", fmt.Sprintf("B%d", row), year[rand.Intn(3)])
// f.SetCellValue("Sheet1", fmt.Sprintf("C%d", row), types[rand.Intn(4)])
// f.SetCellValue("Sheet1", fmt.Sprintf("D%d", row), rand.Intn(5000))
// f.SetCellValue("Sheet1", fmt.Sprintf("E%d", row), region[rand.Intn(4)])
// }
// if err := f.AddPivotTable(&excelize.PivotTableOption{
// DataRange: "Sheet1!$A$1:$E$31",
// PivotTableRange: "Sheet1!$G$2:$M$34",
// Rows: []excelize.PivotTableField{{Data: "Month", DefaultSubtotal: true}, {Data: "Year"}},
// Filter: []excelize.PivotTableField{{Data: "Region"}},
// Columns: []excelize.PivotTableField{{Data: "Type", DefaultSubtotal: true}},
// Data: []excelize.PivotTableField{{Data: "Sales", Name: "Summarize", Subtotal: "Sum"}},
// RowGrandTotals: true,
// ColGrandTotals: true,
// ShowDrill: true,
// ShowRowHeaders: true,
// ShowColHeaders: true,
// ShowLastColumn: true,
// }); err != nil {
// fmt.Println(err)
// }
// if err := f.SaveAs("Book1.xlsx"); err != nil {
// fmt.Println(err)
// }
// }
func (f *File) AddPivotTable(opt *PivotTableOption) error { func (f *File) AddPivotTable(opt *PivotTableOption) error {
// parameter validation // parameter validation
_, pivotTableSheetPath, err := f.parseFormatPivotTableSet(opt) _, pivotTableSheetPath, err := f.parseFormatPivotTableSet(opt)

@ -37,18 +37,17 @@ import (
// For example, get and traverse the value of all cells by rows on a worksheet // For example, get and traverse the value of all cells by rows on a worksheet
// named 'Sheet1': // named 'Sheet1':
// //
// rows, err := f.GetRows("Sheet1") // rows, err := f.GetRows("Sheet1")
// if err != nil { // if err != nil {
// fmt.Println(err) // fmt.Println(err)
// return // return
// } // }
// for _, row := range rows { // for _, row := range rows {
// for _, colCell := range row { // for _, colCell := range row {
// fmt.Print(colCell, "\t") // fmt.Print(colCell, "\t")
// } // }
// fmt.Println() // fmt.Println()
// } // }
//
func (f *File) GetRows(sheet string, opts ...Options) ([][]string, error) { func (f *File) GetRows(sheet string, opts ...Options) ([][]string, error) {
rows, err := f.Rows(sheet) rows, err := f.Rows(sheet)
if err != nil { if err != nil {
@ -240,25 +239,24 @@ func (rows *Rows) rowXMLHandler(rowIterator *rowXMLIterator, xmlElement *xml.Sta
// Rows returns a rows iterator, used for streaming reading data for a // Rows returns a rows iterator, used for streaming reading data for a
// worksheet with a large data. For example: // worksheet with a large data. For example:
// //
// rows, err := f.Rows("Sheet1") // rows, err := f.Rows("Sheet1")
// if err != nil { // if err != nil {
// fmt.Println(err) // fmt.Println(err)
// return // return
// } // }
// for rows.Next() { // for rows.Next() {
// row, err := rows.Columns() // row, err := rows.Columns()
// if err != nil { // if err != nil {
// fmt.Println(err) // fmt.Println(err)
// } // }
// for _, colCell := range row { // for _, colCell := range row {
// fmt.Print(colCell, "\t") // fmt.Print(colCell, "\t")
// } // }
// fmt.Println() // fmt.Println()
// } // }
// if err = rows.Close(); err != nil { // if err = rows.Close(); err != nil {
// fmt.Println(err) // fmt.Println(err)
// } // }
//
func (f *File) Rows(sheet string) (*Rows, error) { func (f *File) Rows(sheet string) (*Rows, error) {
name, ok := f.getSheetXMLPath(sheet) name, ok := f.getSheetXMLPath(sheet)
if !ok { if !ok {
@ -344,8 +342,7 @@ func (f *File) xmlDecoder(name string) (bool, *xml.Decoder, *os.File, error) {
// SetRowHeight provides a function to set the height of a single row. For // SetRowHeight provides a function to set the height of a single row. For
// example, set the height of the first row in Sheet1: // example, set the height of the first row in Sheet1:
// //
// err := f.SetRowHeight("Sheet1", 1, 50) // err := f.SetRowHeight("Sheet1", 1, 50)
//
func (f *File) SetRowHeight(sheet string, row int, height float64) error { func (f *File) SetRowHeight(sheet string, row int, height float64) error {
if row < 1 { if row < 1 {
return newInvalidRowNumberError(row) return newInvalidRowNumberError(row)
@ -385,8 +382,7 @@ func (f *File) getRowHeight(sheet string, row int) int {
// GetRowHeight provides a function to get row height by given worksheet name // GetRowHeight provides a function to get row height by given worksheet name
// and row number. For example, get the height of the first row in Sheet1: // and row number. For example, get the height of the first row in Sheet1:
// //
// height, err := f.GetRowHeight("Sheet1", 1) // height, err := f.GetRowHeight("Sheet1", 1)
//
func (f *File) GetRowHeight(sheet string, row int) (float64, error) { func (f *File) GetRowHeight(sheet string, row int) (float64, error) {
if row < 1 { if row < 1 {
return defaultRowHeightPixels, newInvalidRowNumberError(row) return defaultRowHeightPixels, newInvalidRowNumberError(row)
@ -517,8 +513,7 @@ func roundPrecision(text string, prec int) string {
// SetRowVisible provides a function to set visible of a single row by given // 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: // worksheet name and Excel row number. For example, hide row 2 in Sheet1:
// //
// err := f.SetRowVisible("Sheet1", 2, false) // err := f.SetRowVisible("Sheet1", 2, false)
//
func (f *File) SetRowVisible(sheet string, row int, visible bool) error { func (f *File) SetRowVisible(sheet string, row int, visible bool) error {
if row < 1 { if row < 1 {
return newInvalidRowNumberError(row) return newInvalidRowNumberError(row)
@ -537,8 +532,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 // worksheet name and Excel row number. For example, get visible state of row
// 2 in Sheet1: // 2 in Sheet1:
// //
// visible, err := f.GetRowVisible("Sheet1", 2) // visible, err := f.GetRowVisible("Sheet1", 2)
//
func (f *File) GetRowVisible(sheet string, row int) (bool, error) { func (f *File) GetRowVisible(sheet string, row int) (bool, error) {
if row < 1 { if row < 1 {
return false, newInvalidRowNumberError(row) return false, newInvalidRowNumberError(row)
@ -558,8 +552,7 @@ func (f *File) GetRowVisible(sheet string, row int) (bool, error) {
// single row by given worksheet name and Excel row number. The value of // single row by given worksheet name and Excel row number. The value of
// parameter 'level' is 1-7. For example, outline row 2 in Sheet1 to level 1: // parameter 'level' is 1-7. For example, outline row 2 in Sheet1 to level 1:
// //
// err := f.SetRowOutlineLevel("Sheet1", 2, 1) // err := f.SetRowOutlineLevel("Sheet1", 2, 1)
//
func (f *File) SetRowOutlineLevel(sheet string, row int, level uint8) error { func (f *File) SetRowOutlineLevel(sheet string, row int, level uint8) error {
if row < 1 { if row < 1 {
return newInvalidRowNumberError(row) return newInvalidRowNumberError(row)
@ -580,8 +573,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 // single row by given worksheet name and Excel row number. For example, get
// outline number of row 2 in Sheet1: // outline number of row 2 in Sheet1:
// //
// level, err := f.GetRowOutlineLevel("Sheet1", 2) // level, err := f.GetRowOutlineLevel("Sheet1", 2)
//
func (f *File) GetRowOutlineLevel(sheet string, row int) (uint8, error) { func (f *File) GetRowOutlineLevel(sheet string, row int) (uint8, error) {
if row < 1 { if row < 1 {
return 0, newInvalidRowNumberError(row) return 0, newInvalidRowNumberError(row)
@ -599,7 +591,7 @@ func (f *File) GetRowOutlineLevel(sheet string, row int) (uint8, error) {
// RemoveRow provides a function to remove single row by given worksheet name // RemoveRow provides a function to remove single row by given worksheet name
// and Excel row number. For example, remove row 3 in Sheet1: // and Excel row number. For example, remove row 3 in Sheet1:
// //
// err := f.RemoveRow("Sheet1", 3) // err := f.RemoveRow("Sheet1", 3)
// //
// Use this method with caution, which will affect changes in references such // 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 // as formulas, charts, and so on. If there is any referenced value of the
@ -633,7 +625,7 @@ func (f *File) RemoveRow(sheet string, row int) error {
// number starting from 1. For example, create a new row before row 3 in // number starting from 1. For example, create a new row before row 3 in
// Sheet1: // Sheet1:
// //
// err := f.InsertRow("Sheet1", 3) // err := f.InsertRow("Sheet1", 3)
// //
// Use this method with caution, which will affect changes in references such // 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 // as formulas, charts, and so on. If there is any referenced value of the
@ -648,7 +640,7 @@ func (f *File) InsertRow(sheet string, row int) error {
// DuplicateRow inserts a copy of specified row (by its Excel row number) below // DuplicateRow inserts a copy of specified row (by its Excel row number) below
// //
// err := f.DuplicateRow("Sheet1", 2) // err := f.DuplicateRow("Sheet1", 2)
// //
// Use this method with caution, which will affect changes in references such // 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 // as formulas, charts, and so on. If there is any referenced value of the
@ -661,7 +653,7 @@ func (f *File) DuplicateRow(sheet string, row int) error {
// DuplicateRowTo inserts a copy of specified row by it Excel number // DuplicateRowTo inserts a copy of specified row by it Excel number
// to specified row position moving down exists rows after target position // to specified row position moving down exists rows after target position
// //
// err := f.DuplicateRowTo("Sheet1", 2, 7) // err := f.DuplicateRowTo("Sheet1", 2, 7)
// //
// Use this method with caution, which will affect changes in references such // 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 // as formulas, charts, and so on. If there is any referenced value of the
@ -758,24 +750,24 @@ func (f *File) duplicateMergeCells(sheet string, ws *xlsxWorksheet, row, row2 in
// checkRow provides a function to check and fill each column element for all // checkRow provides a function to check and fill each column element for all
// rows and make that is continuous in a worksheet of XML. For example: // rows and make that is continuous in a worksheet of XML. For example:
// //
// <row r="15" spans="1:22" x14ac:dyDescent="0.2"> // <row r="15" spans="1:22" x14ac:dyDescent="0.2">
// <c r="A15" s="2" /> // <c r="A15" s="2" />
// <c r="B15" s="2" /> // <c r="B15" s="2" />
// <c r="F15" s="1" /> // <c r="F15" s="1" />
// <c r="G15" s="1" /> // <c r="G15" s="1" />
// </row> // </row>
// //
// in this case, we should to change it to // in this case, we should to change it to
// //
// <row r="15" spans="1:22" x14ac:dyDescent="0.2"> // <row r="15" spans="1:22" x14ac:dyDescent="0.2">
// <c r="A15" s="2" /> // <c r="A15" s="2" />
// <c r="B15" s="2" /> // <c r="B15" s="2" />
// <c r="C15" s="2" /> // <c r="C15" s="2" />
// <c r="D15" s="2" /> // <c r="D15" s="2" />
// <c r="E15" s="2" /> // <c r="E15" s="2" />
// <c r="F15" s="1" /> // <c r="F15" s="1" />
// <c r="G15" s="1" /> // <c r="G15" s="1" />
// </row> // </row>
// //
// Noteice: this method could be very slow for large spreadsheets (more than // Noteice: this method could be very slow for large spreadsheets (more than
// 3000 rows one sheet). // 3000 rows one sheet).
@ -843,12 +835,11 @@ func checkRow(ws *xlsxWorksheet) error {
// //
// For example set style of row 1 on Sheet1: // For example set style of row 1 on Sheet1:
// //
// err = f.SetRowStyle("Sheet1", 1, 1, styleID) // err = f.SetRowStyle("Sheet1", 1, 1, styleID)
// //
// Set style of rows 1 to 10 on Sheet1: // Set style of rows 1 to 10 on Sheet1:
// //
// err = f.SetRowStyle("Sheet1", 1, 10, styleID) // err = f.SetRowStyle("Sheet1", 1, 10, styleID)
//
func (f *File) SetRowStyle(sheet string, start, end, styleID int) error { func (f *File) SetRowStyle(sheet string, start, end, styleID int) error {
if end < start { if end < start {
start, end = end, start start, end = end, start

@ -39,245 +39,244 @@ func parseFormatShapeSet(formatSet string) (*formatShape, error) {
// print settings) and properties set. For example, add text box (rect shape) // print settings) and properties set. For example, add text box (rect shape)
// in Sheet1: // in Sheet1:
// //
// err := f.AddShape("Sheet1", "G6", `{ // err := f.AddShape("Sheet1", "G6", `{
// "type": "rect", // "type": "rect",
// "color": // "color":
// { // {
// "line": "#4286F4", // "line": "#4286F4",
// "fill": "#8eb9ff" // "fill": "#8eb9ff"
// }, // },
// "paragraph": [ // "paragraph": [
// { // {
// "text": "Rectangle Shape", // "text": "Rectangle Shape",
// "font": // "font":
// { // {
// "bold": true, // "bold": true,
// "italic": true, // "italic": true,
// "family": "Times New Roman", // "family": "Times New Roman",
// "size": 36, // "size": 36,
// "color": "#777777", // "color": "#777777",
// "underline": "sng" // "underline": "sng"
// } // }
// }], // }],
// "width": 180, // "width": 180,
// "height": 90, // "height": 90,
// "line": // "line":
// { // {
// "width": 1.2 // "width": 1.2
// } // }
// }`) // }`)
// //
// The following shows the type of shape supported by excelize: // The following shows the type of shape supported by excelize:
// //
// accentBorderCallout1 (Callout 1 with Border and Accent Shape) // accentBorderCallout1 (Callout 1 with Border and Accent Shape)
// accentBorderCallout2 (Callout 2 with Border and Accent Shape) // accentBorderCallout2 (Callout 2 with Border and Accent Shape)
// accentBorderCallout3 (Callout 3 with Border and Accent Shape) // accentBorderCallout3 (Callout 3 with Border and Accent Shape)
// accentCallout1 (Callout 1 Shape) // accentCallout1 (Callout 1 Shape)
// accentCallout2 (Callout 2 Shape) // accentCallout2 (Callout 2 Shape)
// accentCallout3 (Callout 3 Shape) // accentCallout3 (Callout 3 Shape)
// actionButtonBackPrevious (Back or Previous Button Shape) // actionButtonBackPrevious (Back or Previous Button Shape)
// actionButtonBeginning (Beginning Button Shape) // actionButtonBeginning (Beginning Button Shape)
// actionButtonBlank (Blank Button Shape) // actionButtonBlank (Blank Button Shape)
// actionButtonDocument (Document Button Shape) // actionButtonDocument (Document Button Shape)
// actionButtonEnd (End Button Shape) // actionButtonEnd (End Button Shape)
// actionButtonForwardNext (Forward or Next Button Shape) // actionButtonForwardNext (Forward or Next Button Shape)
// actionButtonHelp (Help Button Shape) // actionButtonHelp (Help Button Shape)
// actionButtonHome (Home Button Shape) // actionButtonHome (Home Button Shape)
// actionButtonInformation (Information Button Shape) // actionButtonInformation (Information Button Shape)
// actionButtonMovie (Movie Button Shape) // actionButtonMovie (Movie Button Shape)
// actionButtonReturn (Return Button Shape) // actionButtonReturn (Return Button Shape)
// actionButtonSound (Sound Button Shape) // actionButtonSound (Sound Button Shape)
// arc (Curved Arc Shape) // arc (Curved Arc Shape)
// bentArrow (Bent Arrow Shape) // bentArrow (Bent Arrow Shape)
// bentConnector2 (Bent Connector 2 Shape) // bentConnector2 (Bent Connector 2 Shape)
// bentConnector3 (Bent Connector 3 Shape) // bentConnector3 (Bent Connector 3 Shape)
// bentConnector4 (Bent Connector 4 Shape) // bentConnector4 (Bent Connector 4 Shape)
// bentConnector5 (Bent Connector 5 Shape) // bentConnector5 (Bent Connector 5 Shape)
// bentUpArrow (Bent Up Arrow Shape) // bentUpArrow (Bent Up Arrow Shape)
// bevel (Bevel Shape) // bevel (Bevel Shape)
// blockArc (Block Arc Shape) // blockArc (Block Arc Shape)
// borderCallout1 (Callout 1 with Border Shape) // borderCallout1 (Callout 1 with Border Shape)
// borderCallout2 (Callout 2 with Border Shape) // borderCallout2 (Callout 2 with Border Shape)
// borderCallout3 (Callout 3 with Border Shape) // borderCallout3 (Callout 3 with Border Shape)
// bracePair (Brace Pair Shape) // bracePair (Brace Pair Shape)
// bracketPair (Bracket Pair Shape) // bracketPair (Bracket Pair Shape)
// callout1 (Callout 1 Shape) // callout1 (Callout 1 Shape)
// callout2 (Callout 2 Shape) // callout2 (Callout 2 Shape)
// callout3 (Callout 3 Shape) // callout3 (Callout 3 Shape)
// can (Can Shape) // can (Can Shape)
// chartPlus (Chart Plus Shape) // chartPlus (Chart Plus Shape)
// chartStar (Chart Star Shape) // chartStar (Chart Star Shape)
// chartX (Chart X Shape) // chartX (Chart X Shape)
// chevron (Chevron Shape) // chevron (Chevron Shape)
// chord (Chord Shape) // chord (Chord Shape)
// circularArrow (Circular Arrow Shape) // circularArrow (Circular Arrow Shape)
// cloud (Cloud Shape) // cloud (Cloud Shape)
// cloudCallout (Callout Cloud Shape) // cloudCallout (Callout Cloud Shape)
// corner (Corner Shape) // corner (Corner Shape)
// cornerTabs (Corner Tabs Shape) // cornerTabs (Corner Tabs Shape)
// cube (Cube Shape) // cube (Cube Shape)
// curvedConnector2 (Curved Connector 2 Shape) // curvedConnector2 (Curved Connector 2 Shape)
// curvedConnector3 (Curved Connector 3 Shape) // curvedConnector3 (Curved Connector 3 Shape)
// curvedConnector4 (Curved Connector 4 Shape) // curvedConnector4 (Curved Connector 4 Shape)
// curvedConnector5 (Curved Connector 5 Shape) // curvedConnector5 (Curved Connector 5 Shape)
// curvedDownArrow (Curved Down Arrow Shape) // curvedDownArrow (Curved Down Arrow Shape)
// curvedLeftArrow (Curved Left Arrow Shape) // curvedLeftArrow (Curved Left Arrow Shape)
// curvedRightArrow (Curved Right Arrow Shape) // curvedRightArrow (Curved Right Arrow Shape)
// curvedUpArrow (Curved Up Arrow Shape) // curvedUpArrow (Curved Up Arrow Shape)
// decagon (Decagon Shape) // decagon (Decagon Shape)
// diagStripe (Diagonal Stripe Shape) // diagStripe (Diagonal Stripe Shape)
// diamond (Diamond Shape) // diamond (Diamond Shape)
// dodecagon (Dodecagon Shape) // dodecagon (Dodecagon Shape)
// donut (Donut Shape) // donut (Donut Shape)
// doubleWave (Double Wave Shape) // doubleWave (Double Wave Shape)
// downArrow (Down Arrow Shape) // downArrow (Down Arrow Shape)
// downArrowCallout (Callout Down Arrow Shape) // downArrowCallout (Callout Down Arrow Shape)
// ellipse (Ellipse Shape) // ellipse (Ellipse Shape)
// ellipseRibbon (Ellipse Ribbon Shape) // ellipseRibbon (Ellipse Ribbon Shape)
// ellipseRibbon2 (Ellipse Ribbon 2 Shape) // ellipseRibbon2 (Ellipse Ribbon 2 Shape)
// flowChartAlternateProcess (Alternate Process Flow Shape) // flowChartAlternateProcess (Alternate Process Flow Shape)
// flowChartCollate (Collate Flow Shape) // flowChartCollate (Collate Flow Shape)
// flowChartConnector (Connector Flow Shape) // flowChartConnector (Connector Flow Shape)
// flowChartDecision (Decision Flow Shape) // flowChartDecision (Decision Flow Shape)
// flowChartDelay (Delay Flow Shape) // flowChartDelay (Delay Flow Shape)
// flowChartDisplay (Display Flow Shape) // flowChartDisplay (Display Flow Shape)
// flowChartDocument (Document Flow Shape) // flowChartDocument (Document Flow Shape)
// flowChartExtract (Extract Flow Shape) // flowChartExtract (Extract Flow Shape)
// flowChartInputOutput (Input Output Flow Shape) // flowChartInputOutput (Input Output Flow Shape)
// flowChartInternalStorage (Internal Storage Flow Shape) // flowChartInternalStorage (Internal Storage Flow Shape)
// flowChartMagneticDisk (Magnetic Disk Flow Shape) // flowChartMagneticDisk (Magnetic Disk Flow Shape)
// flowChartMagneticDrum (Magnetic Drum Flow Shape) // flowChartMagneticDrum (Magnetic Drum Flow Shape)
// flowChartMagneticTape (Magnetic Tape Flow Shape) // flowChartMagneticTape (Magnetic Tape Flow Shape)
// flowChartManualInput (Manual Input Flow Shape) // flowChartManualInput (Manual Input Flow Shape)
// flowChartManualOperation (Manual Operation Flow Shape) // flowChartManualOperation (Manual Operation Flow Shape)
// flowChartMerge (Merge Flow Shape) // flowChartMerge (Merge Flow Shape)
// flowChartMultidocument (Multi-Document Flow Shape) // flowChartMultidocument (Multi-Document Flow Shape)
// flowChartOfflineStorage (Offline Storage Flow Shape) // flowChartOfflineStorage (Offline Storage Flow Shape)
// flowChartOffpageConnector (Off-Page Connector Flow Shape) // flowChartOffpageConnector (Off-Page Connector Flow Shape)
// flowChartOnlineStorage (Online Storage Flow Shape) // flowChartOnlineStorage (Online Storage Flow Shape)
// flowChartOr (Or Flow Shape) // flowChartOr (Or Flow Shape)
// flowChartPredefinedProcess (Predefined Process Flow Shape) // flowChartPredefinedProcess (Predefined Process Flow Shape)
// flowChartPreparation (Preparation Flow Shape) // flowChartPreparation (Preparation Flow Shape)
// flowChartProcess (Process Flow Shape) // flowChartProcess (Process Flow Shape)
// flowChartPunchedCard (Punched Card Flow Shape) // flowChartPunchedCard (Punched Card Flow Shape)
// flowChartPunchedTape (Punched Tape Flow Shape) // flowChartPunchedTape (Punched Tape Flow Shape)
// flowChartSort (Sort Flow Shape) // flowChartSort (Sort Flow Shape)
// flowChartSummingJunction (Summing Junction Flow Shape) // flowChartSummingJunction (Summing Junction Flow Shape)
// flowChartTerminator (Terminator Flow Shape) // flowChartTerminator (Terminator Flow Shape)
// foldedCorner (Folded Corner Shape) // foldedCorner (Folded Corner Shape)
// frame (Frame Shape) // frame (Frame Shape)
// funnel (Funnel Shape) // funnel (Funnel Shape)
// gear6 (Gear 6 Shape) // gear6 (Gear 6 Shape)
// gear9 (Gear 9 Shape) // gear9 (Gear 9 Shape)
// halfFrame (Half Frame Shape) // halfFrame (Half Frame Shape)
// heart (Heart Shape) // heart (Heart Shape)
// heptagon (Heptagon Shape) // heptagon (Heptagon Shape)
// hexagon (Hexagon Shape) // hexagon (Hexagon Shape)
// homePlate (Home Plate Shape) // homePlate (Home Plate Shape)
// horizontalScroll (Horizontal Scroll Shape) // horizontalScroll (Horizontal Scroll Shape)
// irregularSeal1 (Irregular Seal 1 Shape) // irregularSeal1 (Irregular Seal 1 Shape)
// irregularSeal2 (Irregular Seal 2 Shape) // irregularSeal2 (Irregular Seal 2 Shape)
// leftArrow (Left Arrow Shape) // leftArrow (Left Arrow Shape)
// leftArrowCallout (Callout Left Arrow Shape) // leftArrowCallout (Callout Left Arrow Shape)
// leftBrace (Left Brace Shape) // leftBrace (Left Brace Shape)
// leftBracket (Left Bracket Shape) // leftBracket (Left Bracket Shape)
// leftCircularArrow (Left Circular Arrow Shape) // leftCircularArrow (Left Circular Arrow Shape)
// leftRightArrow (Left Right Arrow Shape) // leftRightArrow (Left Right Arrow Shape)
// leftRightArrowCallout (Callout Left Right Arrow Shape) // leftRightArrowCallout (Callout Left Right Arrow Shape)
// leftRightCircularArrow (Left Right Circular Arrow Shape) // leftRightCircularArrow (Left Right Circular Arrow Shape)
// leftRightRibbon (Left Right Ribbon Shape) // leftRightRibbon (Left Right Ribbon Shape)
// leftRightUpArrow (Left Right Up Arrow Shape) // leftRightUpArrow (Left Right Up Arrow Shape)
// leftUpArrow (Left Up Arrow Shape) // leftUpArrow (Left Up Arrow Shape)
// lightningBolt (Lightning Bolt Shape) // lightningBolt (Lightning Bolt Shape)
// line (Line Shape) // line (Line Shape)
// lineInv (Line Inverse Shape) // lineInv (Line Inverse Shape)
// mathDivide (Divide Math Shape) // mathDivide (Divide Math Shape)
// mathEqual (Equal Math Shape) // mathEqual (Equal Math Shape)
// mathMinus (Minus Math Shape) // mathMinus (Minus Math Shape)
// mathMultiply (Multiply Math Shape) // mathMultiply (Multiply Math Shape)
// mathNotEqual (Not Equal Math Shape) // mathNotEqual (Not Equal Math Shape)
// mathPlus (Plus Math Shape) // mathPlus (Plus Math Shape)
// moon (Moon Shape) // moon (Moon Shape)
// nonIsoscelesTrapezoid (Non-Isosceles Trapezoid Shape) // nonIsoscelesTrapezoid (Non-Isosceles Trapezoid Shape)
// noSmoking (No Smoking Shape) // noSmoking (No Smoking Shape)
// notchedRightArrow (Notched Right Arrow Shape) // notchedRightArrow (Notched Right Arrow Shape)
// octagon (Octagon Shape) // octagon (Octagon Shape)
// parallelogram (Parallelogram Shape) // parallelogram (Parallelogram Shape)
// pentagon (Pentagon Shape) // pentagon (Pentagon Shape)
// pie (Pie Shape) // pie (Pie Shape)
// pieWedge (Pie Wedge Shape) // pieWedge (Pie Wedge Shape)
// plaque (Plaque Shape) // plaque (Plaque Shape)
// plaqueTabs (Plaque Tabs Shape) // plaqueTabs (Plaque Tabs Shape)
// plus (Plus Shape) // plus (Plus Shape)
// quadArrow (Quad-Arrow Shape) // quadArrow (Quad-Arrow Shape)
// quadArrowCallout (Callout Quad-Arrow Shape) // quadArrowCallout (Callout Quad-Arrow Shape)
// rect (Rectangle Shape) // rect (Rectangle Shape)
// ribbon (Ribbon Shape) // ribbon (Ribbon Shape)
// ribbon2 (Ribbon 2 Shape) // ribbon2 (Ribbon 2 Shape)
// rightArrow (Right Arrow Shape) // rightArrow (Right Arrow Shape)
// rightArrowCallout (Callout Right Arrow Shape) // rightArrowCallout (Callout Right Arrow Shape)
// rightBrace (Right Brace Shape) // rightBrace (Right Brace Shape)
// rightBracket (Right Bracket Shape) // rightBracket (Right Bracket Shape)
// round1Rect (One Round Corner Rectangle Shape) // round1Rect (One Round Corner Rectangle Shape)
// round2DiagRect (Two Diagonal Round Corner Rectangle Shape) // round2DiagRect (Two Diagonal Round Corner Rectangle Shape)
// round2SameRect (Two Same-side Round Corner Rectangle Shape) // round2SameRect (Two Same-side Round Corner Rectangle Shape)
// roundRect (Round Corner Rectangle Shape) // roundRect (Round Corner Rectangle Shape)
// rtTriangle (Right Triangle Shape) // rtTriangle (Right Triangle Shape)
// smileyFace (Smiley Face Shape) // smileyFace (Smiley Face Shape)
// snip1Rect (One Snip Corner Rectangle Shape) // snip1Rect (One Snip Corner Rectangle Shape)
// snip2DiagRect (Two Diagonal Snip Corner Rectangle Shape) // snip2DiagRect (Two Diagonal Snip Corner Rectangle Shape)
// snip2SameRect (Two Same-side Snip Corner Rectangle Shape) // snip2SameRect (Two Same-side Snip Corner Rectangle Shape)
// snipRoundRect (One Snip One Round Corner Rectangle Shape) // snipRoundRect (One Snip One Round Corner Rectangle Shape)
// squareTabs (Square Tabs Shape) // squareTabs (Square Tabs Shape)
// star10 (Ten Pointed Star Shape) // star10 (Ten Pointed Star Shape)
// star12 (Twelve Pointed Star Shape) // star12 (Twelve Pointed Star Shape)
// star16 (Sixteen Pointed Star Shape) // star16 (Sixteen Pointed Star Shape)
// star24 (Twenty Four Pointed Star Shape) // star24 (Twenty Four Pointed Star Shape)
// star32 (Thirty Two Pointed Star Shape) // star32 (Thirty Two Pointed Star Shape)
// star4 (Four Pointed Star Shape) // star4 (Four Pointed Star Shape)
// star5 (Five Pointed Star Shape) // star5 (Five Pointed Star Shape)
// star6 (Six Pointed Star Shape) // star6 (Six Pointed Star Shape)
// star7 (Seven Pointed Star Shape) // star7 (Seven Pointed Star Shape)
// star8 (Eight Pointed Star Shape) // star8 (Eight Pointed Star Shape)
// straightConnector1 (Straight Connector 1 Shape) // straightConnector1 (Straight Connector 1 Shape)
// stripedRightArrow (Striped Right Arrow Shape) // stripedRightArrow (Striped Right Arrow Shape)
// sun (Sun Shape) // sun (Sun Shape)
// swooshArrow (Swoosh Arrow Shape) // swooshArrow (Swoosh Arrow Shape)
// teardrop (Teardrop Shape) // teardrop (Teardrop Shape)
// trapezoid (Trapezoid Shape) // trapezoid (Trapezoid Shape)
// triangle (Triangle Shape) // triangle (Triangle Shape)
// upArrow (Up Arrow Shape) // upArrow (Up Arrow Shape)
// upArrowCallout (Callout Up Arrow Shape) // upArrowCallout (Callout Up Arrow Shape)
// upDownArrow (Up Down Arrow Shape) // upDownArrow (Up Down Arrow Shape)
// upDownArrowCallout (Callout Up Down Arrow Shape) // upDownArrowCallout (Callout Up Down Arrow Shape)
// uturnArrow (U-Turn Arrow Shape) // uturnArrow (U-Turn Arrow Shape)
// verticalScroll (Vertical Scroll Shape) // verticalScroll (Vertical Scroll Shape)
// wave (Wave Shape) // wave (Wave Shape)
// wedgeEllipseCallout (Callout Wedge Ellipse Shape) // wedgeEllipseCallout (Callout Wedge Ellipse Shape)
// wedgeRectCallout (Callout Wedge Rectangle Shape) // wedgeRectCallout (Callout Wedge Rectangle Shape)
// wedgeRoundRectCallout (Callout Wedge Round Rectangle Shape) // wedgeRoundRectCallout (Callout Wedge Round Rectangle Shape)
// //
// The following shows the type of text underline supported by excelize: // The following shows the type of text underline supported by excelize:
// //
// none // none
// words // words
// sng // sng
// dbl // dbl
// heavy // heavy
// dotted // dotted
// dottedHeavy // dottedHeavy
// dash // dash
// dashHeavy // dashHeavy
// dashLong // dashLong
// dashLongHeavy // dashLongHeavy
// dotDash // dotDash
// dotDashHeavy // dotDashHeavy
// dotDotDash // dotDotDash
// dotDotDashHeavy // dotDotDashHeavy
// wavy // wavy
// wavyHeavy // wavyHeavy
// wavyDbl // wavyDbl
//
func (f *File) AddShape(sheet, cell, format string) error { func (f *File) AddShape(sheet, cell, format string) error {
formatSet, err := parseFormatShapeSet(format) formatSet, err := parseFormatShapeSet(format)
if err != nil { if err != nil {

@ -392,19 +392,18 @@ func (f *File) GetSheetIndex(sheet string) int {
// GetSheetMap provides a function to get worksheets, chart sheets, dialog // GetSheetMap provides a function to get worksheets, chart sheets, dialog
// sheets ID and name map of the workbook. For example: // sheets ID and name map of the workbook. For example:
// //
// f, err := excelize.OpenFile("Book1.xlsx") // f, err := excelize.OpenFile("Book1.xlsx")
// if err != nil { // if err != nil {
// return // return
// } // }
// defer func() { // defer func() {
// if err := f.Close(); err != nil { // if err := f.Close(); err != nil {
// fmt.Println(err) // fmt.Println(err)
// } // }
// }() // }()
// for index, name := range f.GetSheetMap() { // for index, name := range f.GetSheetMap() {
// fmt.Println(index, name) // fmt.Println(index, name)
// } // }
//
func (f *File) GetSheetMap() map[int]string { func (f *File) GetSheetMap() map[int]string {
wb := f.workbookReader() wb := f.workbookReader()
sheetMap := map[int]string{} sheetMap := map[int]string{}
@ -588,11 +587,10 @@ func (f *File) deleteSheetFromContentTypes(target string) {
// target worksheet index. Note that currently doesn't support duplicate // target worksheet index. Note that currently doesn't support duplicate
// workbooks that contain tables, charts or pictures. For Example: // workbooks that contain tables, charts or pictures. For Example:
// //
// // Sheet1 already exists... // // Sheet1 already exists...
// index := f.NewSheet("Sheet2") // index := f.NewSheet("Sheet2")
// err := f.CopySheet(1, index) // err := f.CopySheet(1, index)
// return err // return err
//
func (f *File) CopySheet(from, to int) error { func (f *File) CopySheet(from, to int) error {
if from < 0 || to < 0 || from == to || f.GetSheetName(from) == "" || f.GetSheetName(to) == "" { if from < 0 || to < 0 || from == to || f.GetSheetName(from) == "" || f.GetSheetName(to) == "" {
return ErrSheetIdx return ErrSheetIdx
@ -634,14 +632,13 @@ func (f *File) copySheet(from, to int) error {
// worksheet has been activated, this setting will be invalidated. Sheet state // worksheet has been activated, this setting will be invalidated. Sheet state
// values as defined by https://docs.microsoft.com/en-us/dotnet/api/documentformat.openxml.spreadsheet.sheetstatevalues // values as defined by https://docs.microsoft.com/en-us/dotnet/api/documentformat.openxml.spreadsheet.sheetstatevalues
// //
// visible // visible
// hidden // hidden
// veryHidden // veryHidden
// //
// For example, hide Sheet1: // For example, hide Sheet1:
// //
// err := f.SetSheetVisible("Sheet1", false) // err := f.SetSheetVisible("Sheet1", false)
//
func (f *File) SetSheetVisible(sheet string, visible bool) error { func (f *File) SetSheetVisible(sheet string, visible bool) error {
sheet = trimSheetName(sheet) sheet = trimSheetName(sheet)
content := f.workbookReader() content := f.workbookReader()
@ -688,50 +685,50 @@ func parseFormatPanesSet(formatSet string) (*formatPanes, error) {
// activePane defines the pane that is active. The possible values for this // activePane defines the pane that is active. The possible values for this
// attribute are defined in the following table: // attribute are defined in the following table:
// //
// Enumeration Value | Description // Enumeration Value | Description
// --------------------------------+------------------------------------------------------------- // --------------------------------+-------------------------------------------------------------
// bottomLeft (Bottom Left Pane) | Bottom left pane, when both vertical and horizontal // bottomLeft (Bottom Left Pane) | Bottom left pane, when both vertical and horizontal
// | splits are applied. // | splits are applied.
// | // |
// | This value is also used when only a horizontal split has // | This value is also used when only a horizontal split has
// | been applied, dividing the pane into upper and lower // | been applied, dividing the pane into upper and lower
// | regions. In that case, this value specifies the bottom // | regions. In that case, this value specifies the bottom
// | pane. // | pane.
// | // |
// bottomRight (Bottom Right Pane) | Bottom right pane, when both vertical and horizontal // bottomRight (Bottom Right Pane) | Bottom right pane, when both vertical and horizontal
// | splits are applied. // | splits are applied.
// | // |
// topLeft (Top Left Pane) | Top left pane, when both vertical and horizontal splits // topLeft (Top Left Pane) | Top left pane, when both vertical and horizontal splits
// | are applied. // | are applied.
// | // |
// | This value is also used when only a horizontal split has // | This value is also used when only a horizontal split has
// | been applied, dividing the pane into upper and lower // | been applied, dividing the pane into upper and lower
// | regions. In that case, this value specifies the top pane. // | regions. In that case, this value specifies the top pane.
// | // |
// | This value is also used when only a vertical split has // | This value is also used when only a vertical split has
// | been applied, dividing the pane into right and left // | been applied, dividing the pane into right and left
// | regions. In that case, this value specifies the left pane // | regions. In that case, this value specifies the left pane
// | // |
// topRight (Top Right Pane) | Top right pane, when both vertical and horizontal // topRight (Top Right Pane) | Top right pane, when both vertical and horizontal
// | splits are applied. // | splits are applied.
// | // |
// | This value is also used when only a vertical split has // | This value is also used when only a vertical split has
// | been applied, dividing the pane into right and left // | been applied, dividing the pane into right and left
// | regions. In that case, this value specifies the right // | regions. In that case, this value specifies the right
// | pane. // | pane.
// //
// Pane state type is restricted to the values supported currently listed in the following table: // Pane state type is restricted to the values supported currently listed in the following table:
// //
// Enumeration Value | Description // Enumeration Value | Description
// --------------------------------+------------------------------------------------------------- // --------------------------------+-------------------------------------------------------------
// frozen (Frozen) | Panes are frozen, but were not split being frozen. In // frozen (Frozen) | Panes are frozen, but were not split being frozen. In
// | this state, when the panes are unfrozen again, a single // | this state, when the panes are unfrozen again, a single
// | pane results, with no split. // | pane results, with no split.
// | // |
// | In this state, the split bars are not adjustable. // | In this state, the split bars are not adjustable.
// | // |
// split (Split) | Panes are split, but not frozen. In this state, the split // split (Split) | Panes are split, but not frozen. In this state, the split
// | bars are adjustable by the user. // | bars are adjustable by the user.
// //
// x_split (Horizontal Split Position): Horizontal position of the split, in // x_split (Horizontal Split Position): Horizontal position of the split, in
// 1/20th of a point; 0 (zero) if none. If the pane is frozen, this value // 1/20th of a point; 0 (zero) if none. If the pane is frozen, this value
@ -751,22 +748,21 @@ func parseFormatPanesSet(formatSet string) (*formatPanes, error) {
// An example of how to freeze column A in the Sheet1 and set the active cell on // An example of how to freeze column A in the Sheet1 and set the active cell on
// Sheet1!K16: // Sheet1!K16:
// //
// 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"}]}`) // 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 // An example of how to freeze rows 1 to 9 in the Sheet1 and set the active cell
// ranges on Sheet1!A11:XFD11: // ranges on Sheet1!A11:XFD11:
// //
// 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"}]}`) // 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 // An example of how to create split panes in the Sheet1 and set the active cell
// on Sheet1!J60: // on Sheet1!J60:
// //
// 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"}]}`) // 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: // An example of how to unfreeze and remove all panes on Sheet1:
// //
// f.SetPanes("Sheet1", `{"freeze":false,"split":false}`) // f.SetPanes("Sheet1", `{"freeze":false,"split":false}`)
//
func (f *File) SetPanes(sheet, panes string) error { func (f *File) SetPanes(sheet, panes string) error {
fs, _ := parseFormatPanesSet(panes) fs, _ := parseFormatPanesSet(panes)
ws, err := f.workSheetReader(sheet) ws, err := f.workSheetReader(sheet)
@ -806,8 +802,7 @@ func (f *File) SetPanes(sheet, panes string) error {
// GetSheetVisible provides a function to get worksheet visible by given worksheet // GetSheetVisible provides a function to get worksheet visible by given worksheet
// name. For example, get visible state of Sheet1: // name. For example, get visible state of Sheet1:
// //
// f.GetSheetVisible("Sheet1") // f.GetSheetVisible("Sheet1")
//
func (f *File) GetSheetVisible(sheet string) bool { func (f *File) GetSheetVisible(sheet string) bool {
content, name, visible := f.workbookReader(), trimSheetName(sheet), false content, name, visible := f.workbookReader(), trimSheetName(sheet), false
for k, v := range content.Sheets.Sheet { for k, v := range content.Sheets.Sheet {
@ -828,13 +823,12 @@ func (f *File) GetSheetVisible(sheet string) bool {
// //
// An example of search the coordinates of the value of "100" on Sheet1: // An example of search the coordinates of the value of "100" on Sheet1:
// //
// result, err := f.SearchSheet("Sheet1", "100") // result, err := f.SearchSheet("Sheet1", "100")
// //
// An example of search the coordinates where the numerical value in the range // An example of search the coordinates where the numerical value in the range
// of "0-9" of Sheet1 is described: // of "0-9" of Sheet1 is described:
// //
// result, err := f.SearchSheet("Sheet1", "[0-9]", true) // result, err := f.SearchSheet("Sheet1", "[0-9]", true)
//
func (f *File) SearchSheet(sheet, value string, reg ...bool) ([]string, error) { func (f *File) SearchSheet(sheet, value string, reg ...bool) ([]string, error) {
var ( var (
regSearch bool regSearch bool
@ -961,95 +955,95 @@ func attrValToBool(name string, attrs []xml.Attr) (val bool, err error) {
// //
// Headers and footers are specified using the following settings fields: // Headers and footers are specified using the following settings fields:
// //
// Fields | Description // Fields | Description
// ------------------+----------------------------------------------------------- // ------------------+-----------------------------------------------------------
// AlignWithMargins | Align header footer margins with page margins // AlignWithMargins | Align header footer margins with page margins
// DifferentFirst | Different first-page header and footer indicator // DifferentFirst | Different first-page header and footer indicator
// DifferentOddEven | Different odd and even page headers and footers indicator // DifferentOddEven | Different odd and even page headers and footers indicator
// ScaleWithDoc | Scale header and footer with document scaling // ScaleWithDoc | Scale header and footer with document scaling
// OddFooter | Odd Page Footer // OddFooter | Odd Page Footer
// OddHeader | Odd Header // OddHeader | Odd Header
// EvenFooter | Even Page Footer // EvenFooter | Even Page Footer
// EvenHeader | Even Page Header // EvenHeader | Even Page Header
// FirstFooter | First Page Footer // FirstFooter | First Page Footer
// FirstHeader | First Page Header // FirstHeader | First Page Header
// //
// The following formatting codes can be used in 6 string type fields: // The following formatting codes can be used in 6 string type fields:
// OddHeader, OddFooter, EvenHeader, EvenFooter, FirstFooter, FirstHeader // OddHeader, OddFooter, EvenHeader, EvenFooter, FirstFooter, FirstHeader
// //
// Formatting Code | Description // Formatting Code | Description
// ------------------------+------------------------------------------------------------------------- // ------------------------+-------------------------------------------------------------------------
// && | The character "&" // && | The character "&"
// | // |
// &font-size | Size of the text font, where font-size is a decimal font size in points // &font-size | Size of the text font, where font-size is a decimal font size in points
// | // |
// &"font name,font type" | A text font-name string, font name, and a text font-type string, // &"font name,font type" | A text font-name string, font name, and a text font-type string,
// | font type // | font type
// | // |
// &"-,Regular" | Regular text format. Toggles bold and italic modes to off // &"-,Regular" | Regular text format. Toggles bold and italic modes to off
// | // |
// &A | Current worksheet's tab name // &A | Current worksheet's tab name
// | // |
// &B or &"-,Bold" | Bold text format, from off to on, or vice versa. The default mode is off // &B or &"-,Bold" | Bold text format, from off to on, or vice versa. The default mode is off
// | // |
// &D | Current date // &D | Current date
// | // |
// &C | Center section // &C | Center section
// | // |
// &E | Double-underline text format // &E | Double-underline text format
// | // |
// &F | Current workbook's file name // &F | Current workbook's file name
// | // |
// &G | Drawing object as background // &G | Drawing object as background
// | // |
// &H | Shadow text format // &H | Shadow text format
// | // |
// &I or &"-,Italic" | Italic text format // &I or &"-,Italic" | Italic text format
// | // |
// &K | Text font color // &K | Text font color
// | // |
// | An RGB Color is specified as RRGGBB // | An RGB Color is specified as RRGGBB
// | // |
// | A Theme Color is specified as TTSNNN where TT is the theme color Id, // | A Theme Color is specified as TTSNNN where TT is the theme color Id,
// | S is either "+" or "-" of the tint/shade value, and NNN is the // | S is either "+" or "-" of the tint/shade value, and NNN is the
// | tint/shade value // | tint/shade value
// | // |
// &L | Left section // &L | Left section
// | // |
// &N | Total number of pages // &N | Total number of pages
// | // |
// &O | Outline text format // &O | Outline text format
// | // |
// &P[[+|-]n] | Without the optional suffix, the current page number in decimal // &P[[+|-]n] | Without the optional suffix, the current page number in decimal
// | // |
// &R | Right section // &R | Right section
// | // |
// &S | Strikethrough text format // &S | Strikethrough text format
// | // |
// &T | Current time // &T | Current time
// | // |
// &U | Single-underline text format. If double-underline mode is on, the next // &U | Single-underline text format. If double-underline mode is on, the next
// | occurrence in a section specifier toggles double-underline mode to off; // | occurrence in a section specifier toggles double-underline mode to off;
// | otherwise, it toggles single-underline mode, from off to on, or vice // | otherwise, it toggles single-underline mode, from off to on, or vice
// | versa. The default mode is off // | versa. The default mode is off
// | // |
// &X | Superscript text format // &X | Superscript text format
// | // |
// &Y | Subscript text format // &Y | Subscript text format
// | // |
// &Z | Current workbook's file path // &Z | Current workbook's file path
// //
// For example: // For example:
// //
// err := f.SetHeaderFooter("Sheet1", &excelize.FormatHeaderFooter{ // err := f.SetHeaderFooter("Sheet1", &excelize.FormatHeaderFooter{
// DifferentFirst: true, // DifferentFirst: true,
// DifferentOddEven: true, // DifferentOddEven: true,
// OddHeader: "&R&P", // OddHeader: "&R&P",
// OddFooter: "&C&F", // OddFooter: "&C&F",
// EvenHeader: "&L&P", // EvenHeader: "&L&P",
// EvenFooter: "&L&D&R&T", // EvenFooter: "&L&D&R&T",
// FirstHeader: `&CCenter &"-,Bold"Bold&"-,Regular"HeaderU+000A&D`, // FirstHeader: `&CCenter &"-,Bold"Bold&"-,Regular"HeaderU+000A&D`,
// }) // })
// //
// This example shows: // This example shows:
// //
@ -1071,7 +1065,6 @@ func attrValToBool(name string, attrs []xml.Attr) (val bool, err error) {
// that same page // that same page
// //
// - No footer on the first page // - No footer on the first page
//
func (f *File) SetHeaderFooter(sheet string, settings *FormatHeaderFooter) error { func (f *File) SetHeaderFooter(sheet string, settings *FormatHeaderFooter) error {
ws, err := f.workSheetReader(sheet) ws, err := f.workSheetReader(sheet)
if err != nil { if err != nil {
@ -1112,12 +1105,11 @@ func (f *File) SetHeaderFooter(sheet string, settings *FormatHeaderFooter) error
// specified, will be using the XOR algorithm as default. For example, protect // specified, will be using the XOR algorithm as default. For example, protect
// Sheet1 with protection settings: // Sheet1 with protection settings:
// //
// err := f.ProtectSheet("Sheet1", &excelize.FormatSheetProtection{ // err := f.ProtectSheet("Sheet1", &excelize.FormatSheetProtection{
// AlgorithmName: "SHA-512", // AlgorithmName: "SHA-512",
// Password: "password", // Password: "password",
// EditScenarios: false, // EditScenarios: false,
// }) // })
//
func (f *File) ProtectSheet(sheet string, settings *FormatSheetProtection) error { func (f *File) ProtectSheet(sheet string, settings *FormatSheetProtection) error {
ws, err := f.workSheetReader(sheet) ws, err := f.workSheetReader(sheet)
if err != nil { if err != nil {
@ -1377,135 +1369,134 @@ func (p *PageLayoutScale) getPageLayout(ps *xlsxPageSetUp) {
// //
// Available options: // Available options:
// //
// BlackAndWhite(bool) // BlackAndWhite(bool)
// FirstPageNumber(uint) // FirstPageNumber(uint)
// PageLayoutOrientation(string) // PageLayoutOrientation(string)
// PageLayoutPaperSize(int) // PageLayoutPaperSize(int)
// FitToHeight(int) // FitToHeight(int)
// FitToWidth(int) // FitToWidth(int)
// PageLayoutScale(uint) // PageLayoutScale(uint)
// //
// The following shows the paper size sorted by excelize index number: // The following shows the paper size sorted by excelize index number:
// //
// Index | Paper Size // Index | Paper Size
// -------+----------------------------------------------- // -------+-----------------------------------------------
// 1 | Letter paper (8.5 in. by 11 in.) // 1 | Letter paper (8.5 in. by 11 in.)
// 2 | Letter small paper (8.5 in. by 11 in.) // 2 | Letter small paper (8.5 in. by 11 in.)
// 3 | Tabloid paper (11 in. by 17 in.) // 3 | Tabloid paper (11 in. by 17 in.)
// 4 | Ledger paper (17 in. by 11 in.) // 4 | Ledger paper (17 in. by 11 in.)
// 5 | Legal paper (8.5 in. by 14 in.) // 5 | Legal paper (8.5 in. by 14 in.)
// 6 | Statement paper (5.5 in. by 8.5 in.) // 6 | Statement paper (5.5 in. by 8.5 in.)
// 7 | Executive paper (7.25 in. by 10.5 in.) // 7 | Executive paper (7.25 in. by 10.5 in.)
// 8 | A3 paper (297 mm by 420 mm) // 8 | A3 paper (297 mm by 420 mm)
// 9 | A4 paper (210 mm by 297 mm) // 9 | A4 paper (210 mm by 297 mm)
// 10 | A4 small paper (210 mm by 297 mm) // 10 | A4 small paper (210 mm by 297 mm)
// 11 | A5 paper (148 mm by 210 mm) // 11 | A5 paper (148 mm by 210 mm)
// 12 | B4 paper (250 mm by 353 mm) // 12 | B4 paper (250 mm by 353 mm)
// 13 | B5 paper (176 mm by 250 mm) // 13 | B5 paper (176 mm by 250 mm)
// 14 | Folio paper (8.5 in. by 13 in.) // 14 | Folio paper (8.5 in. by 13 in.)
// 15 | Quarto paper (215 mm by 275 mm) // 15 | Quarto paper (215 mm by 275 mm)
// 16 | Standard paper (10 in. by 14 in.) // 16 | Standard paper (10 in. by 14 in.)
// 17 | Standard paper (11 in. by 17 in.) // 17 | Standard paper (11 in. by 17 in.)
// 18 | Note paper (8.5 in. by 11 in.) // 18 | Note paper (8.5 in. by 11 in.)
// 19 | #9 envelope (3.875 in. by 8.875 in.) // 19 | #9 envelope (3.875 in. by 8.875 in.)
// 20 | #10 envelope (4.125 in. by 9.5 in.) // 20 | #10 envelope (4.125 in. by 9.5 in.)
// 21 | #11 envelope (4.5 in. by 10.375 in.) // 21 | #11 envelope (4.5 in. by 10.375 in.)
// 22 | #12 envelope (4.75 in. by 11 in.) // 22 | #12 envelope (4.75 in. by 11 in.)
// 23 | #14 envelope (5 in. by 11.5 in.) // 23 | #14 envelope (5 in. by 11.5 in.)
// 24 | C paper (17 in. by 22 in.) // 24 | C paper (17 in. by 22 in.)
// 25 | D paper (22 in. by 34 in.) // 25 | D paper (22 in. by 34 in.)
// 26 | E paper (34 in. by 44 in.) // 26 | E paper (34 in. by 44 in.)
// 27 | DL envelope (110 mm by 220 mm) // 27 | DL envelope (110 mm by 220 mm)
// 28 | C5 envelope (162 mm by 229 mm) // 28 | C5 envelope (162 mm by 229 mm)
// 29 | C3 envelope (324 mm by 458 mm) // 29 | C3 envelope (324 mm by 458 mm)
// 30 | C4 envelope (229 mm by 324 mm) // 30 | C4 envelope (229 mm by 324 mm)
// 31 | C6 envelope (114 mm by 162 mm) // 31 | C6 envelope (114 mm by 162 mm)
// 32 | C65 envelope (114 mm by 229 mm) // 32 | C65 envelope (114 mm by 229 mm)
// 33 | B4 envelope (250 mm by 353 mm) // 33 | B4 envelope (250 mm by 353 mm)
// 34 | B5 envelope (176 mm by 250 mm) // 34 | B5 envelope (176 mm by 250 mm)
// 35 | B6 envelope (176 mm by 125 mm) // 35 | B6 envelope (176 mm by 125 mm)
// 36 | Italy envelope (110 mm by 230 mm) // 36 | Italy envelope (110 mm by 230 mm)
// 37 | Monarch envelope (3.875 in. by 7.5 in.). // 37 | Monarch envelope (3.875 in. by 7.5 in.).
// 38 | 6 3/4 envelope (3.625 in. by 6.5 in.) // 38 | 6 3/4 envelope (3.625 in. by 6.5 in.)
// 39 | US standard fanfold (14.875 in. by 11 in.) // 39 | US standard fanfold (14.875 in. by 11 in.)
// 40 | German standard fanfold (8.5 in. by 12 in.) // 40 | German standard fanfold (8.5 in. by 12 in.)
// 41 | German legal fanfold (8.5 in. by 13 in.) // 41 | German legal fanfold (8.5 in. by 13 in.)
// 42 | ISO B4 (250 mm by 353 mm) // 42 | ISO B4 (250 mm by 353 mm)
// 43 | Japanese postcard (100 mm by 148 mm) // 43 | Japanese postcard (100 mm by 148 mm)
// 44 | Standard paper (9 in. by 11 in.) // 44 | Standard paper (9 in. by 11 in.)
// 45 | Standard paper (10 in. by 11 in.) // 45 | Standard paper (10 in. by 11 in.)
// 46 | Standard paper (15 in. by 11 in.) // 46 | Standard paper (15 in. by 11 in.)
// 47 | Invite envelope (220 mm by 220 mm) // 47 | Invite envelope (220 mm by 220 mm)
// 50 | Letter extra paper (9.275 in. by 12 in.) // 50 | Letter extra paper (9.275 in. by 12 in.)
// 51 | Legal extra paper (9.275 in. by 15 in.) // 51 | Legal extra paper (9.275 in. by 15 in.)
// 52 | Tabloid extra paper (11.69 in. by 18 in.) // 52 | Tabloid extra paper (11.69 in. by 18 in.)
// 53 | A4 extra paper (236 mm by 322 mm) // 53 | A4 extra paper (236 mm by 322 mm)
// 54 | Letter transverse paper (8.275 in. by 11 in.) // 54 | Letter transverse paper (8.275 in. by 11 in.)
// 55 | A4 transverse paper (210 mm by 297 mm) // 55 | A4 transverse paper (210 mm by 297 mm)
// 56 | Letter extra transverse paper (9.275 in. by 12 in.) // 56 | Letter extra transverse paper (9.275 in. by 12 in.)
// 57 | SuperA/SuperA/A4 paper (227 mm by 356 mm) // 57 | SuperA/SuperA/A4 paper (227 mm by 356 mm)
// 58 | SuperB/SuperB/A3 paper (305 mm by 487 mm) // 58 | SuperB/SuperB/A3 paper (305 mm by 487 mm)
// 59 | Letter plus paper (8.5 in. by 12.69 in.) // 59 | Letter plus paper (8.5 in. by 12.69 in.)
// 60 | A4 plus paper (210 mm by 330 mm) // 60 | A4 plus paper (210 mm by 330 mm)
// 61 | A5 transverse paper (148 mm by 210 mm) // 61 | A5 transverse paper (148 mm by 210 mm)
// 62 | JIS B5 transverse paper (182 mm by 257 mm) // 62 | JIS B5 transverse paper (182 mm by 257 mm)
// 63 | A3 extra paper (322 mm by 445 mm) // 63 | A3 extra paper (322 mm by 445 mm)
// 64 | A5 extra paper (174 mm by 235 mm) // 64 | A5 extra paper (174 mm by 235 mm)
// 65 | ISO B5 extra paper (201 mm by 276 mm) // 65 | ISO B5 extra paper (201 mm by 276 mm)
// 66 | A2 paper (420 mm by 594 mm) // 66 | A2 paper (420 mm by 594 mm)
// 67 | A3 transverse paper (297 mm by 420 mm) // 67 | A3 transverse paper (297 mm by 420 mm)
// 68 | A3 extra transverse paper (322 mm by 445 mm) // 68 | A3 extra transverse paper (322 mm by 445 mm)
// 69 | Japanese Double Postcard (200 mm x 148 mm) // 69 | Japanese Double Postcard (200 mm x 148 mm)
// 70 | A6 (105 mm x 148 mm) // 70 | A6 (105 mm x 148 mm)
// 71 | Japanese Envelope Kaku #2 // 71 | Japanese Envelope Kaku #2
// 72 | Japanese Envelope Kaku #3 // 72 | Japanese Envelope Kaku #3
// 73 | Japanese Envelope Chou #3 // 73 | Japanese Envelope Chou #3
// 74 | Japanese Envelope Chou #4 // 74 | Japanese Envelope Chou #4
// 75 | Letter Rotated (11in x 8 1/2 11 in) // 75 | Letter Rotated (11in x 8 1/2 11 in)
// 76 | A3 Rotated (420 mm x 297 mm) // 76 | A3 Rotated (420 mm x 297 mm)
// 77 | A4 Rotated (297 mm x 210 mm) // 77 | A4 Rotated (297 mm x 210 mm)
// 78 | A5 Rotated (210 mm x 148 mm) // 78 | A5 Rotated (210 mm x 148 mm)
// 79 | B4 (JIS) Rotated (364 mm x 257 mm) // 79 | B4 (JIS) Rotated (364 mm x 257 mm)
// 80 | B5 (JIS) Rotated (257 mm x 182 mm) // 80 | B5 (JIS) Rotated (257 mm x 182 mm)
// 81 | Japanese Postcard Rotated (148 mm x 100 mm) // 81 | Japanese Postcard Rotated (148 mm x 100 mm)
// 82 | Double Japanese Postcard Rotated (148 mm x 200 mm) // 82 | Double Japanese Postcard Rotated (148 mm x 200 mm)
// 83 | A6 Rotated (148 mm x 105 mm) // 83 | A6 Rotated (148 mm x 105 mm)
// 84 | Japanese Envelope Kaku #2 Rotated // 84 | Japanese Envelope Kaku #2 Rotated
// 85 | Japanese Envelope Kaku #3 Rotated // 85 | Japanese Envelope Kaku #3 Rotated
// 86 | Japanese Envelope Chou #3 Rotated // 86 | Japanese Envelope Chou #3 Rotated
// 87 | Japanese Envelope Chou #4 Rotated // 87 | Japanese Envelope Chou #4 Rotated
// 88 | B6 (JIS) (128 mm x 182 mm) // 88 | B6 (JIS) (128 mm x 182 mm)
// 89 | B6 (JIS) Rotated (182 mm x 128 mm) // 89 | B6 (JIS) Rotated (182 mm x 128 mm)
// 90 | (12 in x 11 in) // 90 | (12 in x 11 in)
// 91 | Japanese Envelope You #4 // 91 | Japanese Envelope You #4
// 92 | Japanese Envelope You #4 Rotated // 92 | Japanese Envelope You #4 Rotated
// 93 | PRC 16K (146 mm x 215 mm) // 93 | PRC 16K (146 mm x 215 mm)
// 94 | PRC 32K (97 mm x 151 mm) // 94 | PRC 32K (97 mm x 151 mm)
// 95 | PRC 32K(Big) (97 mm x 151 mm) // 95 | PRC 32K(Big) (97 mm x 151 mm)
// 96 | PRC Envelope #1 (102 mm x 165 mm) // 96 | PRC Envelope #1 (102 mm x 165 mm)
// 97 | PRC Envelope #2 (102 mm x 176 mm) // 97 | PRC Envelope #2 (102 mm x 176 mm)
// 98 | PRC Envelope #3 (125 mm x 176 mm) // 98 | PRC Envelope #3 (125 mm x 176 mm)
// 99 | PRC Envelope #4 (110 mm x 208 mm) // 99 | PRC Envelope #4 (110 mm x 208 mm)
// 100 | PRC Envelope #5 (110 mm x 220 mm) // 100 | PRC Envelope #5 (110 mm x 220 mm)
// 101 | PRC Envelope #6 (120 mm x 230 mm) // 101 | PRC Envelope #6 (120 mm x 230 mm)
// 102 | PRC Envelope #7 (160 mm x 230 mm) // 102 | PRC Envelope #7 (160 mm x 230 mm)
// 103 | PRC Envelope #8 (120 mm x 309 mm) // 103 | PRC Envelope #8 (120 mm x 309 mm)
// 104 | PRC Envelope #9 (229 mm x 324 mm) // 104 | PRC Envelope #9 (229 mm x 324 mm)
// 105 | PRC Envelope #10 (324 mm x 458 mm) // 105 | PRC Envelope #10 (324 mm x 458 mm)
// 106 | PRC 16K Rotated // 106 | PRC 16K Rotated
// 107 | PRC 32K Rotated // 107 | PRC 32K Rotated
// 108 | PRC 32K(Big) Rotated // 108 | PRC 32K(Big) Rotated
// 109 | PRC Envelope #1 Rotated (165 mm x 102 mm) // 109 | PRC Envelope #1 Rotated (165 mm x 102 mm)
// 110 | PRC Envelope #2 Rotated (176 mm x 102 mm) // 110 | PRC Envelope #2 Rotated (176 mm x 102 mm)
// 111 | PRC Envelope #3 Rotated (176 mm x 125 mm) // 111 | PRC Envelope #3 Rotated (176 mm x 125 mm)
// 112 | PRC Envelope #4 Rotated (208 mm x 110 mm) // 112 | PRC Envelope #4 Rotated (208 mm x 110 mm)
// 113 | PRC Envelope #5 Rotated (220 mm x 110 mm) // 113 | PRC Envelope #5 Rotated (220 mm x 110 mm)
// 114 | PRC Envelope #6 Rotated (230 mm x 120 mm) // 114 | PRC Envelope #6 Rotated (230 mm x 120 mm)
// 115 | PRC Envelope #7 Rotated (230 mm x 160 mm) // 115 | PRC Envelope #7 Rotated (230 mm x 160 mm)
// 116 | PRC Envelope #8 Rotated (309 mm x 120 mm) // 116 | PRC Envelope #8 Rotated (309 mm x 120 mm)
// 117 | PRC Envelope #9 Rotated (324 mm x 229 mm) // 117 | PRC Envelope #9 Rotated (324 mm x 229 mm)
// 118 | PRC Envelope #10 Rotated (458 mm x 324 mm) // 118 | PRC Envelope #10 Rotated (458 mm x 324 mm)
//
func (f *File) SetPageLayout(sheet string, opts ...PageLayoutOption) error { func (f *File) SetPageLayout(sheet string, opts ...PageLayoutOption) error {
s, err := f.workSheetReader(sheet) s, err := f.workSheetReader(sheet)
if err != nil { if err != nil {
@ -1526,10 +1517,11 @@ func (f *File) SetPageLayout(sheet string, opts ...PageLayoutOption) error {
// GetPageLayout provides a function to gets worksheet page layout. // GetPageLayout provides a function to gets worksheet page layout.
// //
// Available options: // Available options:
// PageLayoutOrientation(string) //
// PageLayoutPaperSize(int) // PageLayoutOrientation(string)
// FitToHeight(int) // PageLayoutPaperSize(int)
// FitToWidth(int) // FitToHeight(int)
// FitToWidth(int)
func (f *File) GetPageLayout(sheet string, opts ...PageLayoutOptionPtr) error { func (f *File) GetPageLayout(sheet string, opts ...PageLayoutOptionPtr) error {
s, err := f.workSheetReader(sheet) s, err := f.workSheetReader(sheet)
if err != nil { if err != nil {
@ -1547,13 +1539,12 @@ func (f *File) GetPageLayout(sheet string, opts ...PageLayoutOptionPtr) error {
// or worksheet. If not specified scope, the default scope is workbook. // or worksheet. If not specified scope, the default scope is workbook.
// For example: // For example:
// //
// f.SetDefinedName(&excelize.DefinedName{ // f.SetDefinedName(&excelize.DefinedName{
// Name: "Amount", // Name: "Amount",
// RefersTo: "Sheet1!$A$2:$D$5", // RefersTo: "Sheet1!$A$2:$D$5",
// Comment: "defined name comment", // Comment: "defined name comment",
// Scope: "Sheet2", // Scope: "Sheet2",
// }) // })
//
func (f *File) SetDefinedName(definedName *DefinedName) error { func (f *File) SetDefinedName(definedName *DefinedName) error {
wb := f.workbookReader() wb := f.workbookReader()
d := xlsxDefinedName{ d := xlsxDefinedName{
@ -1589,11 +1580,10 @@ func (f *File) SetDefinedName(definedName *DefinedName) error {
// workbook or worksheet. If not specified scope, the default scope is // workbook or worksheet. If not specified scope, the default scope is
// workbook. For example: // workbook. For example:
// //
// f.DeleteDefinedName(&excelize.DefinedName{ // f.DeleteDefinedName(&excelize.DefinedName{
// Name: "Amount", // Name: "Amount",
// Scope: "Sheet2", // Scope: "Sheet2",
// }) // })
//
func (f *File) DeleteDefinedName(definedName *DefinedName) error { func (f *File) DeleteDefinedName(definedName *DefinedName) error {
wb := f.workbookReader() wb := f.workbookReader()
if wb.DefinedNames != nil { if wb.DefinedNames != nil {

@ -238,16 +238,17 @@ func (o *AutoPageBreaks) getSheetPrOption(pr *xlsxSheetPr) {
// SetSheetPrOptions provides a function to sets worksheet properties. // SetSheetPrOptions provides a function to sets worksheet properties.
// //
// Available options: // Available options:
// CodeName(string) //
// EnableFormatConditionsCalculation(bool) // CodeName(string)
// Published(bool) // EnableFormatConditionsCalculation(bool)
// FitToPage(bool) // Published(bool)
// TabColorIndexed(int) // FitToPage(bool)
// TabColorRGB(string) // TabColorIndexed(int)
// TabColorTheme(int) // TabColorRGB(string)
// TabColorTint(float64) // TabColorTheme(int)
// AutoPageBreaks(bool) // TabColorTint(float64)
// OutlineSummaryBelow(bool) // AutoPageBreaks(bool)
// OutlineSummaryBelow(bool)
func (f *File) SetSheetPrOptions(sheet string, opts ...SheetPrOption) error { func (f *File) SetSheetPrOptions(sheet string, opts ...SheetPrOption) error {
ws, err := f.workSheetReader(sheet) ws, err := f.workSheetReader(sheet)
if err != nil { if err != nil {
@ -268,16 +269,17 @@ func (f *File) SetSheetPrOptions(sheet string, opts ...SheetPrOption) error {
// GetSheetPrOptions provides a function to gets worksheet properties. // GetSheetPrOptions provides a function to gets worksheet properties.
// //
// Available options: // Available options:
// CodeName(string) //
// EnableFormatConditionsCalculation(bool) // CodeName(string)
// Published(bool) // EnableFormatConditionsCalculation(bool)
// FitToPage(bool) // Published(bool)
// TabColorIndexed(int) // FitToPage(bool)
// TabColorRGB(string) // TabColorIndexed(int)
// TabColorTheme(int) // TabColorRGB(string)
// TabColorTint(float64) // TabColorTheme(int)
// AutoPageBreaks(bool) // TabColorTint(float64)
// OutlineSummaryBelow(bool) // AutoPageBreaks(bool)
// OutlineSummaryBelow(bool)
func (f *File) GetSheetPrOptions(sheet string, opts ...SheetPrOptionPtr) error { func (f *File) GetSheetPrOptions(sheet string, opts ...SheetPrOptionPtr) error {
ws, err := f.workSheetReader(sheet) ws, err := f.workSheetReader(sheet)
if err != nil { if err != nil {
@ -412,12 +414,13 @@ type PageMarginsOptionsPtr interface {
// SetPageMargins provides a function to set worksheet page margins. // SetPageMargins provides a function to set worksheet page margins.
// //
// Available options: // Available options:
// PageMarginBottom(float64) //
// PageMarginFooter(float64) // PageMarginBottom(float64)
// PageMarginHeader(float64) // PageMarginFooter(float64)
// PageMarginLeft(float64) // PageMarginHeader(float64)
// PageMarginRight(float64) // PageMarginLeft(float64)
// PageMarginTop(float64) // PageMarginRight(float64)
// PageMarginTop(float64)
func (f *File) SetPageMargins(sheet string, opts ...PageMarginsOptions) error { func (f *File) SetPageMargins(sheet string, opts ...PageMarginsOptions) error {
s, err := f.workSheetReader(sheet) s, err := f.workSheetReader(sheet)
if err != nil { if err != nil {
@ -438,12 +441,13 @@ func (f *File) SetPageMargins(sheet string, opts ...PageMarginsOptions) error {
// GetPageMargins provides a function to get worksheet page margins. // GetPageMargins provides a function to get worksheet page margins.
// //
// Available options: // Available options:
// PageMarginBottom(float64) //
// PageMarginFooter(float64) // PageMarginBottom(float64)
// PageMarginHeader(float64) // PageMarginFooter(float64)
// PageMarginLeft(float64) // PageMarginHeader(float64)
// PageMarginRight(float64) // PageMarginLeft(float64)
// PageMarginTop(float64) // PageMarginRight(float64)
// PageMarginTop(float64)
func (f *File) GetPageMargins(sheet string, opts ...PageMarginsOptionsPtr) error { func (f *File) GetPageMargins(sheet string, opts ...PageMarginsOptionsPtr) error {
s, err := f.workSheetReader(sheet) s, err := f.workSheetReader(sheet)
if err != nil { if err != nil {
@ -605,13 +609,14 @@ func (p *ThickBottom) getSheetFormatPr(fp *xlsxSheetFormatPr) {
// SetSheetFormatPr provides a function to set worksheet formatting properties. // SetSheetFormatPr provides a function to set worksheet formatting properties.
// //
// Available options: // Available options:
// BaseColWidth(uint8) //
// DefaultColWidth(float64) // BaseColWidth(uint8)
// DefaultRowHeight(float64) // DefaultColWidth(float64)
// CustomHeight(bool) // DefaultRowHeight(float64)
// ZeroHeight(bool) // CustomHeight(bool)
// ThickTop(bool) // ZeroHeight(bool)
// ThickBottom(bool) // ThickTop(bool)
// ThickBottom(bool)
func (f *File) SetSheetFormatPr(sheet string, opts ...SheetFormatPrOptions) error { func (f *File) SetSheetFormatPr(sheet string, opts ...SheetFormatPrOptions) error {
s, err := f.workSheetReader(sheet) s, err := f.workSheetReader(sheet)
if err != nil { if err != nil {
@ -631,13 +636,14 @@ func (f *File) SetSheetFormatPr(sheet string, opts ...SheetFormatPrOptions) erro
// GetSheetFormatPr provides a function to get worksheet formatting properties. // GetSheetFormatPr provides a function to get worksheet formatting properties.
// //
// Available options: // Available options:
// BaseColWidth(uint8) //
// DefaultColWidth(float64) // BaseColWidth(uint8)
// DefaultRowHeight(float64) // DefaultColWidth(float64)
// CustomHeight(bool) // DefaultRowHeight(float64)
// ZeroHeight(bool) // CustomHeight(bool)
// ThickTop(bool) // ZeroHeight(bool)
// ThickBottom(bool) // ThickTop(bool)
// ThickBottom(bool)
func (f *File) GetSheetFormatPr(sheet string, opts ...SheetFormatPrOptionsPtr) error { func (f *File) GetSheetFormatPr(sheet string, opts ...SheetFormatPrOptionsPtr) error {
s, err := f.workSheetReader(sheet) s, err := f.workSheetReader(sheet)
if err != nil { if err != nil {

@ -185,21 +185,20 @@ func (f *File) getSheetView(sheet string, viewIndex int) (*xlsxSheetView, error)
// //
// Available options: // Available options:
// //
// DefaultGridColor(bool) // DefaultGridColor(bool)
// ShowFormulas(bool) // ShowFormulas(bool)
// ShowGridLines(bool) // ShowGridLines(bool)
// ShowRowColHeaders(bool) // ShowRowColHeaders(bool)
// ShowZeros(bool) // ShowZeros(bool)
// RightToLeft(bool) // RightToLeft(bool)
// ShowRuler(bool) // ShowRuler(bool)
// View(string) // View(string)
// TopLeftCell(string) // TopLeftCell(string)
// ZoomScale(float64) // ZoomScale(float64)
// //
// Example: // Example:
// //
// err = f.SetSheetViewOptions("Sheet1", -1, ShowGridLines(false)) // err = f.SetSheetViewOptions("Sheet1", -1, ShowGridLines(false))
//
func (f *File) SetSheetViewOptions(sheet string, viewIndex int, opts ...SheetViewOption) error { func (f *File) SetSheetViewOptions(sheet string, viewIndex int, opts ...SheetViewOption) error {
view, err := f.getSheetView(sheet, viewIndex) view, err := f.getSheetView(sheet, viewIndex)
if err != nil { if err != nil {
@ -217,22 +216,21 @@ func (f *File) SetSheetViewOptions(sheet string, viewIndex int, opts ...SheetVie
// //
// Available options: // Available options:
// //
// DefaultGridColor(bool) // DefaultGridColor(bool)
// ShowFormulas(bool) // ShowFormulas(bool)
// ShowGridLines(bool) // ShowGridLines(bool)
// ShowRowColHeaders(bool) // ShowRowColHeaders(bool)
// ShowZeros(bool) // ShowZeros(bool)
// RightToLeft(bool) // RightToLeft(bool)
// ShowRuler(bool) // ShowRuler(bool)
// View(string) // View(string)
// TopLeftCell(string) // TopLeftCell(string)
// ZoomScale(float64) // ZoomScale(float64)
// //
// Example: // Example:
// //
// var showGridLines excelize.ShowGridLines // var showGridLines excelize.ShowGridLines
// err = f.GetSheetViewOptions("Sheet1", -1, &showGridLines) // err = f.GetSheetViewOptions("Sheet1", -1, &showGridLines)
//
func (f *File) GetSheetViewOptions(sheet string, viewIndex int, opts ...SheetViewOptionPtr) error { func (f *File) GetSheetViewOptions(sheet string, viewIndex int, opts ...SheetViewOptionPtr) error {
view, err := f.getSheetView(sheet, viewIndex) view, err := f.getSheetView(sheet, viewIndex)
if err != nil { if err != nil {

@ -365,29 +365,28 @@ func (f *File) addSparklineGroupByStyle(ID int) *xlsxX14SparklineGroup {
// Excel 2007, but they won't be displayed. For example, add a grouped // Excel 2007, but they won't be displayed. For example, add a grouped
// sparkline. Changes are applied to all three: // sparkline. Changes are applied to all three:
// //
// err := f.AddSparkline("Sheet1", &excelize.SparklineOption{ // err := f.AddSparkline("Sheet1", &excelize.SparklineOption{
// Location: []string{"A1", "A2", "A3"}, // Location: []string{"A1", "A2", "A3"},
// Range: []string{"Sheet2!A1:J1", "Sheet2!A2:J2", "Sheet2!A3:J3"}, // Range: []string{"Sheet2!A1:J1", "Sheet2!A2:J2", "Sheet2!A3:J3"},
// Markers: true, // Markers: true,
// }) // })
// //
// The following shows the formatting options of sparkline supported by excelize: // The following shows the formatting options of sparkline supported by excelize:
// //
// Parameter | Description // Parameter | Description
// -----------+-------------------------------------------- // -----------+--------------------------------------------
// Location | Required, must have the same number with 'Range' parameter // Location | Required, must have the same number with 'Range' parameter
// Range | Required, must have the same number with 'Location' parameter // Range | Required, must have the same number with 'Location' parameter
// Type | Enumeration value: line, column, win_loss // Type | Enumeration value: line, column, win_loss
// Style | Value range: 0 - 35 // Style | Value range: 0 - 35
// Hight | Toggle sparkline high points // Hight | Toggle sparkline high points
// Low | Toggle sparkline low points // Low | Toggle sparkline low points
// First | Toggle sparkline first points // First | Toggle sparkline first points
// Last | Toggle sparkline last points // Last | Toggle sparkline last points
// Negative | Toggle sparkline negative points // Negative | Toggle sparkline negative points
// Markers | Toggle sparkline markers // Markers | Toggle sparkline markers
// ColorAxis | An RGB Color is specified as RRGGBB // ColorAxis | An RGB Color is specified as RRGGBB
// Axis | Show sparkline axis // Axis | Show sparkline axis
//
func (f *File) AddSparkline(sheet string, opt *SparklineOption) (err error) { func (f *File) AddSparkline(sheet string, opt *SparklineOption) (err error) {
var ( var (
ws *xlsxWorksheet ws *xlsxWorksheet

@ -47,49 +47,48 @@ type StreamWriter struct {
// example, set data for worksheet of size 102400 rows x 50 columns with // example, set data for worksheet of size 102400 rows x 50 columns with
// numbers and style: // numbers and style:
// //
// file := excelize.NewFile() // file := excelize.NewFile()
// streamWriter, err := file.NewStreamWriter("Sheet1") // streamWriter, err := file.NewStreamWriter("Sheet1")
// if err != nil { // if err != nil {
// fmt.Println(err) // fmt.Println(err)
// } // }
// styleID, err := file.NewStyle(&excelize.Style{Font: &excelize.Font{Color: "#777777"}}) // styleID, err := file.NewStyle(&excelize.Style{Font: &excelize.Font{Color: "#777777"}})
// if err != nil { // if err != nil {
// fmt.Println(err) // fmt.Println(err)
// } // }
// if err := streamWriter.SetRow("A1", []interface{}{excelize.Cell{StyleID: styleID, Value: "Data"}}, // if err := streamWriter.SetRow("A1", []interface{}{excelize.Cell{StyleID: styleID, Value: "Data"}},
// excelize.RowOpts{Height: 45, Hidden: false}); err != nil { // excelize.RowOpts{Height: 45, Hidden: false}); err != nil {
// fmt.Println(err) // fmt.Println(err)
// } // }
// for rowID := 2; rowID <= 102400; rowID++ { // for rowID := 2; rowID <= 102400; rowID++ {
// row := make([]interface{}, 50) // row := make([]interface{}, 50)
// for colID := 0; colID < 50; colID++ { // for colID := 0; colID < 50; colID++ {
// row[colID] = rand.Intn(640000) // row[colID] = rand.Intn(640000)
// } // }
// cell, _ := excelize.CoordinatesToCellName(1, rowID) // cell, _ := excelize.CoordinatesToCellName(1, rowID)
// if err := streamWriter.SetRow(cell, row); err != nil { // if err := streamWriter.SetRow(cell, row); err != nil {
// fmt.Println(err) // fmt.Println(err)
// } // }
// } // }
// if err := streamWriter.Flush(); err != nil { // if err := streamWriter.Flush(); err != nil {
// fmt.Println(err) // fmt.Println(err)
// } // }
// if err := file.SaveAs("Book1.xlsx"); err != nil { // if err := file.SaveAs("Book1.xlsx"); err != nil {
// fmt.Println(err) // fmt.Println(err)
// } // }
// //
// Set cell value and cell formula for a worksheet with stream writer: // Set cell value and cell formula for a worksheet with stream writer:
// //
// err := streamWriter.SetRow("A1", []interface{}{ // err := streamWriter.SetRow("A1", []interface{}{
// excelize.Cell{Value: 1}, // excelize.Cell{Value: 1},
// excelize.Cell{Value: 2}, // excelize.Cell{Value: 2},
// excelize.Cell{Formula: "SUM(A1,B1)"}}); // excelize.Cell{Formula: "SUM(A1,B1)"}});
// //
// Set cell value and rows style for a worksheet with stream writer: // Set cell value and rows style for a worksheet with stream writer:
// //
// err := streamWriter.SetRow("A1", []interface{}{ // err := streamWriter.SetRow("A1", []interface{}{
// excelize.Cell{Value: 1}}, // excelize.Cell{Value: 1}},
// excelize.RowOpts{StyleID: styleID, Height: 20, Hidden: false}); // excelize.RowOpts{StyleID: styleID, Height: 20, Hidden: false});
//
func (f *File) NewStreamWriter(sheet string) (*StreamWriter, error) { func (f *File) NewStreamWriter(sheet string) (*StreamWriter, error) {
sheetID := f.getSheetID(sheet) sheetID := f.getSheetID(sheet)
if sheetID == -1 { if sheetID == -1 {
@ -120,18 +119,18 @@ func (f *File) NewStreamWriter(sheet string) (*StreamWriter, error) {
// AddTable creates an Excel table for the StreamWriter using the given // AddTable creates an Excel table for the StreamWriter using the given
// coordinate area and format set. For example, create a table of A1:D5: // coordinate area and format set. For example, create a table of A1:D5:
// //
// err := sw.AddTable("A1", "D5", "") // err := sw.AddTable("A1", "D5", "")
// //
// Create a table of F2:H6 with format set: // Create a table of F2:H6 with format set:
// //
// err := sw.AddTable("F2", "H6", `{ // err := sw.AddTable("F2", "H6", `{
// "table_name": "table", // "table_name": "table",
// "table_style": "TableStyleMedium2", // "table_style": "TableStyleMedium2",
// "show_first_column": true, // "show_first_column": true,
// "show_last_column": true, // "show_last_column": true,
// "show_row_stripes": false, // "show_row_stripes": false,
// "show_column_stripes": true // "show_column_stripes": true
// }`) // }`)
// //
// Note that the table must be at least two lines including the header. The // Note that the table must be at least two lines including the header. The
// header cells must contain strings and must be unique. // header cells must contain strings and must be unique.
@ -384,8 +383,7 @@ func marshalRowAttrs(opts ...RowOpts) (attrs string, err error) {
// the 'SetColWidth' function before the 'SetRow' function. For example set // the 'SetColWidth' function before the 'SetRow' function. For example set
// the width column B:C as 20: // the width column B:C as 20:
// //
// err := streamWriter.SetColWidth(2, 3, 20) // err := streamWriter.SetColWidth(2, 3, 20)
//
func (sw *StreamWriter) SetColWidth(min, max int, width float64) error { func (sw *StreamWriter) SetColWidth(min, max int, width float64) error {
if sw.sheetWritten { if sw.sheetWritten {
return ErrStreamSetColWidth return ErrStreamSetColWidth

File diff suppressed because it is too large Load Diff

@ -32,18 +32,18 @@ func parseFormatTableSet(formatSet string) (*formatTable, error) {
// name, coordinate area and format set. For example, create a table of A1:D5 // name, coordinate area and format set. For example, create a table of A1:D5
// on Sheet1: // on Sheet1:
// //
// err := f.AddTable("Sheet1", "A1", "D5", "") // err := f.AddTable("Sheet1", "A1", "D5", "")
// //
// Create a table of F2:H6 on Sheet2 with format set: // Create a table of F2:H6 on Sheet2 with format set:
// //
// err := f.AddTable("Sheet2", "F2", "H6", `{ // err := f.AddTable("Sheet2", "F2", "H6", `{
// "table_name": "table", // "table_name": "table",
// "table_style": "TableStyleMedium2", // "table_style": "TableStyleMedium2",
// "show_first_column": true, // "show_first_column": true,
// "show_last_column": true, // "show_last_column": true,
// "show_row_stripes": false, // "show_row_stripes": false,
// "show_column_stripes": true // "show_column_stripes": true
// }`) // }`)
// //
// Note that the table must be at least two lines including the header. The // Note that the table must be at least two lines including the header. The
// header cells must contain strings and must be unique, and must set the // header cells must contain strings and must be unique, and must set the
@ -54,10 +54,9 @@ func parseFormatTableSet(formatSet string) (*formatTable, error) {
// //
// table_style: The built-in table style names // table_style: The built-in table style names
// //
// TableStyleLight1 - TableStyleLight21 // TableStyleLight1 - TableStyleLight21
// TableStyleMedium1 - TableStyleMedium28 // TableStyleMedium1 - TableStyleMedium28
// TableStyleDark1 - TableStyleDark11 // TableStyleDark1 - TableStyleDark11
//
func (f *File) AddTable(sheet, hCell, vCell, format string) error { func (f *File) AddTable(sheet, hCell, vCell, format string) error {
formatSet, err := parseFormatTableSet(format) formatSet, err := parseFormatTableSet(format)
if err != nil { if err != nil {
@ -216,11 +215,11 @@ func parseAutoFilterSet(formatSet string) (*formatAutoFilter, error) {
// way of filtering a 2D range of data based on some simple criteria. For // 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: // example applying an autofilter to a cell range A1:D4 in the Sheet1:
// //
// err := f.AutoFilter("Sheet1", "A1", "D4", "") // err := f.AutoFilter("Sheet1", "A1", "D4", "")
// //
// Filter data in an autofilter: // Filter data in an autofilter:
// //
// err := f.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 // column defines the filter columns in a autofilter range based on simple
// criteria // criteria
@ -235,38 +234,38 @@ func parseAutoFilterSet(formatSet string) (*formatAutoFilter, error) {
// expression defines the conditions, the following operators are available // expression defines the conditions, the following operators are available
// for setting the filter criteria: // for setting the filter criteria:
// //
// == // ==
// != // !=
// > // >
// < // <
// >= // >=
// <= // <=
// and // and
// or // or
// //
// An expression can comprise a single statement or two statements separated // An expression can comprise a single statement or two statements separated
// by the 'and' and 'or' operators. For example: // by the 'and' and 'or' operators. For example:
// //
// x < 2000 // x < 2000
// x > 2000 // x > 2000
// x == 2000 // x == 2000
// x > 2000 and x < 5000 // x > 2000 and x < 5000
// x == 2000 or x == 5000 // x == 2000 or x == 5000
// //
// Filtering of blank or non-blank data can be achieved by using a value of // Filtering of blank or non-blank data can be achieved by using a value of
// Blanks or NonBlanks in the expression: // Blanks or NonBlanks in the expression:
// //
// x == Blanks // x == Blanks
// x == NonBlanks // x == NonBlanks
// //
// Excel also allows some simple string matching operations: // Excel also allows some simple string matching operations:
// //
// x == b* // begins with b // x == b* // begins with b
// x != b* // doesn't begin with b // x != b* // doesn't begin with b
// x == *b // ends with b // x == *b // ends with b
// x != *b // doesn't end with b // x != *b // doesn't end with b
// x == *b* // contains b // x == *b* // contains b
// x != *b* // doesn't contains b // x != *b* // doesn't contains b
// //
// You can also use '*' to match any character or number and '?' to match any // You can also use '*' to match any character or number and '?' to match any
// single character or number. No other regular expression quantifier is // single character or number. No other regular expression quantifier is
@ -277,10 +276,9 @@ func parseAutoFilterSet(formatSet string) (*formatAutoFilter, error) {
// simple string. The actual placeholder name is ignored internally so the // simple string. The actual placeholder name is ignored internally so the
// following are all equivalent: // following are all equivalent:
// //
// x < 2000 // x < 2000
// col < 2000 // col < 2000
// Price < 2000 // Price < 2000
//
func (f *File) AutoFilter(sheet, hCell, vCell, format string) error { func (f *File) AutoFilter(sheet, hCell, vCell, format string) error {
hCol, hRow, err := CellNameToCoordinates(hCell) hCol, hRow, err := CellNameToCoordinates(hCell)
if err != nil { if err != nil {
@ -436,9 +434,8 @@ func (f *File) writeCustomFilter(filter *xlsxAutoFilter, operator int, val strin
// //
// Examples: // Examples:
// //
// ('x', '==', 2000) -> exp1 // ('x', '==', 2000) -> exp1
// ('x', '>', 2000, 'and', 'x', '<', 5000) -> exp1 and exp2 // ('x', '>', 2000, 'and', 'x', '<', 5000) -> exp1 and exp2
//
func (f *File) parseFilterExpression(expression string, tokens []string) ([]int, []string, error) { func (f *File) parseFilterExpression(expression string, tokens []string) ([]int, []string, error) {
var expressions []int var expressions []int
var t []string var t []string

@ -120,9 +120,10 @@ func (f *File) workBookWriter() {
// SetWorkbookPrOptions provides a function to sets workbook properties. // SetWorkbookPrOptions provides a function to sets workbook properties.
// //
// Available options: // Available options:
// Date1904(bool) //
// FilterPrivacy(bool) // Date1904(bool)
// CodeName(string) // FilterPrivacy(bool)
// CodeName(string)
func (f *File) SetWorkbookPrOptions(opts ...WorkbookPrOption) error { func (f *File) SetWorkbookPrOptions(opts ...WorkbookPrOption) error {
wb := f.workbookReader() wb := f.workbookReader()
pr := wb.WorkbookPr pr := wb.WorkbookPr
@ -154,9 +155,10 @@ func (o CodeName) setWorkbookPrOption(pr *xlsxWorkbookPr) {
// GetWorkbookPrOptions provides a function to gets workbook properties. // GetWorkbookPrOptions provides a function to gets workbook properties.
// //
// Available options: // Available options:
// Date1904(bool) //
// FilterPrivacy(bool) // Date1904(bool)
// CodeName(string) // FilterPrivacy(bool)
// CodeName(string)
func (f *File) GetWorkbookPrOptions(opts ...WorkbookPrOptionPtr) error { func (f *File) GetWorkbookPrOptions(opts ...WorkbookPrOptionPtr) error {
wb := f.workbookReader() wb := f.workbookReader()
pr := wb.WorkbookPr pr := wb.WorkbookPr

@ -21,60 +21,59 @@ type xlsxCalcChain struct {
// xlsxCalcChainC directly maps the c element. // xlsxCalcChainC directly maps the c element.
// //
// Attributes | Attributes // Attributes | Attributes
// --------------------------+---------------------------------------------------------- // --------------------------+----------------------------------------------------------
// a (Array) | A Boolean flag indicating whether the cell's formula // a (Array) | A Boolean flag indicating whether the cell's formula
// | is an array formula. True if this cell's formula is // | is an array formula. True if this cell's formula is
// | an array formula, false otherwise. If there is a // | an array formula, false otherwise. If there is a
// | conflict between this attribute and the t attribute // | conflict between this attribute and the t attribute
// | of the f element (§18.3.1.40), the t attribute takes // | of the f element (§18.3.1.40), the t attribute takes
// | precedence. The possible values for this attribute // | precedence. The possible values for this attribute
// | are defined by the W3C XML Schema boolean datatype. // | are defined by the W3C XML Schema boolean datatype.
// | // |
// i (Sheet Id) | A sheet Id of a sheet the cell belongs to. If this is // i (Sheet Id) | A sheet Id of a sheet the cell belongs to. If this is
// | omitted, it is assumed to be the same as the i value // | omitted, it is assumed to be the same as the i value
// | of the previous cell.The possible values for this // | of the previous cell.The possible values for this
// | attribute are defined by the W3C XML Schema int datatype. // | attribute are defined by the W3C XML Schema int datatype.
// | // |
// l (New Dependency Level) | A Boolean flag indicating that the cell's formula // l (New Dependency Level) | A Boolean flag indicating that the cell's formula
// | starts a new dependency level. True if the formula // | starts a new dependency level. True if the formula
// | starts a new dependency level, false otherwise. // | starts a new dependency level, false otherwise.
// | Starting a new dependency level means that all // | Starting a new dependency level means that all
// | concurrent calculations, and child calculations, shall // | concurrent calculations, and child calculations, shall
// | be completed - and the cells have new values - before // | be completed - and the cells have new values - before
// | the calc chain can continue. In other words, this // | the calc chain can continue. In other words, this
// | dependency level might depend on levels that came before // | dependency level might depend on levels that came before
// | it, and any later dependency levels might depend on // | it, and any later dependency levels might depend on
// | this level; but not later dependency levels can have // | this level; but not later dependency levels can have
// | any calculations started until this dependency level // | any calculations started until this dependency level
// | completes.The possible values for this attribute are // | completes.The possible values for this attribute are
// | defined by the W3C XML Schema boolean datatype. // | defined by the W3C XML Schema boolean datatype.
// | // |
// r (Cell Reference) | An A-1 style reference to a cell.The possible values // r (Cell Reference) | An A-1 style reference to a cell.The possible values
// | for this attribute are defined by the ST_CellRef // | for this attribute are defined by the ST_CellRef
// | simple type (§18.18.7). // | simple type (§18.18.7).
// | // |
// s (Child Chain) | A Boolean flag indicating whether the cell's formula // s (Child Chain) | A Boolean flag indicating whether the cell's formula
// | is on a child chain. True if this cell is part of a // | is on a child chain. True if this cell is part of a
// | child chain, false otherwise. If this is omitted, it // | child chain, false otherwise. If this is omitted, it
// | is assumed to be the same as the s value of the // | is assumed to be the same as the s value of the
// | previous cell .A child chain is a list of calculations // | previous cell .A child chain is a list of calculations
// | that occur which depend on the parent to the chain. // | that occur which depend on the parent to the chain.
// | There shall not be cross dependencies between child // | There shall not be cross dependencies between child
// | chains. Child chains are not the same as dependency // | chains. Child chains are not the same as dependency
// | levels - a child chain and its parent are all on the // | levels - a child chain and its parent are all on the
// | same dependency level. Child chains are series of // | same dependency level. Child chains are series of
// | calculations that can be independently farmed out to // | calculations that can be independently farmed out to
// | other threads or processors.The possible values for // | other threads or processors.The possible values for
// | this attribute is defined by the W3C XML Schema // | this attribute is defined by the W3C XML Schema
// | boolean datatype. // | boolean datatype.
// | // |
// t (New Thread) | A Boolean flag indicating whether the cell's formula // t (New Thread) | A Boolean flag indicating whether the cell's formula
// | starts a new thread. True if the cell's formula starts // | starts a new thread. True if the cell's formula starts
// | a new thread, false otherwise.The possible values for // | a new thread, false otherwise.The possible values for
// | this attribute is defined by the W3C XML Schema // | this attribute is defined by the W3C XML Schema
// | boolean datatype. // | boolean datatype.
//
type xlsxCalcChainC struct { type xlsxCalcChainC struct {
R string `xml:"r,attr"` R string `xml:"r,attr"`
I int `xml:"i,attr"` I int `xml:"i,attr"`

@ -449,16 +449,15 @@ type DataValidation struct {
// //
// This simple type is restricted to the values listed in the following table: // This simple type is restricted to the values listed in the following table:
// //
// Enumeration Value | Description // Enumeration Value | Description
// ---------------------------+--------------------------------- // ---------------------------+---------------------------------
// b (Boolean) | Cell containing a boolean. // b (Boolean) | Cell containing a boolean.
// d (Date) | Cell contains a date in the ISO 8601 format. // d (Date) | Cell contains a date in the ISO 8601 format.
// e (Error) | Cell containing an error. // e (Error) | Cell containing an error.
// inlineStr (Inline String) | Cell containing an (inline) rich string, i.e., one not in the shared string table. If this cell type is used, then the cell value is in the is element rather than the v element in the cell (c element). // inlineStr (Inline String) | Cell containing an (inline) rich string, i.e., one not in the shared string table. If this cell type is used, then the cell value is in the is element rather than the v element in the cell (c element).
// n (Number) | Cell containing a number. // n (Number) | Cell containing a number.
// s (Shared String) | Cell containing a shared string. // s (Shared String) | Cell containing a shared string.
// str (String) | Cell containing a formula string. // str (String) | Cell containing a formula string.
//
type xlsxC struct { type xlsxC struct {
XMLName xml.Name `xml:"c"` XMLName xml.Name `xml:"c"`
XMLSpace xml.Attr `xml:"space,attr,omitempty"` XMLSpace xml.Attr `xml:"space,attr,omitempty"`
@ -644,13 +643,12 @@ type xlsxHyperlink struct {
// size of the sample. To reference the table, just add the tableParts element, // size of the sample. To reference the table, just add the tableParts element,
// of course after having created and stored the table part. For example: // of course after having created and stored the table part. For example:
// //
// <worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"> // <worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
// ... // ...
// <tableParts count="1"> // <tableParts count="1">
// <tablePart r:id="rId1" /> // <tablePart r:id="rId1" />
// </tableParts> // </tableParts>
// </worksheet> // </worksheet>
//
type xlsxTableParts struct { type xlsxTableParts struct {
XMLName xml.Name `xml:"tableParts"` XMLName xml.Name `xml:"tableParts"`
Count int `xml:"count,attr,omitempty"` Count int `xml:"count,attr,omitempty"`
@ -667,8 +665,7 @@ type xlsxTablePart struct {
// http://schemas.openxmlformats.org/spreadsheetml/2006/main - Background sheet // http://schemas.openxmlformats.org/spreadsheetml/2006/main - Background sheet
// image. For example: // image. For example:
// //
// <picture r:id="rId1"/> // <picture r:id="rId1"/>
//
type xlsxPicture struct { type xlsxPicture struct {
XMLName xml.Name `xml:"picture"` XMLName xml.Name `xml:"picture"`
RID string `xml:"http://schemas.openxmlformats.org/officeDocument/2006/relationships id,attr,omitempty"` RID string `xml:"http://schemas.openxmlformats.org/officeDocument/2006/relationships id,attr,omitempty"`

Loading…
Cancel
Save