diff options
Diffstat (limited to 'col.go')
-rw-r--r-- | col.go | 132 |
1 files changed, 61 insertions, 71 deletions
@@ -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 |