- Format code with `gofmt`
This commit is contained in:
parent
8152bbb2ce
commit
551fb8a9e4
|
@ -35,7 +35,6 @@ const (
|
|||
// offset: Number of rows/column to insert/delete negative values indicate deletion
|
||||
//
|
||||
// TODO: adjustPageBreaks, adjustComments, adjustDataValidations, adjustProtectedCells
|
||||
//
|
||||
func (f *File) adjustHelper(sheet string, dir adjustDirection, num, offset int) error {
|
||||
ws, err := f.workSheetReader(sheet)
|
||||
if err != nil {
|
||||
|
|
386
cell.go
386
cell.go
|
@ -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
|
||||
// types:
|
||||
//
|
||||
// int
|
||||
// int8
|
||||
// int16
|
||||
// int32
|
||||
// int64
|
||||
// uint
|
||||
// uint8
|
||||
// uint16
|
||||
// uint32
|
||||
// uint64
|
||||
// float32
|
||||
// float64
|
||||
// string
|
||||
// []byte
|
||||
// time.Duration
|
||||
// time.Time
|
||||
// bool
|
||||
// nil
|
||||
// int
|
||||
// int8
|
||||
// int16
|
||||
// int32
|
||||
// int64
|
||||
// uint
|
||||
// uint8
|
||||
// uint16
|
||||
// uint32
|
||||
// uint64
|
||||
// float32
|
||||
// float64
|
||||
// string
|
||||
// []byte
|
||||
// time.Duration
|
||||
// time.Time
|
||||
// bool
|
||||
// nil
|
||||
//
|
||||
// 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
|
||||
|
@ -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
|
||||
// float64 was originally used for the value. For Example:
|
||||
//
|
||||
// var x float32 = 1.325
|
||||
// f.SetCellFloat("Sheet1", "A1", float64(x), 2, 32)
|
||||
//
|
||||
// var x float32 = 1.325
|
||||
// f.SetCellFloat("Sheet1", "A1", float64(x), 2, 32)
|
||||
func (f *File) SetCellFloat(sheet, axis string, value float64, precision, bitSize int) error {
|
||||
ws, err := f.workSheetReader(sheet)
|
||||
if err != nil {
|
||||
|
@ -522,73 +521,72 @@ type FormulaOpts struct {
|
|||
//
|
||||
// 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
|
||||
// "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)
|
||||
// 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
|
||||
// the cell "A3" on "Sheet1":
|
||||
//
|
||||
// formulaType, ref := excelize.STCellFormulaTypeArray, "A3:A3"
|
||||
// err := f.SetCellFormula("Sheet1", "A3", "={1,2,\"a\",\"b\"}",
|
||||
// excelize.FormulaOpts{Ref: &ref, Type: &formulaType})
|
||||
// formulaType, ref := excelize.STCellFormulaTypeArray, "A3:A3"
|
||||
// err := f.SetCellFormula("Sheet1", "A3", "={1,2,\"a\",\"b\"}",
|
||||
// excelize.FormulaOpts{Ref: &ref, Type: &formulaType})
|
||||
//
|
||||
// Example 5, set range array formula "A1:A2" for the cell "A3" on "Sheet1":
|
||||
//
|
||||
// formulaType, ref := excelize.STCellFormulaTypeArray, "A3:A3"
|
||||
// err := f.SetCellFormula("Sheet1", "A3", "=A1:A2",
|
||||
// excelize.FormulaOpts{Ref: &ref, Type: &formulaType})
|
||||
// formulaType, ref := excelize.STCellFormulaTypeArray, "A3:A3"
|
||||
// err := f.SetCellFormula("Sheet1", "A3", "=A1:A2",
|
||||
// excelize.FormulaOpts{Ref: &ref, Type: &formulaType})
|
||||
//
|
||||
// Example 6, set shared formula "=A1+B1" for the cell "C1:C5"
|
||||
// on "Sheet1", "C1" is the master cell:
|
||||
//
|
||||
// formulaType, ref := excelize.STCellFormulaTypeShared, "C1:C5"
|
||||
// err := f.SetCellFormula("Sheet1", "C1", "=A1+B1",
|
||||
// excelize.FormulaOpts{Ref: &ref, Type: &formulaType})
|
||||
// formulaType, ref := excelize.STCellFormulaTypeShared, "C1:C5"
|
||||
// err := f.SetCellFormula("Sheet1", "C1", "=A1+B1",
|
||||
// excelize.FormulaOpts{Ref: &ref, Type: &formulaType})
|
||||
//
|
||||
// Example 7, set table formula "=SUM(Table1[[A]:[B]])" for the cell "C2"
|
||||
// on "Sheet1":
|
||||
//
|
||||
// package main
|
||||
// package main
|
||||
//
|
||||
// import (
|
||||
// "fmt"
|
||||
// import (
|
||||
// "fmt"
|
||||
//
|
||||
// "github.com/xuri/excelize/v2"
|
||||
// )
|
||||
//
|
||||
// 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)
|
||||
// }
|
||||
// }
|
||||
// "github.com/xuri/excelize/v2"
|
||||
// )
|
||||
//
|
||||
// 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 {
|
||||
ws, err := f.workSheetReader(sheet)
|
||||
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':
|
||||
//
|
||||
// link, target, err := f.GetCellHyperLink("Sheet1", "H6")
|
||||
//
|
||||
// link, target, err := f.GetCellHyperLink("Sheet1", "H6")
|
||||
func (f *File) GetCellHyperLink(sheet, axis string) (bool, string, error) {
|
||||
// Check for correct cell name
|
||||
if _, _, err := SplitCellName(axis); err != nil {
|
||||
|
@ -714,27 +711,26 @@ type HyperlinkOpts struct {
|
|||
// the other functions such as `SetCellStyle` or `SetSheetRow`. The below is
|
||||
// example for external link.
|
||||
//
|
||||
// display, tooltip := "https://github.com/xuri/excelize", "Excelize on GitHub"
|
||||
// if err := f.SetCellHyperLink("Sheet1", "A3",
|
||||
// "https://github.com/xuri/excelize", "External", excelize.HyperlinkOpts{
|
||||
// Display: &display,
|
||||
// Tooltip: &tooltip,
|
||||
// }); err != nil {
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
// // Set underline and font color style for the cell.
|
||||
// style, err := f.NewStyle(&excelize.Style{
|
||||
// Font: &excelize.Font{Color: "#1265BE", Underline: "single"},
|
||||
// })
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
// err = f.SetCellStyle("Sheet1", "A3", "A3", style)
|
||||
// display, tooltip := "https://github.com/xuri/excelize", "Excelize on GitHub"
|
||||
// if err := f.SetCellHyperLink("Sheet1", "A3",
|
||||
// "https://github.com/xuri/excelize", "External", excelize.HyperlinkOpts{
|
||||
// Display: &display,
|
||||
// Tooltip: &tooltip,
|
||||
// }); err != nil {
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
// // Set underline and font color style for the cell.
|
||||
// style, err := f.NewStyle(&excelize.Style{
|
||||
// Font: &excelize.Font{Color: "#1265BE", Underline: "single"},
|
||||
// })
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
// err = f.SetCellStyle("Sheet1", "A3", "A3", style)
|
||||
//
|
||||
// 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 {
|
||||
// Check for correct cell name
|
||||
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
|
||||
// Sheet1:
|
||||
//
|
||||
// package main
|
||||
// package main
|
||||
//
|
||||
// import (
|
||||
// "fmt"
|
||||
// import (
|
||||
// "fmt"
|
||||
//
|
||||
// "github.com/xuri/excelize/v2"
|
||||
// )
|
||||
//
|
||||
// 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)
|
||||
// }
|
||||
// }
|
||||
// "github.com/xuri/excelize/v2"
|
||||
// )
|
||||
//
|
||||
// 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 {
|
||||
ws, err := f.workSheetReader(sheet)
|
||||
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
|
||||
// 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 {
|
||||
col, row, err := CellNameToCoordinates(axis)
|
||||
if err != nil {
|
||||
|
|
569
chart.go
569
chart.go
|
@ -500,152 +500,152 @@ func parseFormatChartSet(formatSet string) (*formatChart, error) {
|
|||
// properties set. For example, create 3D clustered column chart with data
|
||||
// Sheet1!$E$1:$L$15:
|
||||
//
|
||||
// package main
|
||||
// package main
|
||||
//
|
||||
// import (
|
||||
// "fmt"
|
||||
// import (
|
||||
// "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": "col3DClustered",
|
||||
// "series": [
|
||||
// {
|
||||
// "name": "Sheet1!$A$2",
|
||||
// "categories": "Sheet1!$B$1:$D$1",
|
||||
// "values": "Sheet1!$B$2:$D$2"
|
||||
// },
|
||||
// {
|
||||
// "name": "Sheet1!$A$3",
|
||||
// "categories": "Sheet1!$B$1:$D$1",
|
||||
// "values": "Sheet1!$B$3:$D$3"
|
||||
// },
|
||||
// {
|
||||
// "name": "Sheet1!$A$4",
|
||||
// "categories": "Sheet1!$B$1:$D$1",
|
||||
// "values": "Sheet1!$B$4:$D$4"
|
||||
// }],
|
||||
// "title":
|
||||
// {
|
||||
// "name": "Fruit 3D Clustered Column Chart"
|
||||
// },
|
||||
// "legend":
|
||||
// {
|
||||
// "none": false,
|
||||
// "position": "bottom",
|
||||
// "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
|
||||
// },
|
||||
// "show_blanks_as": "zero",
|
||||
// "x_axis":
|
||||
// {
|
||||
// "reverse_order": true
|
||||
// },
|
||||
// "y_axis":
|
||||
// {
|
||||
// "maximum": 7.5,
|
||||
// "minimum": 0.5
|
||||
// }
|
||||
// }`); err != nil {
|
||||
// fmt.Println(err)
|
||||
// return
|
||||
// }
|
||||
// // Save spreadsheet 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": "col3DClustered",
|
||||
// "series": [
|
||||
// {
|
||||
// "name": "Sheet1!$A$2",
|
||||
// "categories": "Sheet1!$B$1:$D$1",
|
||||
// "values": "Sheet1!$B$2:$D$2"
|
||||
// },
|
||||
// {
|
||||
// "name": "Sheet1!$A$3",
|
||||
// "categories": "Sheet1!$B$1:$D$1",
|
||||
// "values": "Sheet1!$B$3:$D$3"
|
||||
// },
|
||||
// {
|
||||
// "name": "Sheet1!$A$4",
|
||||
// "categories": "Sheet1!$B$1:$D$1",
|
||||
// "values": "Sheet1!$B$4:$D$4"
|
||||
// }],
|
||||
// "title":
|
||||
// {
|
||||
// "name": "Fruit 3D Clustered Column Chart"
|
||||
// },
|
||||
// "legend":
|
||||
// {
|
||||
// "none": false,
|
||||
// "position": "bottom",
|
||||
// "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
|
||||
// },
|
||||
// "show_blanks_as": "zero",
|
||||
// "x_axis":
|
||||
// {
|
||||
// "reverse_order": true
|
||||
// },
|
||||
// "y_axis":
|
||||
// {
|
||||
// "maximum": 7.5,
|
||||
// "minimum": 0.5
|
||||
// }
|
||||
// }`); err != nil {
|
||||
// fmt.Println(err)
|
||||
// return
|
||||
// }
|
||||
// // Save spreadsheet by the given path.
|
||||
// if err := f.SaveAs("Book1.xlsx"); err != nil {
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// The following shows the type of chart supported by excelize:
|
||||
//
|
||||
// Type | Chart
|
||||
// -----------------------------+------------------------------
|
||||
// area | 2D area chart
|
||||
// areaStacked | 2D stacked area chart
|
||||
// areaPercentStacked | 2D 100% stacked area chart
|
||||
// area3D | 3D area chart
|
||||
// area3DStacked | 3D stacked area chart
|
||||
// area3DPercentStacked | 3D 100% stacked area chart
|
||||
// bar | 2D clustered bar chart
|
||||
// barStacked | 2D stacked bar chart
|
||||
// barPercentStacked | 2D 100% stacked bar chart
|
||||
// bar3DClustered | 3D clustered bar chart
|
||||
// bar3DStacked | 3D stacked bar chart
|
||||
// bar3DPercentStacked | 3D 100% stacked bar chart
|
||||
// bar3DConeClustered | 3D cone clustered bar chart
|
||||
// bar3DConeStacked | 3D cone stacked bar chart
|
||||
// bar3DConePercentStacked | 3D cone percent bar chart
|
||||
// bar3DPyramidClustered | 3D pyramid clustered bar chart
|
||||
// bar3DPyramidStacked | 3D pyramid stacked bar chart
|
||||
// bar3DPyramidPercentStacked | 3D pyramid percent stacked bar chart
|
||||
// bar3DCylinderClustered | 3D cylinder clustered bar chart
|
||||
// bar3DCylinderStacked | 3D cylinder stacked bar chart
|
||||
// bar3DCylinderPercentStacked | 3D cylinder percent stacked bar chart
|
||||
// col | 2D clustered column chart
|
||||
// colStacked | 2D stacked column chart
|
||||
// colPercentStacked | 2D 100% stacked column chart
|
||||
// col3DClustered | 3D clustered column chart
|
||||
// col3D | 3D column chart
|
||||
// col3DStacked | 3D stacked column chart
|
||||
// col3DPercentStacked | 3D 100% stacked column chart
|
||||
// col3DCone | 3D cone column chart
|
||||
// col3DConeClustered | 3D cone clustered column chart
|
||||
// col3DConeStacked | 3D cone stacked column chart
|
||||
// col3DConePercentStacked | 3D cone percent stacked column chart
|
||||
// col3DPyramid | 3D pyramid column chart
|
||||
// col3DPyramidClustered | 3D pyramid clustered column chart
|
||||
// col3DPyramidStacked | 3D pyramid stacked column chart
|
||||
// col3DPyramidPercentStacked | 3D pyramid percent stacked column chart
|
||||
// col3DCylinder | 3D cylinder column chart
|
||||
// col3DCylinderClustered | 3D cylinder clustered column chart
|
||||
// col3DCylinderStacked | 3D cylinder stacked column chart
|
||||
// col3DCylinderPercentStacked | 3D cylinder percent stacked column chart
|
||||
// doughnut | doughnut chart
|
||||
// line | line chart
|
||||
// pie | pie chart
|
||||
// pie3D | 3D pie chart
|
||||
// pieOfPie | pie of pie chart
|
||||
// barOfPie | bar of pie chart
|
||||
// radar | radar chart
|
||||
// scatter | scatter chart
|
||||
// surface3D | 3D surface chart
|
||||
// wireframeSurface3D | 3D wireframe surface chart
|
||||
// contour | contour chart
|
||||
// wireframeContour | wireframe contour chart
|
||||
// bubble | bubble chart
|
||||
// bubble3D | 3D bubble chart
|
||||
// Type | Chart
|
||||
// -----------------------------+------------------------------
|
||||
// area | 2D area chart
|
||||
// areaStacked | 2D stacked area chart
|
||||
// areaPercentStacked | 2D 100% stacked area chart
|
||||
// area3D | 3D area chart
|
||||
// area3DStacked | 3D stacked area chart
|
||||
// area3DPercentStacked | 3D 100% stacked area chart
|
||||
// bar | 2D clustered bar chart
|
||||
// barStacked | 2D stacked bar chart
|
||||
// barPercentStacked | 2D 100% stacked bar chart
|
||||
// bar3DClustered | 3D clustered bar chart
|
||||
// bar3DStacked | 3D stacked bar chart
|
||||
// bar3DPercentStacked | 3D 100% stacked bar chart
|
||||
// bar3DConeClustered | 3D cone clustered bar chart
|
||||
// bar3DConeStacked | 3D cone stacked bar chart
|
||||
// bar3DConePercentStacked | 3D cone percent bar chart
|
||||
// bar3DPyramidClustered | 3D pyramid clustered bar chart
|
||||
// bar3DPyramidStacked | 3D pyramid stacked bar chart
|
||||
// bar3DPyramidPercentStacked | 3D pyramid percent stacked bar chart
|
||||
// bar3DCylinderClustered | 3D cylinder clustered bar chart
|
||||
// bar3DCylinderStacked | 3D cylinder stacked bar chart
|
||||
// bar3DCylinderPercentStacked | 3D cylinder percent stacked bar chart
|
||||
// col | 2D clustered column chart
|
||||
// colStacked | 2D stacked column chart
|
||||
// colPercentStacked | 2D 100% stacked column chart
|
||||
// col3DClustered | 3D clustered column chart
|
||||
// col3D | 3D column chart
|
||||
// col3DStacked | 3D stacked column chart
|
||||
// col3DPercentStacked | 3D 100% stacked column chart
|
||||
// col3DCone | 3D cone column chart
|
||||
// col3DConeClustered | 3D cone clustered column chart
|
||||
// col3DConeStacked | 3D cone stacked column chart
|
||||
// col3DConePercentStacked | 3D cone percent stacked column chart
|
||||
// col3DPyramid | 3D pyramid column chart
|
||||
// col3DPyramidClustered | 3D pyramid clustered column chart
|
||||
// col3DPyramidStacked | 3D pyramid stacked column chart
|
||||
// col3DPyramidPercentStacked | 3D pyramid percent stacked column chart
|
||||
// col3DCylinder | 3D cylinder column chart
|
||||
// col3DCylinderClustered | 3D cylinder clustered column chart
|
||||
// col3DCylinderStacked | 3D cylinder stacked column chart
|
||||
// col3DCylinderPercentStacked | 3D cylinder percent stacked column chart
|
||||
// doughnut | doughnut chart
|
||||
// line | line chart
|
||||
// pie | pie chart
|
||||
// pie3D | 3D pie chart
|
||||
// pieOfPie | pie of pie chart
|
||||
// barOfPie | bar of pie chart
|
||||
// radar | radar chart
|
||||
// scatter | scatter chart
|
||||
// surface3D | 3D surface chart
|
||||
// wireframeSurface3D | 3D wireframe surface chart
|
||||
// contour | contour chart
|
||||
// wireframeContour | wireframe contour chart
|
||||
// bubble | 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.
|
||||
//
|
||||
// The series options that can be set are:
|
||||
//
|
||||
// name
|
||||
// categories
|
||||
// values
|
||||
// line
|
||||
// marker
|
||||
// name
|
||||
// categories
|
||||
// values
|
||||
// line
|
||||
// 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
|
||||
//
|
||||
|
@ -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'):
|
||||
//
|
||||
// circle
|
||||
// dash
|
||||
// diamond
|
||||
// dot
|
||||
// none
|
||||
// picture
|
||||
// plus
|
||||
// square
|
||||
// star
|
||||
// triangle
|
||||
// x
|
||||
// auto
|
||||
// circle
|
||||
// dash
|
||||
// diamond
|
||||
// dot
|
||||
// none
|
||||
// picture
|
||||
// plus
|
||||
// square
|
||||
// star
|
||||
// triangle
|
||||
// x
|
||||
// auto
|
||||
//
|
||||
// Set properties of the chart legend. The options that can be set are:
|
||||
//
|
||||
// none
|
||||
// position
|
||||
// show_legend_key
|
||||
// none
|
||||
// position
|
||||
// show_legend_key
|
||||
//
|
||||
// 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:
|
||||
//
|
||||
// top
|
||||
// bottom
|
||||
// left
|
||||
// right
|
||||
// top_right
|
||||
// top
|
||||
// bottom
|
||||
// left
|
||||
// right
|
||||
// top_right
|
||||
//
|
||||
// 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:
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// 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
|
||||
// span
|
||||
// zero
|
||||
// gap
|
||||
// span
|
||||
// zero
|
||||
//
|
||||
// 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:
|
||||
//
|
||||
// show_bubble_size
|
||||
// show_cat_name
|
||||
// show_leader_lines
|
||||
// show_percent
|
||||
// show_series_name
|
||||
// show_val
|
||||
// show_bubble_size
|
||||
// show_cat_name
|
||||
// show_leader_lines
|
||||
// show_percent
|
||||
// show_series_name
|
||||
// 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.
|
||||
//
|
||||
|
@ -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:
|
||||
//
|
||||
// none
|
||||
// major_grid_lines
|
||||
// minor_grid_lines
|
||||
// tick_label_skip
|
||||
// reverse_order
|
||||
// maximum
|
||||
// minimum
|
||||
// none
|
||||
// major_grid_lines
|
||||
// minor_grid_lines
|
||||
// tick_label_skip
|
||||
// reverse_order
|
||||
// maximum
|
||||
// minimum
|
||||
//
|
||||
// The properties of y_axis that can be set are:
|
||||
//
|
||||
// none
|
||||
// major_grid_lines
|
||||
// minor_grid_lines
|
||||
// major_unit
|
||||
// reverse_order
|
||||
// maximum
|
||||
// minimum
|
||||
// none
|
||||
// major_grid_lines
|
||||
// minor_grid_lines
|
||||
// major_unit
|
||||
// reverse_order
|
||||
// maximum
|
||||
// minimum
|
||||
//
|
||||
// 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
|
||||
// data Sheet1!$E$1:$L$15:
|
||||
//
|
||||
// package main
|
||||
// package main
|
||||
//
|
||||
// import (
|
||||
// "fmt"
|
||||
// import (
|
||||
// "fmt"
|
||||
//
|
||||
// "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)
|
||||
// }
|
||||
// }
|
||||
// "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 (f *File) AddChart(sheet, cell, format string, combo ...string) error {
|
||||
// Read sheet data.
|
||||
ws, err := f.workSheetReader(sheet)
|
||||
|
|
132
col.go
132
col.go
|
@ -50,18 +50,17 @@ type Cols struct {
|
|||
// worksheet named
|
||||
// 'Sheet1':
|
||||
//
|
||||
// cols, err := f.GetCols("Sheet1")
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// return
|
||||
// }
|
||||
// for _, col := range cols {
|
||||
// for _, rowCell := range col {
|
||||
// fmt.Print(rowCell, "\t")
|
||||
// }
|
||||
// fmt.Println()
|
||||
// }
|
||||
//
|
||||
// cols, err := f.GetCols("Sheet1")
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// return
|
||||
// }
|
||||
// for _, col := range cols {
|
||||
// for _, rowCell := range col {
|
||||
// fmt.Print(rowCell, "\t")
|
||||
// }
|
||||
// fmt.Println()
|
||||
// }
|
||||
func (f *File) GetCols(sheet string, opts ...Options) ([][]string, error) {
|
||||
cols, err := f.Cols(sheet)
|
||||
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
|
||||
// worksheet with a large data. For example:
|
||||
//
|
||||
// cols, err := f.Cols("Sheet1")
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// return
|
||||
// }
|
||||
// for cols.Next() {
|
||||
// col, err := cols.Rows()
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
// for _, rowCell := range col {
|
||||
// fmt.Print(rowCell, "\t")
|
||||
// }
|
||||
// fmt.Println()
|
||||
// }
|
||||
//
|
||||
// cols, err := f.Cols("Sheet1")
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// return
|
||||
// }
|
||||
// for cols.Next() {
|
||||
// col, err := cols.Rows()
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
// for _, rowCell := range col {
|
||||
// fmt.Print(rowCell, "\t")
|
||||
// }
|
||||
// fmt.Println()
|
||||
// }
|
||||
func (f *File) Cols(sheet string) (*Cols, error) {
|
||||
name, ok := f.getSheetXMLPath(sheet)
|
||||
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
|
||||
// in Sheet1:
|
||||
//
|
||||
// visible, err := f.GetColVisible("Sheet1", "D")
|
||||
//
|
||||
// visible, err := f.GetColVisible("Sheet1", "D")
|
||||
func (f *File) GetColVisible(sheet, col string) (bool, error) {
|
||||
colNum, err := ColumnNameToNumber(col)
|
||||
if err != nil {
|
||||
|
@ -273,12 +270,11 @@ func (f *File) GetColVisible(sheet, col string) (bool, error) {
|
|||
//
|
||||
// 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):
|
||||
//
|
||||
// err := f.SetColVisible("Sheet1", "D:F", false)
|
||||
//
|
||||
// err := f.SetColVisible("Sheet1", "D:F", false)
|
||||
func (f *File) SetColVisible(sheet, columns string, visible bool) error {
|
||||
start, end, err := f.parseColRange(columns)
|
||||
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
|
||||
// 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) {
|
||||
level := uint8(0)
|
||||
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
|
||||
// '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 {
|
||||
if level > 7 || level < 1 {
|
||||
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:
|
||||
//
|
||||
// err = f.SetColStyle("Sheet1", "H", style)
|
||||
// err = f.SetColStyle("Sheet1", "H", style)
|
||||
//
|
||||
// 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 {
|
||||
start, end, err := f.parseColRange(columns)
|
||||
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
|
||||
// multiple columns. For example:
|
||||
//
|
||||
// f := excelize.NewFile()
|
||||
// err := f.SetColWidth("Sheet1", "A", "H", 20)
|
||||
//
|
||||
// f := excelize.NewFile()
|
||||
// err := f.SetColWidth("Sheet1", "A", "H", 20)
|
||||
func (f *File) SetColWidth(sheet, startCol, endCol string, width float64) error {
|
||||
min, err := ColumnNameToNumber(startCol)
|
||||
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
|
||||
// graphical object within the worksheet in pixels.
|
||||
//
|
||||
// +------------+------------+
|
||||
// | A | B |
|
||||
// +-----+------------+------------+
|
||||
// | |(x1,y1) | |
|
||||
// | 1 |(A1)._______|______ |
|
||||
// | | | | |
|
||||
// | | | | |
|
||||
// +-----+----| OBJECT |-----+
|
||||
// | | | | |
|
||||
// | 2 | |______________. |
|
||||
// | | | (B2)|
|
||||
// | | | (x2,y2)|
|
||||
// +-----+------------+------------+
|
||||
// +------------+------------+
|
||||
// | A | B |
|
||||
// +-----+------------+------------+
|
||||
// | |(x1,y1) | |
|
||||
// | 1 |(A1)._______|______ |
|
||||
// | | | | |
|
||||
// | | | | |
|
||||
// +-----+----| OBJECT |-----+
|
||||
// | | | | |
|
||||
// | 2 | |______________. |
|
||||
// | | | (B2)|
|
||||
// | | | (x2,y2)|
|
||||
// +-----+------------+------------+
|
||||
//
|
||||
// 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:
|
||||
//
|
||||
// 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
|
||||
// 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
|
||||
// height of the underlying cells.
|
||||
//
|
||||
// colStart # Col containing upper left corner of object.
|
||||
// x1 # Distance to left side of object.
|
||||
// colStart # Col containing upper left corner of object.
|
||||
// x1 # Distance to left side of object.
|
||||
//
|
||||
// rowStart # Row containing top left corner of object.
|
||||
// y1 # Distance to top of object.
|
||||
// rowStart # Row containing top left corner of object.
|
||||
// y1 # Distance to top of object.
|
||||
//
|
||||
// colEnd # Col containing lower right corner of object.
|
||||
// x2 # Distance to right side of object.
|
||||
// colEnd # Col containing lower right corner of object.
|
||||
// x2 # Distance to right side of object.
|
||||
//
|
||||
// rowEnd # Row containing bottom right corner of object.
|
||||
// y2 # Distance to bottom of object.
|
||||
//
|
||||
// width # Width of object frame.
|
||||
// height # Height of object frame.
|
||||
// rowEnd # Row containing bottom right corner of object.
|
||||
// y2 # Distance to bottom of object.
|
||||
//
|
||||
// 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) {
|
||||
// Adjust start column for offsets that are greater than the col width.
|
||||
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
|
||||
// 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 {
|
||||
num, err := ColumnNameToNumber(col)
|
||||
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
|
||||
// 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
|
||||
// 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
|
||||
// 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 {
|
||||
formatSet, err := parseFormatCommentsSet(format)
|
||||
if err != nil {
|
||||
|
|
7
crypt.go
7
crypt.go
|
@ -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
|
||||
// and package stream.
|
||||
//
|
||||
// MSAT - The master sector allocation table
|
||||
// SSAT - The short sector allocation table
|
||||
// SAT - The sector allocation table
|
||||
//
|
||||
// MSAT - The master sector allocation table
|
||||
// SSAT - The short sector allocation table
|
||||
// SAT - The sector allocation table
|
||||
func (c *cfb) Writer(encryptionInfoBuffer, encryptedPackage []byte) []byte {
|
||||
var (
|
||||
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
|
||||
// in-cell dropdown by allowing list source:
|
||||
//
|
||||
// dvRange := excelize.NewDataValidation(true)
|
||||
// dvRange.Sqref = "A7:B8"
|
||||
// dvRange.SetSqrefDropList("$E$1:$E$3")
|
||||
// f.AddDataValidation("Sheet1", dvRange)
|
||||
//
|
||||
// dvRange := excelize.NewDataValidation(true)
|
||||
// dvRange.Sqref = "A7:B8"
|
||||
// dvRange.SetSqrefDropList("$E$1:$E$3")
|
||||
// f.AddDataValidation("Sheet1", dvRange)
|
||||
func (dd *DataValidation) SetSqrefDropList(sqref string) {
|
||||
dd.Formula1 = fmt.Sprintf("<formula1>%s</formula1>", sqref)
|
||||
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
|
||||
// and custom title "error body":
|
||||
//
|
||||
// dvRange := excelize.NewDataValidation(true)
|
||||
// dvRange.Sqref = "A1:B2"
|
||||
// dvRange.SetRange(10, 20, excelize.DataValidationTypeWhole, excelize.DataValidationOperatorBetween)
|
||||
// dvRange.SetError(excelize.DataValidationErrorStyleStop, "error title", "error body")
|
||||
// err := f.AddDataValidation("Sheet1", dvRange)
|
||||
// dvRange := excelize.NewDataValidation(true)
|
||||
// dvRange.Sqref = "A1:B2"
|
||||
// dvRange.SetRange(10, 20, excelize.DataValidationTypeWhole, excelize.DataValidationOperatorBetween)
|
||||
// dvRange.SetError(excelize.DataValidationErrorStyleStop, "error title", "error body")
|
||||
// err := f.AddDataValidation("Sheet1", dvRange)
|
||||
//
|
||||
// Example 2, set data validation on Sheet1!A3:B4 with validation criteria
|
||||
// settings, and show input message when cell is selected:
|
||||
//
|
||||
// dvRange = excelize.NewDataValidation(true)
|
||||
// dvRange.Sqref = "A3:B4"
|
||||
// dvRange.SetRange(10, 20, excelize.DataValidationTypeWhole, excelize.DataValidationOperatorGreaterThan)
|
||||
// dvRange.SetInput("input title", "input body")
|
||||
// err = f.AddDataValidation("Sheet1", dvRange)
|
||||
// dvRange = excelize.NewDataValidation(true)
|
||||
// dvRange.Sqref = "A3:B4"
|
||||
// dvRange.SetRange(10, 20, excelize.DataValidationTypeWhole, excelize.DataValidationOperatorGreaterThan)
|
||||
// dvRange.SetInput("input title", "input body")
|
||||
// err = f.AddDataValidation("Sheet1", dvRange)
|
||||
//
|
||||
// Example 3, set data validation on Sheet1!A5:B6 with validation criteria
|
||||
// settings, create in-cell dropdown by allowing list source:
|
||||
//
|
||||
// dvRange = excelize.NewDataValidation(true)
|
||||
// dvRange.Sqref = "A5:B6"
|
||||
// dvRange.SetDropList([]string{"1", "2", "3"})
|
||||
// err = f.AddDataValidation("Sheet1", dvRange)
|
||||
//
|
||||
// dvRange = excelize.NewDataValidation(true)
|
||||
// dvRange.Sqref = "A5:B6"
|
||||
// dvRange.SetDropList([]string{"1", "2", "3"})
|
||||
// err = f.AddDataValidation("Sheet1", dvRange)
|
||||
func (f *File) AddDataValidation(sheet string, dv *DataValidation) error {
|
||||
ws, err := f.workSheetReader(sheet)
|
||||
if err != nil {
|
||||
|
|
170
docProps.go
170
docProps.go
|
@ -22,50 +22,49 @@ import (
|
|||
// SetAppProps provides a function to set document application properties. The
|
||||
// properties that can be set are:
|
||||
//
|
||||
// Property | Description
|
||||
// -------------------+--------------------------------------------------------------------------
|
||||
// Application | The name of the application that created this document.
|
||||
// |
|
||||
// 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
|
||||
// | this element to 'false' to enable cropping of the document thumbnail to
|
||||
// | show only sections that will fit the display.
|
||||
// |
|
||||
// DocSecurity | Security level of a document as a numeric value. Document security is
|
||||
// | defined as:
|
||||
// | 1 - Document is password protected.
|
||||
// | 2 - Document is recommended to be opened as read-only.
|
||||
// | 3 - Document is enforced to be opened as read-only.
|
||||
// | 4 - Document is locked for annotation.
|
||||
// |
|
||||
// Company | The name of a company associated with the document.
|
||||
// |
|
||||
// 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 'false' to indicate that hyperlinks are outdated.
|
||||
// |
|
||||
// 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
|
||||
// | document shall update the hyperlink relationships with the new
|
||||
// | hyperlinks specified in this part.
|
||||
// |
|
||||
// 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
|
||||
// | represent numerical values, or the document shall be considered
|
||||
// | non-conformant.
|
||||
// Property | Description
|
||||
// -------------------+--------------------------------------------------------------------------
|
||||
// Application | The name of the application that created this document.
|
||||
// |
|
||||
// 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
|
||||
// | this element to 'false' to enable cropping of the document thumbnail to
|
||||
// | show only sections that will fit the display.
|
||||
// |
|
||||
// DocSecurity | Security level of a document as a numeric value. Document security is
|
||||
// | defined as:
|
||||
// | 1 - Document is password protected.
|
||||
// | 2 - Document is recommended to be opened as read-only.
|
||||
// | 3 - Document is enforced to be opened as read-only.
|
||||
// | 4 - Document is locked for annotation.
|
||||
// |
|
||||
// Company | The name of a company associated with the document.
|
||||
// |
|
||||
// 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 'false' to indicate that hyperlinks are outdated.
|
||||
// |
|
||||
// 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
|
||||
// | document shall update the hyperlink relationships with the new
|
||||
// | hyperlinks specified in this part.
|
||||
// |
|
||||
// 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
|
||||
// | represent numerical values, or the document shall be considered
|
||||
// | non-conformant.
|
||||
//
|
||||
// For example:
|
||||
//
|
||||
// err := f.SetAppProps(&excelize.AppProperties{
|
||||
// Application: "Microsoft Excel",
|
||||
// ScaleCrop: true,
|
||||
// DocSecurity: 3,
|
||||
// Company: "Company Name",
|
||||
// LinksUpToDate: true,
|
||||
// HyperlinksChanged: true,
|
||||
// AppVersion: "16.0000",
|
||||
// })
|
||||
//
|
||||
// err := f.SetAppProps(&excelize.AppProperties{
|
||||
// Application: "Microsoft Excel",
|
||||
// ScaleCrop: true,
|
||||
// DocSecurity: 3,
|
||||
// Company: "Company Name",
|
||||
// LinksUpToDate: true,
|
||||
// HyperlinksChanged: true,
|
||||
// AppVersion: "16.0000",
|
||||
// })
|
||||
func (f *File) SetAppProps(appProperties *AppProperties) (err error) {
|
||||
var (
|
||||
app *xlsxProperties
|
||||
|
@ -122,54 +121,53 @@ func (f *File) GetAppProps() (ret *AppProperties, err error) {
|
|||
// SetDocProps provides a function to set document core properties. The
|
||||
// properties that can be set are:
|
||||
//
|
||||
// Property | Description
|
||||
// ----------------+-----------------------------------------------------------------------------
|
||||
// Title | The name given to the resource.
|
||||
// |
|
||||
// Subject | The topic of 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
|
||||
// | typically a list of terms that are not available elsewhere in the properties.
|
||||
// |
|
||||
// Description | An explanation of the content of the resource.
|
||||
// |
|
||||
// LastModifiedBy | The user who performed the last modification. The identification is
|
||||
// | environment-specific.
|
||||
// |
|
||||
// Language | The language of the intellectual content of the resource.
|
||||
// |
|
||||
// Identifier | An unambiguous reference to the resource within a given context.
|
||||
// |
|
||||
// Revision | The topic of the content of the resource.
|
||||
// |
|
||||
// ContentStatus | The status of the content. For example: Values might include "Draft",
|
||||
// | "Reviewed" and "Final"
|
||||
// |
|
||||
// Category | A categorization of the content of this package.
|
||||
// |
|
||||
// Version | The version number. This value is set by the user or by the application.
|
||||
// Property | Description
|
||||
// ----------------+-----------------------------------------------------------------------------
|
||||
// Title | The name given to the resource.
|
||||
// |
|
||||
// Subject | The topic of 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
|
||||
// | typically a list of terms that are not available elsewhere in the properties.
|
||||
// |
|
||||
// Description | An explanation of the content of the resource.
|
||||
// |
|
||||
// LastModifiedBy | The user who performed the last modification. The identification is
|
||||
// | environment-specific.
|
||||
// |
|
||||
// Language | The language of the intellectual content of the resource.
|
||||
// |
|
||||
// Identifier | An unambiguous reference to the resource within a given context.
|
||||
// |
|
||||
// Revision | The topic of the content of the resource.
|
||||
// |
|
||||
// ContentStatus | The status of the content. For example: Values might include "Draft",
|
||||
// | "Reviewed" and "Final"
|
||||
// |
|
||||
// Category | A categorization of the content of this package.
|
||||
// |
|
||||
// Version | The version number. This value is set by the user or by the application.
|
||||
//
|
||||
// For example:
|
||||
//
|
||||
// err := f.SetDocProps(&excelize.DocProperties{
|
||||
// Category: "category",
|
||||
// ContentStatus: "Draft",
|
||||
// Created: "2019-06-04T22:00:10Z",
|
||||
// Creator: "Go Excelize",
|
||||
// Description: "This file created by Go Excelize",
|
||||
// Identifier: "xlsx",
|
||||
// Keywords: "Spreadsheet",
|
||||
// LastModifiedBy: "Go Author",
|
||||
// Modified: "2019-06-04T22:00:10Z",
|
||||
// Revision: "0",
|
||||
// Subject: "Test Subject",
|
||||
// Title: "Test Title",
|
||||
// Language: "en-US",
|
||||
// Version: "1.0.0",
|
||||
// })
|
||||
//
|
||||
// err := f.SetDocProps(&excelize.DocProperties{
|
||||
// Category: "category",
|
||||
// ContentStatus: "Draft",
|
||||
// Created: "2019-06-04T22:00:10Z",
|
||||
// Creator: "Go Excelize",
|
||||
// Description: "This file created by Go Excelize",
|
||||
// Identifier: "xlsx",
|
||||
// Keywords: "Spreadsheet",
|
||||
// LastModifiedBy: "Go Author",
|
||||
// Modified: "2019-06-04T22:00:10Z",
|
||||
// Revision: "0",
|
||||
// Subject: "Test Subject",
|
||||
// Title: "Test Title",
|
||||
// Language: "en-US",
|
||||
// Version: "1.0.0",
|
||||
// })
|
||||
func (f *File) SetDocProps(docProperties *DocProperties) (err error) {
|
||||
var (
|
||||
core *decodeCoreProperties
|
||||
|
|
50
excelize.go
50
excelize.go
|
@ -92,10 +92,10 @@ type Options struct {
|
|||
// spreadsheet file struct for it. For example, open spreadsheet with
|
||||
// password protection:
|
||||
//
|
||||
// f, err := excelize.OpenFile("Book1.xlsx", excelize.Options{Password: "password"})
|
||||
// if err != nil {
|
||||
// return
|
||||
// }
|
||||
// f, err := excelize.OpenFile("Book1.xlsx", excelize.Options{Password: "password"})
|
||||
// if err != nil {
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// Close the file by Close function after opening the spreadsheet.
|
||||
func OpenFile(filename string, opt ...Options) (*File, error) {
|
||||
|
@ -403,21 +403,20 @@ func (f *File) addRels(relPath, relType, target, targetMode string) int {
|
|||
//
|
||||
// For example:
|
||||
//
|
||||
// <row r="19" spans="2:2">
|
||||
// <c r="B19">
|
||||
// <f>SUM(Sheet2!D2,Sheet2!D11)</f>
|
||||
// <v>100</v>
|
||||
// </c>
|
||||
// </row>
|
||||
// <row r="19" spans="2:2">
|
||||
// <c r="B19">
|
||||
// <f>SUM(Sheet2!D2,Sheet2!D11)</f>
|
||||
// <v>100</v>
|
||||
// </c>
|
||||
// </row>
|
||||
//
|
||||
// to
|
||||
//
|
||||
// <row r="19" spans="2:2">
|
||||
// <c r="B19">
|
||||
// <f>SUM(Sheet2!D2,Sheet2!D11)</f>
|
||||
// </c>
|
||||
// </row>
|
||||
//
|
||||
// <row r="19" spans="2:2">
|
||||
// <c r="B19">
|
||||
// <f>SUM(Sheet2!D2,Sheet2!D11)</f>
|
||||
// </c>
|
||||
// </row>
|
||||
func (f *File) UpdateLinkedValue() error {
|
||||
wb := f.workbookReader()
|
||||
// recalculate formulas
|
||||
|
@ -445,16 +444,15 @@ func (f *File) UpdateLinkedValue() error {
|
|||
// AddVBAProject provides the method to add vbaProject.bin file which contains
|
||||
// functions and/or macros. The file extension should be .xlsm. For example:
|
||||
//
|
||||
// if err := f.SetSheetPrOptions("Sheet1", excelize.CodeName("Sheet1")); err != nil {
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
// if err := f.AddVBAProject("vbaProject.bin"); err != nil {
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
// if err := f.SaveAs("macros.xlsm"); err != nil {
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
//
|
||||
// if err := f.SetSheetPrOptions("Sheet1", excelize.CodeName("Sheet1")); err != nil {
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
// if err := f.AddVBAProject("vbaProject.bin"); err != nil {
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
// if err := f.SaveAs("macros.xlsm"); err != nil {
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
func (f *File) AddVBAProject(bin string) error {
|
||||
var err error
|
||||
// Check vbaProject.bin exists first.
|
||||
|
|
3
file.go
3
file.go
|
@ -24,8 +24,7 @@ import (
|
|||
// NewFile provides a function to create new file by default template.
|
||||
// For example:
|
||||
//
|
||||
// f := NewFile()
|
||||
//
|
||||
// f := NewFile()
|
||||
func NewFile() *File {
|
||||
f := newFile()
|
||||
f.Pkg.Store("_rels/.rels", []byte(xml.Header+templateRels))
|
||||
|
|
21
lib.go
21
lib.go
|
@ -148,8 +148,7 @@ func readFile(file *zip.File) ([]byte, error) {
|
|||
//
|
||||
// Example:
|
||||
//
|
||||
// excelize.SplitCellName("AK74") // return "AK", 74, nil
|
||||
//
|
||||
// excelize.SplitCellName("AK74") // return "AK", 74, nil
|
||||
func SplitCellName(cell string) (string, int, error) {
|
||||
alpha := func(r rune) bool {
|
||||
return ('A' <= r && r <= 'Z') || ('a' <= r && r <= 'z') || (r == 36)
|
||||
|
@ -192,8 +191,7 @@ func JoinCellName(col string, row int) (string, error) {
|
|||
//
|
||||
// Example:
|
||||
//
|
||||
// excelize.ColumnNameToNumber("AK") // returns 37, nil
|
||||
//
|
||||
// excelize.ColumnNameToNumber("AK") // returns 37, nil
|
||||
func ColumnNameToNumber(name string) (int, error) {
|
||||
if len(name) == 0 {
|
||||
return -1, newInvalidColumnNameError(name)
|
||||
|
@ -222,8 +220,7 @@ func ColumnNameToNumber(name string) (int, error) {
|
|||
//
|
||||
// Example:
|
||||
//
|
||||
// excelize.ColumnNumberToName(37) // returns "AK", nil
|
||||
//
|
||||
// excelize.ColumnNumberToName(37) // returns "AK", nil
|
||||
func ColumnNumberToName(num int) (string, error) {
|
||||
if num < MinColumns || num > MaxColumns {
|
||||
return "", ErrColumnNumber
|
||||
|
@ -241,9 +238,8 @@ func ColumnNumberToName(num int) (string, error) {
|
|||
//
|
||||
// Example:
|
||||
//
|
||||
// excelize.CellNameToCoordinates("A1") // returns 1, 1, nil
|
||||
// excelize.CellNameToCoordinates("Z3") // returns 26, 3, nil
|
||||
//
|
||||
// excelize.CellNameToCoordinates("A1") // returns 1, 1, nil
|
||||
// excelize.CellNameToCoordinates("Z3") // returns 26, 3, nil
|
||||
func CellNameToCoordinates(cell string) (int, int, error) {
|
||||
colName, row, err := SplitCellName(cell)
|
||||
if err != nil {
|
||||
|
@ -261,9 +257,8 @@ func CellNameToCoordinates(cell string) (int, int, error) {
|
|||
//
|
||||
// Example:
|
||||
//
|
||||
// excelize.CoordinatesToCellName(1, 1) // returns "A1", nil
|
||||
// excelize.CoordinatesToCellName(1, 1, true) // returns "$A$1", nil
|
||||
//
|
||||
// excelize.CoordinatesToCellName(1, 1) // returns "A1", nil
|
||||
// excelize.CoordinatesToCellName(1, 1, true) // returns "$A$1", nil
|
||||
func CoordinatesToCellName(col, row int, abs ...bool) (string, error) {
|
||||
if col < 1 || row < 1 {
|
||||
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 {
|
||||
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
|
||||
|
|
27
merge.go
27
merge.go
|
@ -27,25 +27,24 @@ func (mc *xlsxMergeCell) Rect() ([]int, error) {
|
|||
// discards the other values. For example create a merged cell of D3:E9 on
|
||||
// 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,
|
||||
// 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)
|
||||
// A8(x3,y4) D8(x2,y4)
|
||||
//
|
||||
// B1(x1,y1) D1(x2,y1)
|
||||
// +------------------------+
|
||||
// | |
|
||||
// A4(x3,y3) | C4(x4,y3) |
|
||||
// +------------------------+ |
|
||||
// | | | |
|
||||
// | |B5(x1,y2) | D5(x2,y2)|
|
||||
// | +------------------------+
|
||||
// | |
|
||||
// |A8(x3,y4) C8(x4,y4)|
|
||||
// +------------------------+
|
||||
//
|
||||
// B1(x1,y1) D1(x2,y1)
|
||||
// +------------------------+
|
||||
// | |
|
||||
// A4(x3,y3) | C4(x4,y3) |
|
||||
// +------------------------+ |
|
||||
// | | | |
|
||||
// | |B5(x1,y2) | D5(x2,y2)|
|
||||
// | +------------------------+
|
||||
// | |
|
||||
// |A8(x3,y4) C8(x4,y4)|
|
||||
// +------------------------+
|
||||
func (f *File) MergeCell(sheet, hCell, vCell string) error {
|
||||
rect, err := areaRefToCoordinates(hCell + ":" + vCell)
|
||||
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.
|
||||
// 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.
|
||||
func (f *File) UnmergeCell(sheet string, hCell, vCell string) error {
|
||||
|
|
129
picture.go
129
picture.go
|
@ -42,34 +42,34 @@ func parseFormatPictureSet(formatSet string) (*formatPicture, error) {
|
|||
// format set (such as offset, scale, aspect ratio setting and print settings)
|
||||
// and file path. For example:
|
||||
//
|
||||
// package main
|
||||
// package main
|
||||
//
|
||||
// import (
|
||||
// _ "image/gif"
|
||||
// _ "image/jpeg"
|
||||
// _ "image/png"
|
||||
// import (
|
||||
// _ "image/gif"
|
||||
// _ "image/jpeg"
|
||||
// _ "image/png"
|
||||
//
|
||||
// "github.com/xuri/excelize/v2"
|
||||
// )
|
||||
// "github.com/xuri/excelize/v2"
|
||||
// )
|
||||
//
|
||||
// func main() {
|
||||
// f := excelize.NewFile()
|
||||
// // Insert a picture.
|
||||
// if err := f.AddPicture("Sheet1", "A2", "image.jpg", ""); err != nil {
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
// // 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 {
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
// // 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 {
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
// if err := f.SaveAs("Book1.xlsx"); err != nil {
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
// }
|
||||
// func main() {
|
||||
// f := excelize.NewFile()
|
||||
// // Insert a picture.
|
||||
// if err := f.AddPicture("Sheet1", "A2", "image.jpg", ""); err != nil {
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
// // 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 {
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
// // 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 {
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
// if err := f.SaveAs("Book1.xlsx"); err != nil {
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// The optional parameter "autofit" specifies if you make image size auto-fits the
|
||||
// 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 default value of that is 1.0 which presents 100%.
|
||||
//
|
||||
func (f *File) AddPicture(sheet, cell, picture, format string) error {
|
||||
var err error
|
||||
// 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
|
||||
// settings), file base name, extension name and file bytes. For example:
|
||||
//
|
||||
// package main
|
||||
// package main
|
||||
//
|
||||
// import (
|
||||
// "fmt"
|
||||
// _ "image/jpeg"
|
||||
// "io/ioutil"
|
||||
// import (
|
||||
// "fmt"
|
||||
// _ "image/jpeg"
|
||||
// "io/ioutil"
|
||||
//
|
||||
// "github.com/xuri/excelize/v2"
|
||||
// )
|
||||
// "github.com/xuri/excelize/v2"
|
||||
// )
|
||||
//
|
||||
// func main() {
|
||||
// f := excelize.NewFile()
|
||||
//
|
||||
// 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 main() {
|
||||
// f := excelize.NewFile()
|
||||
//
|
||||
// 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 {
|
||||
var drawingHyperlinkRID int
|
||||
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
|
||||
// types. For example:
|
||||
//
|
||||
// f, err := excelize.OpenFile("Book1.xlsx")
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// return
|
||||
// }
|
||||
// defer func() {
|
||||
// if err := f.Close(); err != nil {
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
// }()
|
||||
// file, raw, err := f.GetPicture("Sheet1", "A2")
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// return
|
||||
// }
|
||||
// if err := ioutil.WriteFile(file, raw, 0644); err != nil {
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
//
|
||||
// f, err := excelize.OpenFile("Book1.xlsx")
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// return
|
||||
// }
|
||||
// defer func() {
|
||||
// if err := f.Close(); err != nil {
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
// }()
|
||||
// file, raw, err := f.GetPicture("Sheet1", "A2")
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// return
|
||||
// }
|
||||
// if err := ioutil.WriteFile(file, raw, 0644); err != nil {
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
func (f *File) GetPicture(sheet, cell string) (string, []byte, error) {
|
||||
col, row, err := CellNameToCoordinates(cell)
|
||||
if err != nil {
|
||||
|
|
112
pivotTable.go
112
pivotTable.go
|
@ -22,10 +22,9 @@ import (
|
|||
//
|
||||
// PivotTableStyleName: The built-in pivot table style names
|
||||
//
|
||||
// PivotStyleLight1 - PivotStyleLight28
|
||||
// PivotStyleMedium1 - PivotStyleMedium28
|
||||
// PivotStyleDark1 - PivotStyleDark28
|
||||
//
|
||||
// PivotStyleLight1 - PivotStyleLight28
|
||||
// PivotStyleMedium1 - PivotStyleMedium28
|
||||
// PivotStyleDark1 - PivotStyleDark28
|
||||
type PivotTableOption struct {
|
||||
pivotTableSheetName string
|
||||
DataRange string
|
||||
|
@ -55,17 +54,17 @@ type PivotTableOption struct {
|
|||
// field. The default value is sum. The possible values for this attribute
|
||||
// are:
|
||||
//
|
||||
// Average
|
||||
// Count
|
||||
// CountNums
|
||||
// Max
|
||||
// Min
|
||||
// Product
|
||||
// StdDev
|
||||
// StdDevp
|
||||
// Sum
|
||||
// Var
|
||||
// Varp
|
||||
// Average
|
||||
// Count
|
||||
// CountNums
|
||||
// Max
|
||||
// Min
|
||||
// Product
|
||||
// StdDev
|
||||
// StdDevp
|
||||
// Sum
|
||||
// Var
|
||||
// Varp
|
||||
//
|
||||
// Name specifies the name of the data field. Maximum 255 characters
|
||||
// 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
|
||||
// region Sheet1!$A$1:$E$31 as the data source, summarize by sum for sales:
|
||||
//
|
||||
// package main
|
||||
// package main
|
||||
//
|
||||
// import (
|
||||
// "fmt"
|
||||
// "math/rand"
|
||||
// import (
|
||||
// "fmt"
|
||||
// "math/rand"
|
||||
//
|
||||
// "github.com/xuri/excelize/v2"
|
||||
// )
|
||||
//
|
||||
// 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)
|
||||
// }
|
||||
// }
|
||||
// "github.com/xuri/excelize/v2"
|
||||
// )
|
||||
//
|
||||
// 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 {
|
||||
// parameter validation
|
||||
_, pivotTableSheetPath, err := f.parseFormatPivotTableSet(opt)
|
||||
|
|
121
rows.go
121
rows.go
|
@ -37,18 +37,17 @@ import (
|
|||
// For example, get and traverse the value of all cells by rows on a worksheet
|
||||
// named 'Sheet1':
|
||||
//
|
||||
// rows, err := f.GetRows("Sheet1")
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// return
|
||||
// }
|
||||
// for _, row := range rows {
|
||||
// for _, colCell := range row {
|
||||
// fmt.Print(colCell, "\t")
|
||||
// }
|
||||
// fmt.Println()
|
||||
// }
|
||||
//
|
||||
// rows, err := f.GetRows("Sheet1")
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// return
|
||||
// }
|
||||
// for _, row := range rows {
|
||||
// for _, colCell := range row {
|
||||
// fmt.Print(colCell, "\t")
|
||||
// }
|
||||
// fmt.Println()
|
||||
// }
|
||||
func (f *File) GetRows(sheet string, opts ...Options) ([][]string, error) {
|
||||
rows, err := f.Rows(sheet)
|
||||
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
|
||||
// worksheet with a large data. For example:
|
||||
//
|
||||
// rows, err := f.Rows("Sheet1")
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// return
|
||||
// }
|
||||
// for rows.Next() {
|
||||
// row, err := rows.Columns()
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
// for _, colCell := range row {
|
||||
// fmt.Print(colCell, "\t")
|
||||
// }
|
||||
// fmt.Println()
|
||||
// }
|
||||
// if err = rows.Close(); err != nil {
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
//
|
||||
// rows, err := f.Rows("Sheet1")
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// return
|
||||
// }
|
||||
// for rows.Next() {
|
||||
// row, err := rows.Columns()
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
// for _, colCell := range row {
|
||||
// fmt.Print(colCell, "\t")
|
||||
// }
|
||||
// fmt.Println()
|
||||
// }
|
||||
// if err = rows.Close(); err != nil {
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
func (f *File) Rows(sheet string) (*Rows, error) {
|
||||
name, ok := f.getSheetXMLPath(sheet)
|
||||
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
|
||||
// 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 {
|
||||
if row < 1 {
|
||||
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
|
||||
// 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) {
|
||||
if row < 1 {
|
||||
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
|
||||
// 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 {
|
||||
if row < 1 {
|
||||
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
|
||||
// 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) {
|
||||
if row < 1 {
|
||||
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
|
||||
// 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 {
|
||||
if row < 1 {
|
||||
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
|
||||
// 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) {
|
||||
if row < 1 {
|
||||
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
|
||||
// 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
|
||||
// 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
|
||||
// Sheet1:
|
||||
//
|
||||
// err := f.InsertRow("Sheet1", 3)
|
||||
// err := f.InsertRow("Sheet1", 3)
|
||||
//
|
||||
// Use this method with caution, which will affect changes in references such
|
||||
// as formulas, charts, and so on. If there is any referenced value of the
|
||||
|
@ -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
|
||||
//
|
||||
// err := f.DuplicateRow("Sheet1", 2)
|
||||
// err := f.DuplicateRow("Sheet1", 2)
|
||||
//
|
||||
// Use this method with caution, which will affect changes in references such
|
||||
// as formulas, charts, and so on. If there is any referenced value of the
|
||||
|
@ -661,7 +653,7 @@ func (f *File) DuplicateRow(sheet string, row int) error {
|
|||
// DuplicateRowTo inserts a copy of specified row by it Excel number
|
||||
// to specified row position moving down exists rows after target position
|
||||
//
|
||||
// err := f.DuplicateRowTo("Sheet1", 2, 7)
|
||||
// err := f.DuplicateRowTo("Sheet1", 2, 7)
|
||||
//
|
||||
// Use this method with caution, which will affect changes in references such
|
||||
// as formulas, charts, and so on. If there is any referenced value of the
|
||||
|
@ -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
|
||||
// rows and make that is continuous in a worksheet of XML. For example:
|
||||
//
|
||||
// <row r="15" spans="1:22" x14ac:dyDescent="0.2">
|
||||
// <c r="A15" s="2" />
|
||||
// <c r="B15" s="2" />
|
||||
// <c r="F15" s="1" />
|
||||
// <c r="G15" s="1" />
|
||||
// </row>
|
||||
// <row r="15" spans="1:22" x14ac:dyDescent="0.2">
|
||||
// <c r="A15" s="2" />
|
||||
// <c r="B15" s="2" />
|
||||
// <c r="F15" s="1" />
|
||||
// <c r="G15" s="1" />
|
||||
// </row>
|
||||
//
|
||||
// in this case, we should to change it to
|
||||
//
|
||||
// <row r="15" spans="1:22" x14ac:dyDescent="0.2">
|
||||
// <c r="A15" s="2" />
|
||||
// <c r="B15" s="2" />
|
||||
// <c r="C15" s="2" />
|
||||
// <c r="D15" s="2" />
|
||||
// <c r="E15" s="2" />
|
||||
// <c r="F15" s="1" />
|
||||
// <c r="G15" s="1" />
|
||||
// </row>
|
||||
// <row r="15" spans="1:22" x14ac:dyDescent="0.2">
|
||||
// <c r="A15" s="2" />
|
||||
// <c r="B15" s="2" />
|
||||
// <c r="C15" s="2" />
|
||||
// <c r="D15" s="2" />
|
||||
// <c r="E15" s="2" />
|
||||
// <c r="F15" s="1" />
|
||||
// <c r="G15" s="1" />
|
||||
// </row>
|
||||
//
|
||||
// Noteice: this method could be very slow for large spreadsheets (more than
|
||||
// 3000 rows one sheet).
|
||||
|
@ -843,12 +835,11 @@ func checkRow(ws *xlsxWorksheet) error {
|
|||
//
|
||||
// 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:
|
||||
//
|
||||
// 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 {
|
||||
if end < start {
|
||||
start, end = end, start
|
||||
|
|
465
shape.go
465
shape.go
|
@ -39,245 +39,244 @@ func parseFormatShapeSet(formatSet string) (*formatShape, error) {
|
|||
// print settings) and properties set. For example, add text box (rect shape)
|
||||
// in Sheet1:
|
||||
//
|
||||
// err := f.AddShape("Sheet1", "G6", `{
|
||||
// "type": "rect",
|
||||
// "color":
|
||||
// {
|
||||
// "line": "#4286F4",
|
||||
// "fill": "#8eb9ff"
|
||||
// },
|
||||
// "paragraph": [
|
||||
// {
|
||||
// "text": "Rectangle Shape",
|
||||
// "font":
|
||||
// {
|
||||
// "bold": true,
|
||||
// "italic": true,
|
||||
// "family": "Times New Roman",
|
||||
// "size": 36,
|
||||
// "color": "#777777",
|
||||
// "underline": "sng"
|
||||
// }
|
||||
// }],
|
||||
// "width": 180,
|
||||
// "height": 90,
|
||||
// "line":
|
||||
// {
|
||||
// "width": 1.2
|
||||
// }
|
||||
// }`)
|
||||
// err := f.AddShape("Sheet1", "G6", `{
|
||||
// "type": "rect",
|
||||
// "color":
|
||||
// {
|
||||
// "line": "#4286F4",
|
||||
// "fill": "#8eb9ff"
|
||||
// },
|
||||
// "paragraph": [
|
||||
// {
|
||||
// "text": "Rectangle Shape",
|
||||
// "font":
|
||||
// {
|
||||
// "bold": true,
|
||||
// "italic": true,
|
||||
// "family": "Times New Roman",
|
||||
// "size": 36,
|
||||
// "color": "#777777",
|
||||
// "underline": "sng"
|
||||
// }
|
||||
// }],
|
||||
// "width": 180,
|
||||
// "height": 90,
|
||||
// "line":
|
||||
// {
|
||||
// "width": 1.2
|
||||
// }
|
||||
// }`)
|
||||
//
|
||||
// The following shows the type of shape supported by excelize:
|
||||
//
|
||||
// accentBorderCallout1 (Callout 1 with Border and Accent Shape)
|
||||
// accentBorderCallout2 (Callout 2 with Border and Accent Shape)
|
||||
// accentBorderCallout3 (Callout 3 with Border and Accent Shape)
|
||||
// accentCallout1 (Callout 1 Shape)
|
||||
// accentCallout2 (Callout 2 Shape)
|
||||
// accentCallout3 (Callout 3 Shape)
|
||||
// actionButtonBackPrevious (Back or Previous Button Shape)
|
||||
// actionButtonBeginning (Beginning Button Shape)
|
||||
// actionButtonBlank (Blank Button Shape)
|
||||
// actionButtonDocument (Document Button Shape)
|
||||
// actionButtonEnd (End Button Shape)
|
||||
// actionButtonForwardNext (Forward or Next Button Shape)
|
||||
// actionButtonHelp (Help Button Shape)
|
||||
// actionButtonHome (Home Button Shape)
|
||||
// actionButtonInformation (Information Button Shape)
|
||||
// actionButtonMovie (Movie Button Shape)
|
||||
// actionButtonReturn (Return Button Shape)
|
||||
// actionButtonSound (Sound Button Shape)
|
||||
// arc (Curved Arc Shape)
|
||||
// bentArrow (Bent Arrow Shape)
|
||||
// bentConnector2 (Bent Connector 2 Shape)
|
||||
// bentConnector3 (Bent Connector 3 Shape)
|
||||
// bentConnector4 (Bent Connector 4 Shape)
|
||||
// bentConnector5 (Bent Connector 5 Shape)
|
||||
// bentUpArrow (Bent Up Arrow Shape)
|
||||
// bevel (Bevel Shape)
|
||||
// blockArc (Block Arc Shape)
|
||||
// borderCallout1 (Callout 1 with Border Shape)
|
||||
// borderCallout2 (Callout 2 with Border Shape)
|
||||
// borderCallout3 (Callout 3 with Border Shape)
|
||||
// bracePair (Brace Pair Shape)
|
||||
// bracketPair (Bracket Pair Shape)
|
||||
// callout1 (Callout 1 Shape)
|
||||
// callout2 (Callout 2 Shape)
|
||||
// callout3 (Callout 3 Shape)
|
||||
// can (Can Shape)
|
||||
// chartPlus (Chart Plus Shape)
|
||||
// chartStar (Chart Star Shape)
|
||||
// chartX (Chart X Shape)
|
||||
// chevron (Chevron Shape)
|
||||
// chord (Chord Shape)
|
||||
// circularArrow (Circular Arrow Shape)
|
||||
// cloud (Cloud Shape)
|
||||
// cloudCallout (Callout Cloud Shape)
|
||||
// corner (Corner Shape)
|
||||
// cornerTabs (Corner Tabs Shape)
|
||||
// cube (Cube Shape)
|
||||
// curvedConnector2 (Curved Connector 2 Shape)
|
||||
// curvedConnector3 (Curved Connector 3 Shape)
|
||||
// curvedConnector4 (Curved Connector 4 Shape)
|
||||
// curvedConnector5 (Curved Connector 5 Shape)
|
||||
// curvedDownArrow (Curved Down Arrow Shape)
|
||||
// curvedLeftArrow (Curved Left Arrow Shape)
|
||||
// curvedRightArrow (Curved Right Arrow Shape)
|
||||
// curvedUpArrow (Curved Up Arrow Shape)
|
||||
// decagon (Decagon Shape)
|
||||
// diagStripe (Diagonal Stripe Shape)
|
||||
// diamond (Diamond Shape)
|
||||
// dodecagon (Dodecagon Shape)
|
||||
// donut (Donut Shape)
|
||||
// doubleWave (Double Wave Shape)
|
||||
// downArrow (Down Arrow Shape)
|
||||
// downArrowCallout (Callout Down Arrow Shape)
|
||||
// ellipse (Ellipse Shape)
|
||||
// ellipseRibbon (Ellipse Ribbon Shape)
|
||||
// ellipseRibbon2 (Ellipse Ribbon 2 Shape)
|
||||
// flowChartAlternateProcess (Alternate Process Flow Shape)
|
||||
// flowChartCollate (Collate Flow Shape)
|
||||
// flowChartConnector (Connector Flow Shape)
|
||||
// flowChartDecision (Decision Flow Shape)
|
||||
// flowChartDelay (Delay Flow Shape)
|
||||
// flowChartDisplay (Display Flow Shape)
|
||||
// flowChartDocument (Document Flow Shape)
|
||||
// flowChartExtract (Extract Flow Shape)
|
||||
// flowChartInputOutput (Input Output Flow Shape)
|
||||
// flowChartInternalStorage (Internal Storage Flow Shape)
|
||||
// flowChartMagneticDisk (Magnetic Disk Flow Shape)
|
||||
// flowChartMagneticDrum (Magnetic Drum Flow Shape)
|
||||
// flowChartMagneticTape (Magnetic Tape Flow Shape)
|
||||
// flowChartManualInput (Manual Input Flow Shape)
|
||||
// flowChartManualOperation (Manual Operation Flow Shape)
|
||||
// flowChartMerge (Merge Flow Shape)
|
||||
// flowChartMultidocument (Multi-Document Flow Shape)
|
||||
// flowChartOfflineStorage (Offline Storage Flow Shape)
|
||||
// flowChartOffpageConnector (Off-Page Connector Flow Shape)
|
||||
// flowChartOnlineStorage (Online Storage Flow Shape)
|
||||
// flowChartOr (Or Flow Shape)
|
||||
// flowChartPredefinedProcess (Predefined Process Flow Shape)
|
||||
// flowChartPreparation (Preparation Flow Shape)
|
||||
// flowChartProcess (Process Flow Shape)
|
||||
// flowChartPunchedCard (Punched Card Flow Shape)
|
||||
// flowChartPunchedTape (Punched Tape Flow Shape)
|
||||
// flowChartSort (Sort Flow Shape)
|
||||
// flowChartSummingJunction (Summing Junction Flow Shape)
|
||||
// flowChartTerminator (Terminator Flow Shape)
|
||||
// foldedCorner (Folded Corner Shape)
|
||||
// frame (Frame Shape)
|
||||
// funnel (Funnel Shape)
|
||||
// gear6 (Gear 6 Shape)
|
||||
// gear9 (Gear 9 Shape)
|
||||
// halfFrame (Half Frame Shape)
|
||||
// heart (Heart Shape)
|
||||
// heptagon (Heptagon Shape)
|
||||
// hexagon (Hexagon Shape)
|
||||
// homePlate (Home Plate Shape)
|
||||
// horizontalScroll (Horizontal Scroll Shape)
|
||||
// irregularSeal1 (Irregular Seal 1 Shape)
|
||||
// irregularSeal2 (Irregular Seal 2 Shape)
|
||||
// leftArrow (Left Arrow Shape)
|
||||
// leftArrowCallout (Callout Left Arrow Shape)
|
||||
// leftBrace (Left Brace Shape)
|
||||
// leftBracket (Left Bracket Shape)
|
||||
// leftCircularArrow (Left Circular Arrow Shape)
|
||||
// leftRightArrow (Left Right Arrow Shape)
|
||||
// leftRightArrowCallout (Callout Left Right Arrow Shape)
|
||||
// leftRightCircularArrow (Left Right Circular Arrow Shape)
|
||||
// leftRightRibbon (Left Right Ribbon Shape)
|
||||
// leftRightUpArrow (Left Right Up Arrow Shape)
|
||||
// leftUpArrow (Left Up Arrow Shape)
|
||||
// lightningBolt (Lightning Bolt Shape)
|
||||
// line (Line Shape)
|
||||
// lineInv (Line Inverse Shape)
|
||||
// mathDivide (Divide Math Shape)
|
||||
// mathEqual (Equal Math Shape)
|
||||
// mathMinus (Minus Math Shape)
|
||||
// mathMultiply (Multiply Math Shape)
|
||||
// mathNotEqual (Not Equal Math Shape)
|
||||
// mathPlus (Plus Math Shape)
|
||||
// moon (Moon Shape)
|
||||
// nonIsoscelesTrapezoid (Non-Isosceles Trapezoid Shape)
|
||||
// noSmoking (No Smoking Shape)
|
||||
// notchedRightArrow (Notched Right Arrow Shape)
|
||||
// octagon (Octagon Shape)
|
||||
// parallelogram (Parallelogram Shape)
|
||||
// pentagon (Pentagon Shape)
|
||||
// pie (Pie Shape)
|
||||
// pieWedge (Pie Wedge Shape)
|
||||
// plaque (Plaque Shape)
|
||||
// plaqueTabs (Plaque Tabs Shape)
|
||||
// plus (Plus Shape)
|
||||
// quadArrow (Quad-Arrow Shape)
|
||||
// quadArrowCallout (Callout Quad-Arrow Shape)
|
||||
// rect (Rectangle Shape)
|
||||
// ribbon (Ribbon Shape)
|
||||
// ribbon2 (Ribbon 2 Shape)
|
||||
// rightArrow (Right Arrow Shape)
|
||||
// rightArrowCallout (Callout Right Arrow Shape)
|
||||
// rightBrace (Right Brace Shape)
|
||||
// rightBracket (Right Bracket Shape)
|
||||
// round1Rect (One Round Corner Rectangle Shape)
|
||||
// round2DiagRect (Two Diagonal Round Corner Rectangle Shape)
|
||||
// round2SameRect (Two Same-side Round Corner Rectangle Shape)
|
||||
// roundRect (Round Corner Rectangle Shape)
|
||||
// rtTriangle (Right Triangle Shape)
|
||||
// smileyFace (Smiley Face Shape)
|
||||
// snip1Rect (One Snip Corner Rectangle Shape)
|
||||
// snip2DiagRect (Two Diagonal Snip Corner Rectangle Shape)
|
||||
// snip2SameRect (Two Same-side Snip Corner Rectangle Shape)
|
||||
// snipRoundRect (One Snip One Round Corner Rectangle Shape)
|
||||
// squareTabs (Square Tabs Shape)
|
||||
// star10 (Ten Pointed Star Shape)
|
||||
// star12 (Twelve Pointed Star Shape)
|
||||
// star16 (Sixteen Pointed Star Shape)
|
||||
// star24 (Twenty Four Pointed Star Shape)
|
||||
// star32 (Thirty Two Pointed Star Shape)
|
||||
// star4 (Four Pointed Star Shape)
|
||||
// star5 (Five Pointed Star Shape)
|
||||
// star6 (Six Pointed Star Shape)
|
||||
// star7 (Seven Pointed Star Shape)
|
||||
// star8 (Eight Pointed Star Shape)
|
||||
// straightConnector1 (Straight Connector 1 Shape)
|
||||
// stripedRightArrow (Striped Right Arrow Shape)
|
||||
// sun (Sun Shape)
|
||||
// swooshArrow (Swoosh Arrow Shape)
|
||||
// teardrop (Teardrop Shape)
|
||||
// trapezoid (Trapezoid Shape)
|
||||
// triangle (Triangle Shape)
|
||||
// upArrow (Up Arrow Shape)
|
||||
// upArrowCallout (Callout Up Arrow Shape)
|
||||
// upDownArrow (Up Down Arrow Shape)
|
||||
// upDownArrowCallout (Callout Up Down Arrow Shape)
|
||||
// uturnArrow (U-Turn Arrow Shape)
|
||||
// verticalScroll (Vertical Scroll Shape)
|
||||
// wave (Wave Shape)
|
||||
// wedgeEllipseCallout (Callout Wedge Ellipse Shape)
|
||||
// wedgeRectCallout (Callout Wedge Rectangle Shape)
|
||||
// wedgeRoundRectCallout (Callout Wedge Round Rectangle Shape)
|
||||
// accentBorderCallout1 (Callout 1 with Border and Accent Shape)
|
||||
// accentBorderCallout2 (Callout 2 with Border and Accent Shape)
|
||||
// accentBorderCallout3 (Callout 3 with Border and Accent Shape)
|
||||
// accentCallout1 (Callout 1 Shape)
|
||||
// accentCallout2 (Callout 2 Shape)
|
||||
// accentCallout3 (Callout 3 Shape)
|
||||
// actionButtonBackPrevious (Back or Previous Button Shape)
|
||||
// actionButtonBeginning (Beginning Button Shape)
|
||||
// actionButtonBlank (Blank Button Shape)
|
||||
// actionButtonDocument (Document Button Shape)
|
||||
// actionButtonEnd (End Button Shape)
|
||||
// actionButtonForwardNext (Forward or Next Button Shape)
|
||||
// actionButtonHelp (Help Button Shape)
|
||||
// actionButtonHome (Home Button Shape)
|
||||
// actionButtonInformation (Information Button Shape)
|
||||
// actionButtonMovie (Movie Button Shape)
|
||||
// actionButtonReturn (Return Button Shape)
|
||||
// actionButtonSound (Sound Button Shape)
|
||||
// arc (Curved Arc Shape)
|
||||
// bentArrow (Bent Arrow Shape)
|
||||
// bentConnector2 (Bent Connector 2 Shape)
|
||||
// bentConnector3 (Bent Connector 3 Shape)
|
||||
// bentConnector4 (Bent Connector 4 Shape)
|
||||
// bentConnector5 (Bent Connector 5 Shape)
|
||||
// bentUpArrow (Bent Up Arrow Shape)
|
||||
// bevel (Bevel Shape)
|
||||
// blockArc (Block Arc Shape)
|
||||
// borderCallout1 (Callout 1 with Border Shape)
|
||||
// borderCallout2 (Callout 2 with Border Shape)
|
||||
// borderCallout3 (Callout 3 with Border Shape)
|
||||
// bracePair (Brace Pair Shape)
|
||||
// bracketPair (Bracket Pair Shape)
|
||||
// callout1 (Callout 1 Shape)
|
||||
// callout2 (Callout 2 Shape)
|
||||
// callout3 (Callout 3 Shape)
|
||||
// can (Can Shape)
|
||||
// chartPlus (Chart Plus Shape)
|
||||
// chartStar (Chart Star Shape)
|
||||
// chartX (Chart X Shape)
|
||||
// chevron (Chevron Shape)
|
||||
// chord (Chord Shape)
|
||||
// circularArrow (Circular Arrow Shape)
|
||||
// cloud (Cloud Shape)
|
||||
// cloudCallout (Callout Cloud Shape)
|
||||
// corner (Corner Shape)
|
||||
// cornerTabs (Corner Tabs Shape)
|
||||
// cube (Cube Shape)
|
||||
// curvedConnector2 (Curved Connector 2 Shape)
|
||||
// curvedConnector3 (Curved Connector 3 Shape)
|
||||
// curvedConnector4 (Curved Connector 4 Shape)
|
||||
// curvedConnector5 (Curved Connector 5 Shape)
|
||||
// curvedDownArrow (Curved Down Arrow Shape)
|
||||
// curvedLeftArrow (Curved Left Arrow Shape)
|
||||
// curvedRightArrow (Curved Right Arrow Shape)
|
||||
// curvedUpArrow (Curved Up Arrow Shape)
|
||||
// decagon (Decagon Shape)
|
||||
// diagStripe (Diagonal Stripe Shape)
|
||||
// diamond (Diamond Shape)
|
||||
// dodecagon (Dodecagon Shape)
|
||||
// donut (Donut Shape)
|
||||
// doubleWave (Double Wave Shape)
|
||||
// downArrow (Down Arrow Shape)
|
||||
// downArrowCallout (Callout Down Arrow Shape)
|
||||
// ellipse (Ellipse Shape)
|
||||
// ellipseRibbon (Ellipse Ribbon Shape)
|
||||
// ellipseRibbon2 (Ellipse Ribbon 2 Shape)
|
||||
// flowChartAlternateProcess (Alternate Process Flow Shape)
|
||||
// flowChartCollate (Collate Flow Shape)
|
||||
// flowChartConnector (Connector Flow Shape)
|
||||
// flowChartDecision (Decision Flow Shape)
|
||||
// flowChartDelay (Delay Flow Shape)
|
||||
// flowChartDisplay (Display Flow Shape)
|
||||
// flowChartDocument (Document Flow Shape)
|
||||
// flowChartExtract (Extract Flow Shape)
|
||||
// flowChartInputOutput (Input Output Flow Shape)
|
||||
// flowChartInternalStorage (Internal Storage Flow Shape)
|
||||
// flowChartMagneticDisk (Magnetic Disk Flow Shape)
|
||||
// flowChartMagneticDrum (Magnetic Drum Flow Shape)
|
||||
// flowChartMagneticTape (Magnetic Tape Flow Shape)
|
||||
// flowChartManualInput (Manual Input Flow Shape)
|
||||
// flowChartManualOperation (Manual Operation Flow Shape)
|
||||
// flowChartMerge (Merge Flow Shape)
|
||||
// flowChartMultidocument (Multi-Document Flow Shape)
|
||||
// flowChartOfflineStorage (Offline Storage Flow Shape)
|
||||
// flowChartOffpageConnector (Off-Page Connector Flow Shape)
|
||||
// flowChartOnlineStorage (Online Storage Flow Shape)
|
||||
// flowChartOr (Or Flow Shape)
|
||||
// flowChartPredefinedProcess (Predefined Process Flow Shape)
|
||||
// flowChartPreparation (Preparation Flow Shape)
|
||||
// flowChartProcess (Process Flow Shape)
|
||||
// flowChartPunchedCard (Punched Card Flow Shape)
|
||||
// flowChartPunchedTape (Punched Tape Flow Shape)
|
||||
// flowChartSort (Sort Flow Shape)
|
||||
// flowChartSummingJunction (Summing Junction Flow Shape)
|
||||
// flowChartTerminator (Terminator Flow Shape)
|
||||
// foldedCorner (Folded Corner Shape)
|
||||
// frame (Frame Shape)
|
||||
// funnel (Funnel Shape)
|
||||
// gear6 (Gear 6 Shape)
|
||||
// gear9 (Gear 9 Shape)
|
||||
// halfFrame (Half Frame Shape)
|
||||
// heart (Heart Shape)
|
||||
// heptagon (Heptagon Shape)
|
||||
// hexagon (Hexagon Shape)
|
||||
// homePlate (Home Plate Shape)
|
||||
// horizontalScroll (Horizontal Scroll Shape)
|
||||
// irregularSeal1 (Irregular Seal 1 Shape)
|
||||
// irregularSeal2 (Irregular Seal 2 Shape)
|
||||
// leftArrow (Left Arrow Shape)
|
||||
// leftArrowCallout (Callout Left Arrow Shape)
|
||||
// leftBrace (Left Brace Shape)
|
||||
// leftBracket (Left Bracket Shape)
|
||||
// leftCircularArrow (Left Circular Arrow Shape)
|
||||
// leftRightArrow (Left Right Arrow Shape)
|
||||
// leftRightArrowCallout (Callout Left Right Arrow Shape)
|
||||
// leftRightCircularArrow (Left Right Circular Arrow Shape)
|
||||
// leftRightRibbon (Left Right Ribbon Shape)
|
||||
// leftRightUpArrow (Left Right Up Arrow Shape)
|
||||
// leftUpArrow (Left Up Arrow Shape)
|
||||
// lightningBolt (Lightning Bolt Shape)
|
||||
// line (Line Shape)
|
||||
// lineInv (Line Inverse Shape)
|
||||
// mathDivide (Divide Math Shape)
|
||||
// mathEqual (Equal Math Shape)
|
||||
// mathMinus (Minus Math Shape)
|
||||
// mathMultiply (Multiply Math Shape)
|
||||
// mathNotEqual (Not Equal Math Shape)
|
||||
// mathPlus (Plus Math Shape)
|
||||
// moon (Moon Shape)
|
||||
// nonIsoscelesTrapezoid (Non-Isosceles Trapezoid Shape)
|
||||
// noSmoking (No Smoking Shape)
|
||||
// notchedRightArrow (Notched Right Arrow Shape)
|
||||
// octagon (Octagon Shape)
|
||||
// parallelogram (Parallelogram Shape)
|
||||
// pentagon (Pentagon Shape)
|
||||
// pie (Pie Shape)
|
||||
// pieWedge (Pie Wedge Shape)
|
||||
// plaque (Plaque Shape)
|
||||
// plaqueTabs (Plaque Tabs Shape)
|
||||
// plus (Plus Shape)
|
||||
// quadArrow (Quad-Arrow Shape)
|
||||
// quadArrowCallout (Callout Quad-Arrow Shape)
|
||||
// rect (Rectangle Shape)
|
||||
// ribbon (Ribbon Shape)
|
||||
// ribbon2 (Ribbon 2 Shape)
|
||||
// rightArrow (Right Arrow Shape)
|
||||
// rightArrowCallout (Callout Right Arrow Shape)
|
||||
// rightBrace (Right Brace Shape)
|
||||
// rightBracket (Right Bracket Shape)
|
||||
// round1Rect (One Round Corner Rectangle Shape)
|
||||
// round2DiagRect (Two Diagonal Round Corner Rectangle Shape)
|
||||
// round2SameRect (Two Same-side Round Corner Rectangle Shape)
|
||||
// roundRect (Round Corner Rectangle Shape)
|
||||
// rtTriangle (Right Triangle Shape)
|
||||
// smileyFace (Smiley Face Shape)
|
||||
// snip1Rect (One Snip Corner Rectangle Shape)
|
||||
// snip2DiagRect (Two Diagonal Snip Corner Rectangle Shape)
|
||||
// snip2SameRect (Two Same-side Snip Corner Rectangle Shape)
|
||||
// snipRoundRect (One Snip One Round Corner Rectangle Shape)
|
||||
// squareTabs (Square Tabs Shape)
|
||||
// star10 (Ten Pointed Star Shape)
|
||||
// star12 (Twelve Pointed Star Shape)
|
||||
// star16 (Sixteen Pointed Star Shape)
|
||||
// star24 (Twenty Four Pointed Star Shape)
|
||||
// star32 (Thirty Two Pointed Star Shape)
|
||||
// star4 (Four Pointed Star Shape)
|
||||
// star5 (Five Pointed Star Shape)
|
||||
// star6 (Six Pointed Star Shape)
|
||||
// star7 (Seven Pointed Star Shape)
|
||||
// star8 (Eight Pointed Star Shape)
|
||||
// straightConnector1 (Straight Connector 1 Shape)
|
||||
// stripedRightArrow (Striped Right Arrow Shape)
|
||||
// sun (Sun Shape)
|
||||
// swooshArrow (Swoosh Arrow Shape)
|
||||
// teardrop (Teardrop Shape)
|
||||
// trapezoid (Trapezoid Shape)
|
||||
// triangle (Triangle Shape)
|
||||
// upArrow (Up Arrow Shape)
|
||||
// upArrowCallout (Callout Up Arrow Shape)
|
||||
// upDownArrow (Up Down Arrow Shape)
|
||||
// upDownArrowCallout (Callout Up Down Arrow Shape)
|
||||
// uturnArrow (U-Turn Arrow Shape)
|
||||
// verticalScroll (Vertical Scroll Shape)
|
||||
// wave (Wave Shape)
|
||||
// wedgeEllipseCallout (Callout Wedge Ellipse Shape)
|
||||
// wedgeRectCallout (Callout Wedge Rectangle Shape)
|
||||
// wedgeRoundRectCallout (Callout Wedge Round Rectangle Shape)
|
||||
//
|
||||
// The following shows the type of text underline supported by excelize:
|
||||
//
|
||||
// none
|
||||
// words
|
||||
// sng
|
||||
// dbl
|
||||
// heavy
|
||||
// dotted
|
||||
// dottedHeavy
|
||||
// dash
|
||||
// dashHeavy
|
||||
// dashLong
|
||||
// dashLongHeavy
|
||||
// dotDash
|
||||
// dotDashHeavy
|
||||
// dotDotDash
|
||||
// dotDotDashHeavy
|
||||
// wavy
|
||||
// wavyHeavy
|
||||
// wavyDbl
|
||||
//
|
||||
// none
|
||||
// words
|
||||
// sng
|
||||
// dbl
|
||||
// heavy
|
||||
// dotted
|
||||
// dottedHeavy
|
||||
// dash
|
||||
// dashHeavy
|
||||
// dashLong
|
||||
// dashLongHeavy
|
||||
// dotDash
|
||||
// dotDashHeavy
|
||||
// dotDotDash
|
||||
// dotDotDashHeavy
|
||||
// wavy
|
||||
// wavyHeavy
|
||||
// wavyDbl
|
||||
func (f *File) AddShape(sheet, cell, format string) error {
|
||||
formatSet, err := parseFormatShapeSet(format)
|
||||
if err != nil {
|
||||
|
|
600
sheet.go
600
sheet.go
|
@ -392,19 +392,18 @@ func (f *File) GetSheetIndex(sheet string) int {
|
|||
// GetSheetMap provides a function to get worksheets, chart sheets, dialog
|
||||
// sheets ID and name map of the workbook. For example:
|
||||
//
|
||||
// f, err := excelize.OpenFile("Book1.xlsx")
|
||||
// if err != nil {
|
||||
// return
|
||||
// }
|
||||
// defer func() {
|
||||
// if err := f.Close(); err != nil {
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
// }()
|
||||
// for index, name := range f.GetSheetMap() {
|
||||
// fmt.Println(index, name)
|
||||
// }
|
||||
//
|
||||
// f, err := excelize.OpenFile("Book1.xlsx")
|
||||
// if err != nil {
|
||||
// return
|
||||
// }
|
||||
// defer func() {
|
||||
// if err := f.Close(); err != nil {
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
// }()
|
||||
// for index, name := range f.GetSheetMap() {
|
||||
// fmt.Println(index, name)
|
||||
// }
|
||||
func (f *File) GetSheetMap() map[int]string {
|
||||
wb := f.workbookReader()
|
||||
sheetMap := map[int]string{}
|
||||
|
@ -588,11 +587,10 @@ func (f *File) deleteSheetFromContentTypes(target string) {
|
|||
// target worksheet index. Note that currently doesn't support duplicate
|
||||
// workbooks that contain tables, charts or pictures. For Example:
|
||||
//
|
||||
// // Sheet1 already exists...
|
||||
// index := f.NewSheet("Sheet2")
|
||||
// err := f.CopySheet(1, index)
|
||||
// return err
|
||||
//
|
||||
// // Sheet1 already exists...
|
||||
// index := f.NewSheet("Sheet2")
|
||||
// err := f.CopySheet(1, index)
|
||||
// return err
|
||||
func (f *File) CopySheet(from, to int) error {
|
||||
if from < 0 || to < 0 || from == to || f.GetSheetName(from) == "" || f.GetSheetName(to) == "" {
|
||||
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
|
||||
// values as defined by https://docs.microsoft.com/en-us/dotnet/api/documentformat.openxml.spreadsheet.sheetstatevalues
|
||||
//
|
||||
// visible
|
||||
// hidden
|
||||
// veryHidden
|
||||
// visible
|
||||
// hidden
|
||||
// veryHidden
|
||||
//
|
||||
// For example, hide Sheet1:
|
||||
//
|
||||
// err := f.SetSheetVisible("Sheet1", false)
|
||||
//
|
||||
// err := f.SetSheetVisible("Sheet1", false)
|
||||
func (f *File) SetSheetVisible(sheet string, visible bool) error {
|
||||
sheet = trimSheetName(sheet)
|
||||
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
|
||||
// attribute are defined in the following table:
|
||||
//
|
||||
// Enumeration Value | Description
|
||||
// --------------------------------+-------------------------------------------------------------
|
||||
// bottomLeft (Bottom Left Pane) | Bottom left pane, when both vertical and horizontal
|
||||
// | splits are applied.
|
||||
// |
|
||||
// | This value is also used when only a horizontal split has
|
||||
// | been applied, dividing the pane into upper and lower
|
||||
// | regions. In that case, this value specifies the bottom
|
||||
// | pane.
|
||||
// |
|
||||
// bottomRight (Bottom Right Pane) | Bottom right pane, when both vertical and horizontal
|
||||
// | splits are applied.
|
||||
// |
|
||||
// topLeft (Top Left Pane) | Top left pane, when both vertical and horizontal splits
|
||||
// | are applied.
|
||||
// |
|
||||
// | This value is also used when only a horizontal split has
|
||||
// | been applied, dividing the pane into upper and lower
|
||||
// | regions. In that case, this value specifies the top pane.
|
||||
// |
|
||||
// | This value is also used when only a vertical split has
|
||||
// | been applied, dividing the pane into right and left
|
||||
// | regions. In that case, this value specifies the left pane
|
||||
// |
|
||||
// topRight (Top Right Pane) | Top right pane, when both vertical and horizontal
|
||||
// | splits are applied.
|
||||
// |
|
||||
// | This value is also used when only a vertical split has
|
||||
// | been applied, dividing the pane into right and left
|
||||
// | regions. In that case, this value specifies the right
|
||||
// | pane.
|
||||
// Enumeration Value | Description
|
||||
// --------------------------------+-------------------------------------------------------------
|
||||
// bottomLeft (Bottom Left Pane) | Bottom left pane, when both vertical and horizontal
|
||||
// | splits are applied.
|
||||
// |
|
||||
// | This value is also used when only a horizontal split has
|
||||
// | been applied, dividing the pane into upper and lower
|
||||
// | regions. In that case, this value specifies the bottom
|
||||
// | pane.
|
||||
// |
|
||||
// bottomRight (Bottom Right Pane) | Bottom right pane, when both vertical and horizontal
|
||||
// | splits are applied.
|
||||
// |
|
||||
// topLeft (Top Left Pane) | Top left pane, when both vertical and horizontal splits
|
||||
// | are applied.
|
||||
// |
|
||||
// | This value is also used when only a horizontal split has
|
||||
// | been applied, dividing the pane into upper and lower
|
||||
// | regions. In that case, this value specifies the top pane.
|
||||
// |
|
||||
// | This value is also used when only a vertical split has
|
||||
// | been applied, dividing the pane into right and left
|
||||
// | regions. In that case, this value specifies the left pane
|
||||
// |
|
||||
// topRight (Top Right Pane) | Top right pane, when both vertical and horizontal
|
||||
// | splits are applied.
|
||||
// |
|
||||
// | This value is also used when only a vertical split has
|
||||
// | been applied, dividing the pane into right and left
|
||||
// | regions. In that case, this value specifies the right
|
||||
// | pane.
|
||||
//
|
||||
// Pane state type is restricted to the values supported currently listed in the following table:
|
||||
//
|
||||
// Enumeration Value | Description
|
||||
// --------------------------------+-------------------------------------------------------------
|
||||
// frozen (Frozen) | Panes are frozen, but were not split being frozen. In
|
||||
// | this state, when the panes are unfrozen again, a single
|
||||
// | pane results, with no split.
|
||||
// |
|
||||
// | In this state, the split bars are not adjustable.
|
||||
// |
|
||||
// split (Split) | Panes are split, but not frozen. In this state, the split
|
||||
// | bars are adjustable by the user.
|
||||
// Enumeration Value | Description
|
||||
// --------------------------------+-------------------------------------------------------------
|
||||
// frozen (Frozen) | Panes are frozen, but were not split being frozen. In
|
||||
// | this state, when the panes are unfrozen again, a single
|
||||
// | pane results, with no split.
|
||||
// |
|
||||
// | In this state, the split bars are not adjustable.
|
||||
// |
|
||||
// split (Split) | Panes are split, but not frozen. In this state, the split
|
||||
// | bars are adjustable by the user.
|
||||
//
|
||||
// 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
|
||||
|
@ -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
|
||||
// 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
|
||||
// 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
|
||||
// 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:
|
||||
//
|
||||
// f.SetPanes("Sheet1", `{"freeze":false,"split":false}`)
|
||||
//
|
||||
// f.SetPanes("Sheet1", `{"freeze":false,"split":false}`)
|
||||
func (f *File) SetPanes(sheet, panes string) error {
|
||||
fs, _ := parseFormatPanesSet(panes)
|
||||
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
|
||||
// name. For example, get visible state of Sheet1:
|
||||
//
|
||||
// f.GetSheetVisible("Sheet1")
|
||||
//
|
||||
// f.GetSheetVisible("Sheet1")
|
||||
func (f *File) GetSheetVisible(sheet string) bool {
|
||||
content, name, visible := f.workbookReader(), trimSheetName(sheet), false
|
||||
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:
|
||||
//
|
||||
// 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
|
||||
// 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) {
|
||||
var (
|
||||
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:
|
||||
//
|
||||
// Fields | Description
|
||||
// ------------------+-----------------------------------------------------------
|
||||
// AlignWithMargins | Align header footer margins with page margins
|
||||
// DifferentFirst | Different first-page header and footer indicator
|
||||
// DifferentOddEven | Different odd and even page headers and footers indicator
|
||||
// ScaleWithDoc | Scale header and footer with document scaling
|
||||
// OddFooter | Odd Page Footer
|
||||
// OddHeader | Odd Header
|
||||
// EvenFooter | Even Page Footer
|
||||
// EvenHeader | Even Page Header
|
||||
// FirstFooter | First Page Footer
|
||||
// FirstHeader | First Page Header
|
||||
// Fields | Description
|
||||
// ------------------+-----------------------------------------------------------
|
||||
// AlignWithMargins | Align header footer margins with page margins
|
||||
// DifferentFirst | Different first-page header and footer indicator
|
||||
// DifferentOddEven | Different odd and even page headers and footers indicator
|
||||
// ScaleWithDoc | Scale header and footer with document scaling
|
||||
// OddFooter | Odd Page Footer
|
||||
// OddHeader | Odd Header
|
||||
// EvenFooter | Even Page Footer
|
||||
// EvenHeader | Even Page Header
|
||||
// FirstFooter | First Page Footer
|
||||
// FirstHeader | First Page Header
|
||||
//
|
||||
// The following formatting codes can be used in 6 string type fields:
|
||||
// OddHeader, OddFooter, EvenHeader, EvenFooter, FirstFooter, FirstHeader
|
||||
//
|
||||
// Formatting Code | Description
|
||||
// ------------------------+-------------------------------------------------------------------------
|
||||
// && | The character "&"
|
||||
// |
|
||||
// &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 type
|
||||
// |
|
||||
// &"-,Regular" | Regular text format. Toggles bold and italic modes to off
|
||||
// |
|
||||
// &A | Current worksheet's tab name
|
||||
// |
|
||||
// &B or &"-,Bold" | Bold text format, from off to on, or vice versa. The default mode is off
|
||||
// |
|
||||
// &D | Current date
|
||||
// |
|
||||
// &C | Center section
|
||||
// |
|
||||
// &E | Double-underline text format
|
||||
// |
|
||||
// &F | Current workbook's file name
|
||||
// |
|
||||
// &G | Drawing object as background
|
||||
// |
|
||||
// &H | Shadow text format
|
||||
// |
|
||||
// &I or &"-,Italic" | Italic text format
|
||||
// |
|
||||
// &K | Text font color
|
||||
// |
|
||||
// | An RGB Color is specified as RRGGBB
|
||||
// |
|
||||
// | 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
|
||||
// | tint/shade value
|
||||
// |
|
||||
// &L | Left section
|
||||
// |
|
||||
// &N | Total number of pages
|
||||
// |
|
||||
// &O | Outline text format
|
||||
// |
|
||||
// &P[[+|-]n] | Without the optional suffix, the current page number in decimal
|
||||
// |
|
||||
// &R | Right section
|
||||
// |
|
||||
// &S | Strikethrough text format
|
||||
// |
|
||||
// &T | Current time
|
||||
// |
|
||||
// &U | Single-underline text format. If double-underline mode is on, the next
|
||||
// | occurrence in a section specifier toggles double-underline mode to off;
|
||||
// | otherwise, it toggles single-underline mode, from off to on, or vice
|
||||
// | versa. The default mode is off
|
||||
// |
|
||||
// &X | Superscript text format
|
||||
// |
|
||||
// &Y | Subscript text format
|
||||
// |
|
||||
// &Z | Current workbook's file path
|
||||
// Formatting Code | Description
|
||||
// ------------------------+-------------------------------------------------------------------------
|
||||
// && | The character "&"
|
||||
// |
|
||||
// &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 type
|
||||
// |
|
||||
// &"-,Regular" | Regular text format. Toggles bold and italic modes to off
|
||||
// |
|
||||
// &A | Current worksheet's tab name
|
||||
// |
|
||||
// &B or &"-,Bold" | Bold text format, from off to on, or vice versa. The default mode is off
|
||||
// |
|
||||
// &D | Current date
|
||||
// |
|
||||
// &C | Center section
|
||||
// |
|
||||
// &E | Double-underline text format
|
||||
// |
|
||||
// &F | Current workbook's file name
|
||||
// |
|
||||
// &G | Drawing object as background
|
||||
// |
|
||||
// &H | Shadow text format
|
||||
// |
|
||||
// &I or &"-,Italic" | Italic text format
|
||||
// |
|
||||
// &K | Text font color
|
||||
// |
|
||||
// | An RGB Color is specified as RRGGBB
|
||||
// |
|
||||
// | 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
|
||||
// | tint/shade value
|
||||
// |
|
||||
// &L | Left section
|
||||
// |
|
||||
// &N | Total number of pages
|
||||
// |
|
||||
// &O | Outline text format
|
||||
// |
|
||||
// &P[[+|-]n] | Without the optional suffix, the current page number in decimal
|
||||
// |
|
||||
// &R | Right section
|
||||
// |
|
||||
// &S | Strikethrough text format
|
||||
// |
|
||||
// &T | Current time
|
||||
// |
|
||||
// &U | Single-underline text format. If double-underline mode is on, the next
|
||||
// | occurrence in a section specifier toggles double-underline mode to off;
|
||||
// | otherwise, it toggles single-underline mode, from off to on, or vice
|
||||
// | versa. The default mode is off
|
||||
// |
|
||||
// &X | Superscript text format
|
||||
// |
|
||||
// &Y | Subscript text format
|
||||
// |
|
||||
// &Z | Current workbook's file path
|
||||
//
|
||||
// For example:
|
||||
//
|
||||
// err := f.SetHeaderFooter("Sheet1", &excelize.FormatHeaderFooter{
|
||||
// DifferentFirst: true,
|
||||
// DifferentOddEven: true,
|
||||
// OddHeader: "&R&P",
|
||||
// OddFooter: "&C&F",
|
||||
// EvenHeader: "&L&P",
|
||||
// EvenFooter: "&L&D&R&T",
|
||||
// FirstHeader: `&CCenter &"-,Bold"Bold&"-,Regular"HeaderU+000A&D`,
|
||||
// })
|
||||
// err := f.SetHeaderFooter("Sheet1", &excelize.FormatHeaderFooter{
|
||||
// DifferentFirst: true,
|
||||
// DifferentOddEven: true,
|
||||
// OddHeader: "&R&P",
|
||||
// OddFooter: "&C&F",
|
||||
// EvenHeader: "&L&P",
|
||||
// EvenFooter: "&L&D&R&T",
|
||||
// FirstHeader: `&CCenter &"-,Bold"Bold&"-,Regular"HeaderU+000A&D`,
|
||||
// })
|
||||
//
|
||||
// This example shows:
|
||||
//
|
||||
|
@ -1071,7 +1065,6 @@ func attrValToBool(name string, attrs []xml.Attr) (val bool, err error) {
|
|||
// that same page
|
||||
//
|
||||
// - No footer on the first page
|
||||
//
|
||||
func (f *File) SetHeaderFooter(sheet string, settings *FormatHeaderFooter) error {
|
||||
ws, err := f.workSheetReader(sheet)
|
||||
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
|
||||
// Sheet1 with protection settings:
|
||||
//
|
||||
// err := f.ProtectSheet("Sheet1", &excelize.FormatSheetProtection{
|
||||
// AlgorithmName: "SHA-512",
|
||||
// Password: "password",
|
||||
// EditScenarios: false,
|
||||
// })
|
||||
//
|
||||
// err := f.ProtectSheet("Sheet1", &excelize.FormatSheetProtection{
|
||||
// AlgorithmName: "SHA-512",
|
||||
// Password: "password",
|
||||
// EditScenarios: false,
|
||||
// })
|
||||
func (f *File) ProtectSheet(sheet string, settings *FormatSheetProtection) error {
|
||||
ws, err := f.workSheetReader(sheet)
|
||||
if err != nil {
|
||||
|
@ -1377,135 +1369,134 @@ func (p *PageLayoutScale) getPageLayout(ps *xlsxPageSetUp) {
|
|||
//
|
||||
// Available options:
|
||||
//
|
||||
// BlackAndWhite(bool)
|
||||
// FirstPageNumber(uint)
|
||||
// PageLayoutOrientation(string)
|
||||
// PageLayoutPaperSize(int)
|
||||
// FitToHeight(int)
|
||||
// FitToWidth(int)
|
||||
// PageLayoutScale(uint)
|
||||
// BlackAndWhite(bool)
|
||||
// FirstPageNumber(uint)
|
||||
// PageLayoutOrientation(string)
|
||||
// PageLayoutPaperSize(int)
|
||||
// FitToHeight(int)
|
||||
// FitToWidth(int)
|
||||
// PageLayoutScale(uint)
|
||||
//
|
||||
// The following shows the paper size sorted by excelize index number:
|
||||
//
|
||||
// Index | Paper Size
|
||||
// -------+-----------------------------------------------
|
||||
// 1 | Letter 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.)
|
||||
// 4 | Ledger paper (17 in. by 11 in.)
|
||||
// 5 | Legal paper (8.5 in. by 14 in.)
|
||||
// 6 | Statement paper (5.5 in. by 8.5 in.)
|
||||
// 7 | Executive paper (7.25 in. by 10.5 in.)
|
||||
// 8 | A3 paper (297 mm by 420 mm)
|
||||
// 9 | A4 paper (210 mm by 297 mm)
|
||||
// 10 | A4 small paper (210 mm by 297 mm)
|
||||
// 11 | A5 paper (148 mm by 210 mm)
|
||||
// 12 | B4 paper (250 mm by 353 mm)
|
||||
// 13 | B5 paper (176 mm by 250 mm)
|
||||
// 14 | Folio paper (8.5 in. by 13 in.)
|
||||
// 15 | Quarto paper (215 mm by 275 mm)
|
||||
// 16 | Standard paper (10 in. by 14 in.)
|
||||
// 17 | Standard paper (11 in. by 17 in.)
|
||||
// 18 | Note paper (8.5 in. by 11 in.)
|
||||
// 19 | #9 envelope (3.875 in. by 8.875 in.)
|
||||
// 20 | #10 envelope (4.125 in. by 9.5 in.)
|
||||
// 21 | #11 envelope (4.5 in. by 10.375 in.)
|
||||
// 22 | #12 envelope (4.75 in. by 11 in.)
|
||||
// 23 | #14 envelope (5 in. by 11.5 in.)
|
||||
// 24 | C paper (17 in. by 22 in.)
|
||||
// 25 | D paper (22 in. by 34 in.)
|
||||
// 26 | E paper (34 in. by 44 in.)
|
||||
// 27 | DL envelope (110 mm by 220 mm)
|
||||
// 28 | C5 envelope (162 mm by 229 mm)
|
||||
// 29 | C3 envelope (324 mm by 458 mm)
|
||||
// 30 | C4 envelope (229 mm by 324 mm)
|
||||
// 31 | C6 envelope (114 mm by 162 mm)
|
||||
// 32 | C65 envelope (114 mm by 229 mm)
|
||||
// 33 | B4 envelope (250 mm by 353 mm)
|
||||
// 34 | B5 envelope (176 mm by 250 mm)
|
||||
// 35 | B6 envelope (176 mm by 125 mm)
|
||||
// 36 | Italy envelope (110 mm by 230 mm)
|
||||
// 37 | Monarch envelope (3.875 in. by 7.5 in.).
|
||||
// 38 | 6 3/4 envelope (3.625 in. by 6.5 in.)
|
||||
// 39 | US standard fanfold (14.875 in. by 11 in.)
|
||||
// 40 | German standard fanfold (8.5 in. by 12 in.)
|
||||
// 41 | German legal fanfold (8.5 in. by 13 in.)
|
||||
// 42 | ISO B4 (250 mm by 353 mm)
|
||||
// 43 | Japanese postcard (100 mm by 148 mm)
|
||||
// 44 | Standard paper (9 in. by 11 in.)
|
||||
// 45 | Standard paper (10 in. by 11 in.)
|
||||
// 46 | Standard paper (15 in. by 11 in.)
|
||||
// 47 | Invite envelope (220 mm by 220 mm)
|
||||
// 50 | Letter extra paper (9.275 in. by 12 in.)
|
||||
// 51 | Legal extra paper (9.275 in. by 15 in.)
|
||||
// 52 | Tabloid extra paper (11.69 in. by 18 in.)
|
||||
// 53 | A4 extra paper (236 mm by 322 mm)
|
||||
// 54 | Letter transverse paper (8.275 in. by 11 in.)
|
||||
// 55 | A4 transverse paper (210 mm by 297 mm)
|
||||
// 56 | Letter extra transverse paper (9.275 in. by 12 in.)
|
||||
// 57 | SuperA/SuperA/A4 paper (227 mm by 356 mm)
|
||||
// 58 | SuperB/SuperB/A3 paper (305 mm by 487 mm)
|
||||
// 59 | Letter plus paper (8.5 in. by 12.69 in.)
|
||||
// 60 | A4 plus paper (210 mm by 330 mm)
|
||||
// 61 | A5 transverse paper (148 mm by 210 mm)
|
||||
// 62 | JIS B5 transverse paper (182 mm by 257 mm)
|
||||
// 63 | A3 extra paper (322 mm by 445 mm)
|
||||
// 64 | A5 extra paper (174 mm by 235 mm)
|
||||
// 65 | ISO B5 extra paper (201 mm by 276 mm)
|
||||
// 66 | A2 paper (420 mm by 594 mm)
|
||||
// 67 | A3 transverse paper (297 mm by 420 mm)
|
||||
// 68 | A3 extra transverse paper (322 mm by 445 mm)
|
||||
// 69 | Japanese Double Postcard (200 mm x 148 mm)
|
||||
// 70 | A6 (105 mm x 148 mm)
|
||||
// 71 | Japanese Envelope Kaku #2
|
||||
// 72 | Japanese Envelope Kaku #3
|
||||
// 73 | Japanese Envelope Chou #3
|
||||
// 74 | Japanese Envelope Chou #4
|
||||
// 75 | Letter Rotated (11in x 8 1/2 11 in)
|
||||
// 76 | A3 Rotated (420 mm x 297 mm)
|
||||
// 77 | A4 Rotated (297 mm x 210 mm)
|
||||
// 78 | A5 Rotated (210 mm x 148 mm)
|
||||
// 79 | B4 (JIS) Rotated (364 mm x 257 mm)
|
||||
// 80 | B5 (JIS) Rotated (257 mm x 182 mm)
|
||||
// 81 | Japanese Postcard Rotated (148 mm x 100 mm)
|
||||
// 82 | Double Japanese Postcard Rotated (148 mm x 200 mm)
|
||||
// 83 | A6 Rotated (148 mm x 105 mm)
|
||||
// 84 | Japanese Envelope Kaku #2 Rotated
|
||||
// 85 | Japanese Envelope Kaku #3 Rotated
|
||||
// 86 | Japanese Envelope Chou #3 Rotated
|
||||
// 87 | Japanese Envelope Chou #4 Rotated
|
||||
// 88 | B6 (JIS) (128 mm x 182 mm)
|
||||
// 89 | B6 (JIS) Rotated (182 mm x 128 mm)
|
||||
// 90 | (12 in x 11 in)
|
||||
// 91 | Japanese Envelope You #4
|
||||
// 92 | Japanese Envelope You #4 Rotated
|
||||
// 93 | PRC 16K (146 mm x 215 mm)
|
||||
// 94 | PRC 32K (97 mm x 151 mm)
|
||||
// 95 | PRC 32K(Big) (97 mm x 151 mm)
|
||||
// 96 | PRC Envelope #1 (102 mm x 165 mm)
|
||||
// 97 | PRC Envelope #2 (102 mm x 176 mm)
|
||||
// 98 | PRC Envelope #3 (125 mm x 176 mm)
|
||||
// 99 | PRC Envelope #4 (110 mm x 208 mm)
|
||||
// 100 | PRC Envelope #5 (110 mm x 220 mm)
|
||||
// 101 | PRC Envelope #6 (120 mm x 230 mm)
|
||||
// 102 | PRC Envelope #7 (160 mm x 230 mm)
|
||||
// 103 | PRC Envelope #8 (120 mm x 309 mm)
|
||||
// 104 | PRC Envelope #9 (229 mm x 324 mm)
|
||||
// 105 | PRC Envelope #10 (324 mm x 458 mm)
|
||||
// 106 | PRC 16K Rotated
|
||||
// 107 | PRC 32K Rotated
|
||||
// 108 | PRC 32K(Big) Rotated
|
||||
// 109 | PRC Envelope #1 Rotated (165 mm x 102 mm)
|
||||
// 110 | PRC Envelope #2 Rotated (176 mm x 102 mm)
|
||||
// 111 | PRC Envelope #3 Rotated (176 mm x 125 mm)
|
||||
// 112 | PRC Envelope #4 Rotated (208 mm x 110 mm)
|
||||
// 113 | PRC Envelope #5 Rotated (220 mm x 110 mm)
|
||||
// 114 | PRC Envelope #6 Rotated (230 mm x 120 mm)
|
||||
// 115 | PRC Envelope #7 Rotated (230 mm x 160 mm)
|
||||
// 116 | PRC Envelope #8 Rotated (309 mm x 120 mm)
|
||||
// 117 | PRC Envelope #9 Rotated (324 mm x 229 mm)
|
||||
// 118 | PRC Envelope #10 Rotated (458 mm x 324 mm)
|
||||
//
|
||||
// Index | Paper Size
|
||||
// -------+-----------------------------------------------
|
||||
// 1 | Letter 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.)
|
||||
// 4 | Ledger paper (17 in. by 11 in.)
|
||||
// 5 | Legal paper (8.5 in. by 14 in.)
|
||||
// 6 | Statement paper (5.5 in. by 8.5 in.)
|
||||
// 7 | Executive paper (7.25 in. by 10.5 in.)
|
||||
// 8 | A3 paper (297 mm by 420 mm)
|
||||
// 9 | A4 paper (210 mm by 297 mm)
|
||||
// 10 | A4 small paper (210 mm by 297 mm)
|
||||
// 11 | A5 paper (148 mm by 210 mm)
|
||||
// 12 | B4 paper (250 mm by 353 mm)
|
||||
// 13 | B5 paper (176 mm by 250 mm)
|
||||
// 14 | Folio paper (8.5 in. by 13 in.)
|
||||
// 15 | Quarto paper (215 mm by 275 mm)
|
||||
// 16 | Standard paper (10 in. by 14 in.)
|
||||
// 17 | Standard paper (11 in. by 17 in.)
|
||||
// 18 | Note paper (8.5 in. by 11 in.)
|
||||
// 19 | #9 envelope (3.875 in. by 8.875 in.)
|
||||
// 20 | #10 envelope (4.125 in. by 9.5 in.)
|
||||
// 21 | #11 envelope (4.5 in. by 10.375 in.)
|
||||
// 22 | #12 envelope (4.75 in. by 11 in.)
|
||||
// 23 | #14 envelope (5 in. by 11.5 in.)
|
||||
// 24 | C paper (17 in. by 22 in.)
|
||||
// 25 | D paper (22 in. by 34 in.)
|
||||
// 26 | E paper (34 in. by 44 in.)
|
||||
// 27 | DL envelope (110 mm by 220 mm)
|
||||
// 28 | C5 envelope (162 mm by 229 mm)
|
||||
// 29 | C3 envelope (324 mm by 458 mm)
|
||||
// 30 | C4 envelope (229 mm by 324 mm)
|
||||
// 31 | C6 envelope (114 mm by 162 mm)
|
||||
// 32 | C65 envelope (114 mm by 229 mm)
|
||||
// 33 | B4 envelope (250 mm by 353 mm)
|
||||
// 34 | B5 envelope (176 mm by 250 mm)
|
||||
// 35 | B6 envelope (176 mm by 125 mm)
|
||||
// 36 | Italy envelope (110 mm by 230 mm)
|
||||
// 37 | Monarch envelope (3.875 in. by 7.5 in.).
|
||||
// 38 | 6 3/4 envelope (3.625 in. by 6.5 in.)
|
||||
// 39 | US standard fanfold (14.875 in. by 11 in.)
|
||||
// 40 | German standard fanfold (8.5 in. by 12 in.)
|
||||
// 41 | German legal fanfold (8.5 in. by 13 in.)
|
||||
// 42 | ISO B4 (250 mm by 353 mm)
|
||||
// 43 | Japanese postcard (100 mm by 148 mm)
|
||||
// 44 | Standard paper (9 in. by 11 in.)
|
||||
// 45 | Standard paper (10 in. by 11 in.)
|
||||
// 46 | Standard paper (15 in. by 11 in.)
|
||||
// 47 | Invite envelope (220 mm by 220 mm)
|
||||
// 50 | Letter extra paper (9.275 in. by 12 in.)
|
||||
// 51 | Legal extra paper (9.275 in. by 15 in.)
|
||||
// 52 | Tabloid extra paper (11.69 in. by 18 in.)
|
||||
// 53 | A4 extra paper (236 mm by 322 mm)
|
||||
// 54 | Letter transverse paper (8.275 in. by 11 in.)
|
||||
// 55 | A4 transverse paper (210 mm by 297 mm)
|
||||
// 56 | Letter extra transverse paper (9.275 in. by 12 in.)
|
||||
// 57 | SuperA/SuperA/A4 paper (227 mm by 356 mm)
|
||||
// 58 | SuperB/SuperB/A3 paper (305 mm by 487 mm)
|
||||
// 59 | Letter plus paper (8.5 in. by 12.69 in.)
|
||||
// 60 | A4 plus paper (210 mm by 330 mm)
|
||||
// 61 | A5 transverse paper (148 mm by 210 mm)
|
||||
// 62 | JIS B5 transverse paper (182 mm by 257 mm)
|
||||
// 63 | A3 extra paper (322 mm by 445 mm)
|
||||
// 64 | A5 extra paper (174 mm by 235 mm)
|
||||
// 65 | ISO B5 extra paper (201 mm by 276 mm)
|
||||
// 66 | A2 paper (420 mm by 594 mm)
|
||||
// 67 | A3 transverse paper (297 mm by 420 mm)
|
||||
// 68 | A3 extra transverse paper (322 mm by 445 mm)
|
||||
// 69 | Japanese Double Postcard (200 mm x 148 mm)
|
||||
// 70 | A6 (105 mm x 148 mm)
|
||||
// 71 | Japanese Envelope Kaku #2
|
||||
// 72 | Japanese Envelope Kaku #3
|
||||
// 73 | Japanese Envelope Chou #3
|
||||
// 74 | Japanese Envelope Chou #4
|
||||
// 75 | Letter Rotated (11in x 8 1/2 11 in)
|
||||
// 76 | A3 Rotated (420 mm x 297 mm)
|
||||
// 77 | A4 Rotated (297 mm x 210 mm)
|
||||
// 78 | A5 Rotated (210 mm x 148 mm)
|
||||
// 79 | B4 (JIS) Rotated (364 mm x 257 mm)
|
||||
// 80 | B5 (JIS) Rotated (257 mm x 182 mm)
|
||||
// 81 | Japanese Postcard Rotated (148 mm x 100 mm)
|
||||
// 82 | Double Japanese Postcard Rotated (148 mm x 200 mm)
|
||||
// 83 | A6 Rotated (148 mm x 105 mm)
|
||||
// 84 | Japanese Envelope Kaku #2 Rotated
|
||||
// 85 | Japanese Envelope Kaku #3 Rotated
|
||||
// 86 | Japanese Envelope Chou #3 Rotated
|
||||
// 87 | Japanese Envelope Chou #4 Rotated
|
||||
// 88 | B6 (JIS) (128 mm x 182 mm)
|
||||
// 89 | B6 (JIS) Rotated (182 mm x 128 mm)
|
||||
// 90 | (12 in x 11 in)
|
||||
// 91 | Japanese Envelope You #4
|
||||
// 92 | Japanese Envelope You #4 Rotated
|
||||
// 93 | PRC 16K (146 mm x 215 mm)
|
||||
// 94 | PRC 32K (97 mm x 151 mm)
|
||||
// 95 | PRC 32K(Big) (97 mm x 151 mm)
|
||||
// 96 | PRC Envelope #1 (102 mm x 165 mm)
|
||||
// 97 | PRC Envelope #2 (102 mm x 176 mm)
|
||||
// 98 | PRC Envelope #3 (125 mm x 176 mm)
|
||||
// 99 | PRC Envelope #4 (110 mm x 208 mm)
|
||||
// 100 | PRC Envelope #5 (110 mm x 220 mm)
|
||||
// 101 | PRC Envelope #6 (120 mm x 230 mm)
|
||||
// 102 | PRC Envelope #7 (160 mm x 230 mm)
|
||||
// 103 | PRC Envelope #8 (120 mm x 309 mm)
|
||||
// 104 | PRC Envelope #9 (229 mm x 324 mm)
|
||||
// 105 | PRC Envelope #10 (324 mm x 458 mm)
|
||||
// 106 | PRC 16K Rotated
|
||||
// 107 | PRC 32K Rotated
|
||||
// 108 | PRC 32K(Big) Rotated
|
||||
// 109 | PRC Envelope #1 Rotated (165 mm x 102 mm)
|
||||
// 110 | PRC Envelope #2 Rotated (176 mm x 102 mm)
|
||||
// 111 | PRC Envelope #3 Rotated (176 mm x 125 mm)
|
||||
// 112 | PRC Envelope #4 Rotated (208 mm x 110 mm)
|
||||
// 113 | PRC Envelope #5 Rotated (220 mm x 110 mm)
|
||||
// 114 | PRC Envelope #6 Rotated (230 mm x 120 mm)
|
||||
// 115 | PRC Envelope #7 Rotated (230 mm x 160 mm)
|
||||
// 116 | PRC Envelope #8 Rotated (309 mm x 120 mm)
|
||||
// 117 | PRC Envelope #9 Rotated (324 mm x 229 mm)
|
||||
// 118 | PRC Envelope #10 Rotated (458 mm x 324 mm)
|
||||
func (f *File) SetPageLayout(sheet string, opts ...PageLayoutOption) error {
|
||||
s, err := f.workSheetReader(sheet)
|
||||
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.
|
||||
//
|
||||
// Available options:
|
||||
// PageLayoutOrientation(string)
|
||||
// PageLayoutPaperSize(int)
|
||||
// FitToHeight(int)
|
||||
// FitToWidth(int)
|
||||
//
|
||||
// PageLayoutOrientation(string)
|
||||
// PageLayoutPaperSize(int)
|
||||
// FitToHeight(int)
|
||||
// FitToWidth(int)
|
||||
func (f *File) GetPageLayout(sheet string, opts ...PageLayoutOptionPtr) error {
|
||||
s, err := f.workSheetReader(sheet)
|
||||
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.
|
||||
// For example:
|
||||
//
|
||||
// f.SetDefinedName(&excelize.DefinedName{
|
||||
// Name: "Amount",
|
||||
// RefersTo: "Sheet1!$A$2:$D$5",
|
||||
// Comment: "defined name comment",
|
||||
// Scope: "Sheet2",
|
||||
// })
|
||||
//
|
||||
// f.SetDefinedName(&excelize.DefinedName{
|
||||
// Name: "Amount",
|
||||
// RefersTo: "Sheet1!$A$2:$D$5",
|
||||
// Comment: "defined name comment",
|
||||
// Scope: "Sheet2",
|
||||
// })
|
||||
func (f *File) SetDefinedName(definedName *DefinedName) error {
|
||||
wb := f.workbookReader()
|
||||
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. For example:
|
||||
//
|
||||
// f.DeleteDefinedName(&excelize.DefinedName{
|
||||
// Name: "Amount",
|
||||
// Scope: "Sheet2",
|
||||
// })
|
||||
//
|
||||
// f.DeleteDefinedName(&excelize.DefinedName{
|
||||
// Name: "Amount",
|
||||
// Scope: "Sheet2",
|
||||
// })
|
||||
func (f *File) DeleteDefinedName(definedName *DefinedName) error {
|
||||
wb := f.workbookReader()
|
||||
if wb.DefinedNames != nil {
|
||||
|
|
98
sheetpr.go
98
sheetpr.go
|
@ -238,16 +238,17 @@ func (o *AutoPageBreaks) getSheetPrOption(pr *xlsxSheetPr) {
|
|||
// SetSheetPrOptions provides a function to sets worksheet properties.
|
||||
//
|
||||
// Available options:
|
||||
// CodeName(string)
|
||||
// EnableFormatConditionsCalculation(bool)
|
||||
// Published(bool)
|
||||
// FitToPage(bool)
|
||||
// TabColorIndexed(int)
|
||||
// TabColorRGB(string)
|
||||
// TabColorTheme(int)
|
||||
// TabColorTint(float64)
|
||||
// AutoPageBreaks(bool)
|
||||
// OutlineSummaryBelow(bool)
|
||||
//
|
||||
// CodeName(string)
|
||||
// EnableFormatConditionsCalculation(bool)
|
||||
// Published(bool)
|
||||
// FitToPage(bool)
|
||||
// TabColorIndexed(int)
|
||||
// TabColorRGB(string)
|
||||
// TabColorTheme(int)
|
||||
// TabColorTint(float64)
|
||||
// AutoPageBreaks(bool)
|
||||
// OutlineSummaryBelow(bool)
|
||||
func (f *File) SetSheetPrOptions(sheet string, opts ...SheetPrOption) error {
|
||||
ws, err := f.workSheetReader(sheet)
|
||||
if err != nil {
|
||||
|
@ -268,16 +269,17 @@ func (f *File) SetSheetPrOptions(sheet string, opts ...SheetPrOption) error {
|
|||
// GetSheetPrOptions provides a function to gets worksheet properties.
|
||||
//
|
||||
// Available options:
|
||||
// CodeName(string)
|
||||
// EnableFormatConditionsCalculation(bool)
|
||||
// Published(bool)
|
||||
// FitToPage(bool)
|
||||
// TabColorIndexed(int)
|
||||
// TabColorRGB(string)
|
||||
// TabColorTheme(int)
|
||||
// TabColorTint(float64)
|
||||
// AutoPageBreaks(bool)
|
||||
// OutlineSummaryBelow(bool)
|
||||
//
|
||||
// CodeName(string)
|
||||
// EnableFormatConditionsCalculation(bool)
|
||||
// Published(bool)
|
||||
// FitToPage(bool)
|
||||
// TabColorIndexed(int)
|
||||
// TabColorRGB(string)
|
||||
// TabColorTheme(int)
|
||||
// TabColorTint(float64)
|
||||
// AutoPageBreaks(bool)
|
||||
// OutlineSummaryBelow(bool)
|
||||
func (f *File) GetSheetPrOptions(sheet string, opts ...SheetPrOptionPtr) error {
|
||||
ws, err := f.workSheetReader(sheet)
|
||||
if err != nil {
|
||||
|
@ -412,12 +414,13 @@ type PageMarginsOptionsPtr interface {
|
|||
// SetPageMargins provides a function to set worksheet page margins.
|
||||
//
|
||||
// Available options:
|
||||
// PageMarginBottom(float64)
|
||||
// PageMarginFooter(float64)
|
||||
// PageMarginHeader(float64)
|
||||
// PageMarginLeft(float64)
|
||||
// PageMarginRight(float64)
|
||||
// PageMarginTop(float64)
|
||||
//
|
||||
// PageMarginBottom(float64)
|
||||
// PageMarginFooter(float64)
|
||||
// PageMarginHeader(float64)
|
||||
// PageMarginLeft(float64)
|
||||
// PageMarginRight(float64)
|
||||
// PageMarginTop(float64)
|
||||
func (f *File) SetPageMargins(sheet string, opts ...PageMarginsOptions) error {
|
||||
s, err := f.workSheetReader(sheet)
|
||||
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.
|
||||
//
|
||||
// Available options:
|
||||
// PageMarginBottom(float64)
|
||||
// PageMarginFooter(float64)
|
||||
// PageMarginHeader(float64)
|
||||
// PageMarginLeft(float64)
|
||||
// PageMarginRight(float64)
|
||||
// PageMarginTop(float64)
|
||||
//
|
||||
// PageMarginBottom(float64)
|
||||
// PageMarginFooter(float64)
|
||||
// PageMarginHeader(float64)
|
||||
// PageMarginLeft(float64)
|
||||
// PageMarginRight(float64)
|
||||
// PageMarginTop(float64)
|
||||
func (f *File) GetPageMargins(sheet string, opts ...PageMarginsOptionsPtr) error {
|
||||
s, err := f.workSheetReader(sheet)
|
||||
if err != nil {
|
||||
|
@ -605,13 +609,14 @@ func (p *ThickBottom) getSheetFormatPr(fp *xlsxSheetFormatPr) {
|
|||
// SetSheetFormatPr provides a function to set worksheet formatting properties.
|
||||
//
|
||||
// Available options:
|
||||
// BaseColWidth(uint8)
|
||||
// DefaultColWidth(float64)
|
||||
// DefaultRowHeight(float64)
|
||||
// CustomHeight(bool)
|
||||
// ZeroHeight(bool)
|
||||
// ThickTop(bool)
|
||||
// ThickBottom(bool)
|
||||
//
|
||||
// BaseColWidth(uint8)
|
||||
// DefaultColWidth(float64)
|
||||
// DefaultRowHeight(float64)
|
||||
// CustomHeight(bool)
|
||||
// ZeroHeight(bool)
|
||||
// ThickTop(bool)
|
||||
// ThickBottom(bool)
|
||||
func (f *File) SetSheetFormatPr(sheet string, opts ...SheetFormatPrOptions) error {
|
||||
s, err := f.workSheetReader(sheet)
|
||||
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.
|
||||
//
|
||||
// Available options:
|
||||
// BaseColWidth(uint8)
|
||||
// DefaultColWidth(float64)
|
||||
// DefaultRowHeight(float64)
|
||||
// CustomHeight(bool)
|
||||
// ZeroHeight(bool)
|
||||
// ThickTop(bool)
|
||||
// ThickBottom(bool)
|
||||
//
|
||||
// BaseColWidth(uint8)
|
||||
// DefaultColWidth(float64)
|
||||
// DefaultRowHeight(float64)
|
||||
// CustomHeight(bool)
|
||||
// ZeroHeight(bool)
|
||||
// ThickTop(bool)
|
||||
// ThickBottom(bool)
|
||||
func (f *File) GetSheetFormatPr(sheet string, opts ...SheetFormatPrOptionsPtr) error {
|
||||
s, err := f.workSheetReader(sheet)
|
||||
if err != nil {
|
||||
|
|
48
sheetview.go
48
sheetview.go
|
@ -185,21 +185,20 @@ func (f *File) getSheetView(sheet string, viewIndex int) (*xlsxSheetView, error)
|
|||
//
|
||||
// Available options:
|
||||
//
|
||||
// DefaultGridColor(bool)
|
||||
// ShowFormulas(bool)
|
||||
// ShowGridLines(bool)
|
||||
// ShowRowColHeaders(bool)
|
||||
// ShowZeros(bool)
|
||||
// RightToLeft(bool)
|
||||
// ShowRuler(bool)
|
||||
// View(string)
|
||||
// TopLeftCell(string)
|
||||
// ZoomScale(float64)
|
||||
// DefaultGridColor(bool)
|
||||
// ShowFormulas(bool)
|
||||
// ShowGridLines(bool)
|
||||
// ShowRowColHeaders(bool)
|
||||
// ShowZeros(bool)
|
||||
// RightToLeft(bool)
|
||||
// ShowRuler(bool)
|
||||
// View(string)
|
||||
// TopLeftCell(string)
|
||||
// ZoomScale(float64)
|
||||
//
|
||||
// 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 {
|
||||
view, err := f.getSheetView(sheet, viewIndex)
|
||||
if err != nil {
|
||||
|
@ -217,22 +216,21 @@ func (f *File) SetSheetViewOptions(sheet string, viewIndex int, opts ...SheetVie
|
|||
//
|
||||
// Available options:
|
||||
//
|
||||
// DefaultGridColor(bool)
|
||||
// ShowFormulas(bool)
|
||||
// ShowGridLines(bool)
|
||||
// ShowRowColHeaders(bool)
|
||||
// ShowZeros(bool)
|
||||
// RightToLeft(bool)
|
||||
// ShowRuler(bool)
|
||||
// View(string)
|
||||
// TopLeftCell(string)
|
||||
// ZoomScale(float64)
|
||||
// DefaultGridColor(bool)
|
||||
// ShowFormulas(bool)
|
||||
// ShowGridLines(bool)
|
||||
// ShowRowColHeaders(bool)
|
||||
// ShowZeros(bool)
|
||||
// RightToLeft(bool)
|
||||
// ShowRuler(bool)
|
||||
// View(string)
|
||||
// TopLeftCell(string)
|
||||
// ZoomScale(float64)
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// var showGridLines excelize.ShowGridLines
|
||||
// err = f.GetSheetViewOptions("Sheet1", -1, &showGridLines)
|
||||
//
|
||||
// var showGridLines excelize.ShowGridLines
|
||||
// err = f.GetSheetViewOptions("Sheet1", -1, &showGridLines)
|
||||
func (f *File) GetSheetViewOptions(sheet string, viewIndex int, opts ...SheetViewOptionPtr) error {
|
||||
view, err := f.getSheetView(sheet, viewIndex)
|
||||
if err != nil {
|
||||
|
|
39
sparkline.go
39
sparkline.go
|
@ -365,29 +365,28 @@ func (f *File) addSparklineGroupByStyle(ID int) *xlsxX14SparklineGroup {
|
|||
// Excel 2007, but they won't be displayed. For example, add a grouped
|
||||
// sparkline. Changes are applied to all three:
|
||||
//
|
||||
// err := f.AddSparkline("Sheet1", &excelize.SparklineOption{
|
||||
// Location: []string{"A1", "A2", "A3"},
|
||||
// Range: []string{"Sheet2!A1:J1", "Sheet2!A2:J2", "Sheet2!A3:J3"},
|
||||
// Markers: true,
|
||||
// })
|
||||
// err := f.AddSparkline("Sheet1", &excelize.SparklineOption{
|
||||
// Location: []string{"A1", "A2", "A3"},
|
||||
// Range: []string{"Sheet2!A1:J1", "Sheet2!A2:J2", "Sheet2!A3:J3"},
|
||||
// Markers: true,
|
||||
// })
|
||||
//
|
||||
// The following shows the formatting options of sparkline supported by excelize:
|
||||
//
|
||||
// Parameter | Description
|
||||
// -----------+--------------------------------------------
|
||||
// Location | Required, must have the same number with 'Range' parameter
|
||||
// Range | Required, must have the same number with 'Location' parameter
|
||||
// Type | Enumeration value: line, column, win_loss
|
||||
// Style | Value range: 0 - 35
|
||||
// Hight | Toggle sparkline high points
|
||||
// Low | Toggle sparkline low points
|
||||
// First | Toggle sparkline first points
|
||||
// Last | Toggle sparkline last points
|
||||
// Negative | Toggle sparkline negative points
|
||||
// Markers | Toggle sparkline markers
|
||||
// ColorAxis | An RGB Color is specified as RRGGBB
|
||||
// Axis | Show sparkline axis
|
||||
//
|
||||
// Parameter | Description
|
||||
// -----------+--------------------------------------------
|
||||
// Location | Required, must have the same number with 'Range' parameter
|
||||
// Range | Required, must have the same number with 'Location' parameter
|
||||
// Type | Enumeration value: line, column, win_loss
|
||||
// Style | Value range: 0 - 35
|
||||
// Hight | Toggle sparkline high points
|
||||
// Low | Toggle sparkline low points
|
||||
// First | Toggle sparkline first points
|
||||
// Last | Toggle sparkline last points
|
||||
// Negative | Toggle sparkline negative points
|
||||
// Markers | Toggle sparkline markers
|
||||
// ColorAxis | An RGB Color is specified as RRGGBB
|
||||
// Axis | Show sparkline axis
|
||||
func (f *File) AddSparkline(sheet string, opt *SparklineOption) (err error) {
|
||||
var (
|
||||
ws *xlsxWorksheet
|
||||
|
|
94
stream.go
94
stream.go
|
@ -47,49 +47,48 @@ type StreamWriter struct {
|
|||
// example, set data for worksheet of size 102400 rows x 50 columns with
|
||||
// numbers and style:
|
||||
//
|
||||
// file := excelize.NewFile()
|
||||
// streamWriter, err := file.NewStreamWriter("Sheet1")
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
// styleID, err := file.NewStyle(&excelize.Style{Font: &excelize.Font{Color: "#777777"}})
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
// if err := streamWriter.SetRow("A1", []interface{}{excelize.Cell{StyleID: styleID, Value: "Data"}},
|
||||
// excelize.RowOpts{Height: 45, Hidden: false}); err != nil {
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
// for rowID := 2; rowID <= 102400; rowID++ {
|
||||
// row := make([]interface{}, 50)
|
||||
// for colID := 0; colID < 50; colID++ {
|
||||
// row[colID] = rand.Intn(640000)
|
||||
// }
|
||||
// cell, _ := excelize.CoordinatesToCellName(1, rowID)
|
||||
// if err := streamWriter.SetRow(cell, row); err != nil {
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
// }
|
||||
// if err := streamWriter.Flush(); err != nil {
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
// if err := file.SaveAs("Book1.xlsx"); err != nil {
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
// file := excelize.NewFile()
|
||||
// streamWriter, err := file.NewStreamWriter("Sheet1")
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
// styleID, err := file.NewStyle(&excelize.Style{Font: &excelize.Font{Color: "#777777"}})
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
// if err := streamWriter.SetRow("A1", []interface{}{excelize.Cell{StyleID: styleID, Value: "Data"}},
|
||||
// excelize.RowOpts{Height: 45, Hidden: false}); err != nil {
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
// for rowID := 2; rowID <= 102400; rowID++ {
|
||||
// row := make([]interface{}, 50)
|
||||
// for colID := 0; colID < 50; colID++ {
|
||||
// row[colID] = rand.Intn(640000)
|
||||
// }
|
||||
// cell, _ := excelize.CoordinatesToCellName(1, rowID)
|
||||
// if err := streamWriter.SetRow(cell, row); err != nil {
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
// }
|
||||
// if err := streamWriter.Flush(); err != nil {
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
// if err := file.SaveAs("Book1.xlsx"); err != nil {
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
//
|
||||
// Set cell value and cell formula for a worksheet with stream writer:
|
||||
//
|
||||
// err := streamWriter.SetRow("A1", []interface{}{
|
||||
// excelize.Cell{Value: 1},
|
||||
// excelize.Cell{Value: 2},
|
||||
// excelize.Cell{Formula: "SUM(A1,B1)"}});
|
||||
// err := streamWriter.SetRow("A1", []interface{}{
|
||||
// excelize.Cell{Value: 1},
|
||||
// excelize.Cell{Value: 2},
|
||||
// excelize.Cell{Formula: "SUM(A1,B1)"}});
|
||||
//
|
||||
// Set cell value and rows style for a worksheet with stream writer:
|
||||
//
|
||||
// err := streamWriter.SetRow("A1", []interface{}{
|
||||
// excelize.Cell{Value: 1}},
|
||||
// excelize.RowOpts{StyleID: styleID, Height: 20, Hidden: false});
|
||||
//
|
||||
// err := streamWriter.SetRow("A1", []interface{}{
|
||||
// excelize.Cell{Value: 1}},
|
||||
// excelize.RowOpts{StyleID: styleID, Height: 20, Hidden: false});
|
||||
func (f *File) NewStreamWriter(sheet string) (*StreamWriter, error) {
|
||||
sheetID := f.getSheetID(sheet)
|
||||
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
|
||||
// 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:
|
||||
//
|
||||
// err := sw.AddTable("F2", "H6", `{
|
||||
// "table_name": "table",
|
||||
// "table_style": "TableStyleMedium2",
|
||||
// "show_first_column": true,
|
||||
// "show_last_column": true,
|
||||
// "show_row_stripes": false,
|
||||
// "show_column_stripes": true
|
||||
// }`)
|
||||
// err := sw.AddTable("F2", "H6", `{
|
||||
// "table_name": "table",
|
||||
// "table_style": "TableStyleMedium2",
|
||||
// "show_first_column": true,
|
||||
// "show_last_column": true,
|
||||
// "show_row_stripes": false,
|
||||
// "show_column_stripes": true
|
||||
// }`)
|
||||
//
|
||||
// Note that the table must be at least two lines including the header. The
|
||||
// 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 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 {
|
||||
if sw.sheetWritten {
|
||||
return ErrStreamSetColWidth
|
||||
|
|
83
table.go
83
table.go
|
@ -32,18 +32,18 @@ func parseFormatTableSet(formatSet string) (*formatTable, error) {
|
|||
// name, coordinate area and format set. For example, create a table of A1:D5
|
||||
// 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:
|
||||
//
|
||||
// err := f.AddTable("Sheet2", "F2", "H6", `{
|
||||
// "table_name": "table",
|
||||
// "table_style": "TableStyleMedium2",
|
||||
// "show_first_column": true,
|
||||
// "show_last_column": true,
|
||||
// "show_row_stripes": false,
|
||||
// "show_column_stripes": true
|
||||
// }`)
|
||||
// err := f.AddTable("Sheet2", "F2", "H6", `{
|
||||
// "table_name": "table",
|
||||
// "table_style": "TableStyleMedium2",
|
||||
// "show_first_column": true,
|
||||
// "show_last_column": true,
|
||||
// "show_row_stripes": false,
|
||||
// "show_column_stripes": true
|
||||
// }`)
|
||||
//
|
||||
// Note that the table must be at least two lines including the header. 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
|
||||
//
|
||||
// TableStyleLight1 - TableStyleLight21
|
||||
// TableStyleMedium1 - TableStyleMedium28
|
||||
// TableStyleDark1 - TableStyleDark11
|
||||
//
|
||||
// TableStyleLight1 - TableStyleLight21
|
||||
// TableStyleMedium1 - TableStyleMedium28
|
||||
// TableStyleDark1 - TableStyleDark11
|
||||
func (f *File) AddTable(sheet, hCell, vCell, format string) error {
|
||||
formatSet, err := parseFormatTableSet(format)
|
||||
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
|
||||
// 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:
|
||||
//
|
||||
// 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
|
||||
// criteria
|
||||
|
@ -235,38 +234,38 @@ func parseAutoFilterSet(formatSet string) (*formatAutoFilter, error) {
|
|||
// expression defines the conditions, the following operators are available
|
||||
// for setting the filter criteria:
|
||||
//
|
||||
// ==
|
||||
// !=
|
||||
// >
|
||||
// <
|
||||
// >=
|
||||
// <=
|
||||
// and
|
||||
// or
|
||||
// ==
|
||||
// !=
|
||||
// >
|
||||
// <
|
||||
// >=
|
||||
// <=
|
||||
// and
|
||||
// or
|
||||
//
|
||||
// An expression can comprise a single statement or two statements separated
|
||||
// by the 'and' and 'or' operators. For example:
|
||||
//
|
||||
// x < 2000
|
||||
// x > 2000
|
||||
// x == 2000
|
||||
// x > 2000 and x < 5000
|
||||
// x == 2000 or x == 5000
|
||||
// x < 2000
|
||||
// x > 2000
|
||||
// x == 2000
|
||||
// x > 2000 and x < 5000
|
||||
// x == 2000 or x == 5000
|
||||
//
|
||||
// Filtering of blank or non-blank data can be achieved by using a value of
|
||||
// Blanks or NonBlanks in the expression:
|
||||
//
|
||||
// x == Blanks
|
||||
// x == NonBlanks
|
||||
// x == Blanks
|
||||
// x == NonBlanks
|
||||
//
|
||||
// Excel also allows some simple string matching operations:
|
||||
//
|
||||
// x == b* // begins with b
|
||||
// x != b* // doesn't begin with b
|
||||
// x == *b // ends with b
|
||||
// x != *b // doesn't end with b
|
||||
// x == *b* // contains b
|
||||
// x != *b* // doesn't contains b
|
||||
// x == b* // begins with b
|
||||
// x != b* // doesn't begin with b
|
||||
// x == *b // ends with b
|
||||
// x != *b // doesn't end with b
|
||||
// x == *b* // contains b
|
||||
// x != *b* // doesn't contains b
|
||||
//
|
||||
// You can also use '*' to match any character or number and '?' to match any
|
||||
// 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
|
||||
// following are all equivalent:
|
||||
//
|
||||
// x < 2000
|
||||
// col < 2000
|
||||
// Price < 2000
|
||||
//
|
||||
// x < 2000
|
||||
// col < 2000
|
||||
// Price < 2000
|
||||
func (f *File) AutoFilter(sheet, hCell, vCell, format string) error {
|
||||
hCol, hRow, err := CellNameToCoordinates(hCell)
|
||||
if err != nil {
|
||||
|
@ -436,9 +434,8 @@ func (f *File) writeCustomFilter(filter *xlsxAutoFilter, operator int, val strin
|
|||
//
|
||||
// Examples:
|
||||
//
|
||||
// ('x', '==', 2000) -> exp1
|
||||
// ('x', '>', 2000, 'and', 'x', '<', 5000) -> exp1 and exp2
|
||||
//
|
||||
// ('x', '==', 2000) -> exp1
|
||||
// ('x', '>', 2000, 'and', 'x', '<', 5000) -> exp1 and exp2
|
||||
func (f *File) parseFilterExpression(expression string, tokens []string) ([]int, []string, error) {
|
||||
var expressions []int
|
||||
var t []string
|
||||
|
|
14
workbook.go
14
workbook.go
|
@ -120,9 +120,10 @@ func (f *File) workBookWriter() {
|
|||
// SetWorkbookPrOptions provides a function to sets workbook properties.
|
||||
//
|
||||
// Available options:
|
||||
// Date1904(bool)
|
||||
// FilterPrivacy(bool)
|
||||
// CodeName(string)
|
||||
//
|
||||
// Date1904(bool)
|
||||
// FilterPrivacy(bool)
|
||||
// CodeName(string)
|
||||
func (f *File) SetWorkbookPrOptions(opts ...WorkbookPrOption) error {
|
||||
wb := f.workbookReader()
|
||||
pr := wb.WorkbookPr
|
||||
|
@ -154,9 +155,10 @@ func (o CodeName) setWorkbookPrOption(pr *xlsxWorkbookPr) {
|
|||
// GetWorkbookPrOptions provides a function to gets workbook properties.
|
||||
//
|
||||
// Available options:
|
||||
// Date1904(bool)
|
||||
// FilterPrivacy(bool)
|
||||
// CodeName(string)
|
||||
//
|
||||
// Date1904(bool)
|
||||
// FilterPrivacy(bool)
|
||||
// CodeName(string)
|
||||
func (f *File) GetWorkbookPrOptions(opts ...WorkbookPrOptionPtr) error {
|
||||
wb := f.workbookReader()
|
||||
pr := wb.WorkbookPr
|
||||
|
|
107
xmlCalcChain.go
107
xmlCalcChain.go
|
@ -21,60 +21,59 @@ type xlsxCalcChain struct {
|
|||
|
||||
// xlsxCalcChainC directly maps the c element.
|
||||
//
|
||||
// Attributes | Attributes
|
||||
// --------------------------+----------------------------------------------------------
|
||||
// a (Array) | A Boolean flag indicating whether the cell's formula
|
||||
// | is an array formula. True if this cell's formula is
|
||||
// | an array formula, false otherwise. If there is a
|
||||
// | conflict between this attribute and the t attribute
|
||||
// | of the f element (§18.3.1.40), the t attribute takes
|
||||
// | precedence. The possible values for this attribute
|
||||
// | 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
|
||||
// | omitted, it is assumed to be the same as the i value
|
||||
// | of the previous cell.The possible values for this
|
||||
// | attribute are defined by the W3C XML Schema int datatype.
|
||||
// |
|
||||
// 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, false otherwise.
|
||||
// | Starting a new dependency level means that all
|
||||
// | concurrent calculations, and child calculations, shall
|
||||
// | be completed - and the cells have new values - before
|
||||
// | the calc chain can continue. In other words, this
|
||||
// | dependency level might depend on levels that came before
|
||||
// | it, and any later dependency levels might depend on
|
||||
// | this level; but not later dependency levels can have
|
||||
// | any calculations started until this dependency level
|
||||
// | completes.The possible values for this attribute are
|
||||
// | defined by the W3C XML Schema boolean datatype.
|
||||
// |
|
||||
// r (Cell Reference) | An A-1 style reference to a cell.The possible values
|
||||
// | for this attribute are defined by the ST_CellRef
|
||||
// | simple type (§18.18.7).
|
||||
// |
|
||||
// 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
|
||||
// | child chain, false otherwise. If this is omitted, it
|
||||
// | is assumed to be the same as the s value of the
|
||||
// | previous cell .A child chain is a list of calculations
|
||||
// | that occur which depend on the parent to the chain.
|
||||
// | There shall not be cross dependencies between child
|
||||
// | chains. Child chains are not the same as dependency
|
||||
// | levels - a child chain and its parent are all on the
|
||||
// | same dependency level. Child chains are series of
|
||||
// | calculations that can be independently farmed out to
|
||||
// | other threads or processors.The possible values for
|
||||
// | this attribute is defined by the W3C XML Schema
|
||||
// | boolean datatype.
|
||||
// |
|
||||
// t (New Thread) | A Boolean flag indicating whether the cell's formula
|
||||
// | starts a new thread. True if the cell's formula starts
|
||||
// | a new thread, false otherwise.The possible values for
|
||||
// | this attribute is defined by the W3C XML Schema
|
||||
// | boolean datatype.
|
||||
//
|
||||
// Attributes | Attributes
|
||||
// --------------------------+----------------------------------------------------------
|
||||
// a (Array) | A Boolean flag indicating whether the cell's formula
|
||||
// | is an array formula. True if this cell's formula is
|
||||
// | an array formula, false otherwise. If there is a
|
||||
// | conflict between this attribute and the t attribute
|
||||
// | of the f element (§18.3.1.40), the t attribute takes
|
||||
// | precedence. The possible values for this attribute
|
||||
// | 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
|
||||
// | omitted, it is assumed to be the same as the i value
|
||||
// | of the previous cell.The possible values for this
|
||||
// | attribute are defined by the W3C XML Schema int datatype.
|
||||
// |
|
||||
// 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, false otherwise.
|
||||
// | Starting a new dependency level means that all
|
||||
// | concurrent calculations, and child calculations, shall
|
||||
// | be completed - and the cells have new values - before
|
||||
// | the calc chain can continue. In other words, this
|
||||
// | dependency level might depend on levels that came before
|
||||
// | it, and any later dependency levels might depend on
|
||||
// | this level; but not later dependency levels can have
|
||||
// | any calculations started until this dependency level
|
||||
// | completes.The possible values for this attribute are
|
||||
// | defined by the W3C XML Schema boolean datatype.
|
||||
// |
|
||||
// r (Cell Reference) | An A-1 style reference to a cell.The possible values
|
||||
// | for this attribute are defined by the ST_CellRef
|
||||
// | simple type (§18.18.7).
|
||||
// |
|
||||
// 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
|
||||
// | child chain, false otherwise. If this is omitted, it
|
||||
// | is assumed to be the same as the s value of the
|
||||
// | previous cell .A child chain is a list of calculations
|
||||
// | that occur which depend on the parent to the chain.
|
||||
// | There shall not be cross dependencies between child
|
||||
// | chains. Child chains are not the same as dependency
|
||||
// | levels - a child chain and its parent are all on the
|
||||
// | same dependency level. Child chains are series of
|
||||
// | calculations that can be independently farmed out to
|
||||
// | other threads or processors.The possible values for
|
||||
// | this attribute is defined by the W3C XML Schema
|
||||
// | boolean datatype.
|
||||
// |
|
||||
// t (New Thread) | A Boolean flag indicating whether the cell's formula
|
||||
// | starts a new thread. True if the cell's formula starts
|
||||
// | a new thread, false otherwise.The possible values for
|
||||
// | this attribute is defined by the W3C XML Schema
|
||||
// | boolean datatype.
|
||||
type xlsxCalcChainC struct {
|
||||
R string `xml:"r,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:
|
||||
//
|
||||
// Enumeration Value | Description
|
||||
// ---------------------------+---------------------------------
|
||||
// b (Boolean) | Cell containing a boolean.
|
||||
// d (Date) | Cell contains a date in the ISO 8601 format.
|
||||
// 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).
|
||||
// n (Number) | Cell containing a number.
|
||||
// s (Shared String) | Cell containing a shared string.
|
||||
// str (String) | Cell containing a formula string.
|
||||
//
|
||||
// Enumeration Value | Description
|
||||
// ---------------------------+---------------------------------
|
||||
// b (Boolean) | Cell containing a boolean.
|
||||
// d (Date) | Cell contains a date in the ISO 8601 format.
|
||||
// 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).
|
||||
// n (Number) | Cell containing a number.
|
||||
// s (Shared String) | Cell containing a shared string.
|
||||
// str (String) | Cell containing a formula string.
|
||||
type xlsxC struct {
|
||||
XMLName xml.Name `xml:"c"`
|
||||
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,
|
||||
// of course after having created and stored the table part. For example:
|
||||
//
|
||||
// <worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
|
||||
// ...
|
||||
// <tableParts count="1">
|
||||
// <tablePart r:id="rId1" />
|
||||
// </tableParts>
|
||||
// </worksheet>
|
||||
//
|
||||
// <worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
|
||||
// ...
|
||||
// <tableParts count="1">
|
||||
// <tablePart r:id="rId1" />
|
||||
// </tableParts>
|
||||
// </worksheet>
|
||||
type xlsxTableParts struct {
|
||||
XMLName xml.Name `xml:"tableParts"`
|
||||
Count int `xml:"count,attr,omitempty"`
|
||||
|
@ -667,8 +665,7 @@ type xlsxTablePart struct {
|
|||
// http://schemas.openxmlformats.org/spreadsheetml/2006/main - Background sheet
|
||||
// image. For example:
|
||||
//
|
||||
// <picture r:id="rId1"/>
|
||||
//
|
||||
// <picture r:id="rId1"/>
|
||||
type xlsxPicture struct {
|
||||
XMLName xml.Name `xml:"picture"`
|
||||
RID string `xml:"http://schemas.openxmlformats.org/officeDocument/2006/relationships id,attr,omitempty"`
|
||||
|
|
Loading…
Reference in New Issue