From 40ff5dc1a7d7aa42f5db9cf9dfe858cc3820b44e Mon Sep 17 00:00:00 2001 From: xuri Date: Sat, 23 Mar 2019 20:08:06 +0800 Subject: refactor: handler error instead of panic, Exported functions: SetCellStyle InsertCol RemoveCol RemoveRow InsertRow DuplicateRow DuplicateRowTo SetRowHeight GetRowHeight GetCellValue GetCellFormula GetCellHyperLink SetCellHyperLink SetCellInt SetCellBool SetCellFloat SetCellStr SetCellDefault GetCellStyle SetCellValue MergeCell SetSheetRow SetRowVisible GetRowVisible SetRowOutlineLevel GetRowOutlineLevel GetRows Columns SearchSheet AddTable GetPicture AutoFilter GetColVisible SetColVisible GetColOutlineLevel SetColOutlineLevel SetColWidth GetColWidth inner functions: adjustHelper adjustMergeCells adjustAutoFilter prepareCell setDefaultTimeStyle timeToExcelTime addDrawingChart addDrawingVML addDrawingPicture getTotalRowsCols checkRow addDrawingShape addTable --- lib.go | 53 ++++++----------------------------------------------- 1 file changed, 6 insertions(+), 47 deletions(-) (limited to 'lib.go') diff --git a/lib.go b/lib.go index 809a16b..ad4f79a 100644 --- a/lib.go +++ b/lib.go @@ -135,22 +135,6 @@ func ColumnNameToNumber(name string) (int, error) { return col, nil } -// MustColumnNameToNumber provides a function to convert Excel sheet column -// name to int. Column name case insencitive. -// Function returns error if column name incorrect. -// -// Example: -// -// excelize.MustColumnNameToNumber("AK") // returns 37 -// -func MustColumnNameToNumber(name string) int { - n, err := ColumnNameToNumber(name) - if err != nil { - panic(err) - } - return n -} - // ColumnNumberToName provides a function to convert integer // to Excel sheet column title. // @@ -174,8 +158,9 @@ func ColumnNumberToName(num int) (string, error) { // to [X, Y] coordinates or retrusn an error. // // Example: -// CellCoordinates("A1") // returns 1, 1, nil -// CellCoordinates("Z3") // returns 26, 3, nil +// +// CellCoordinates("A1") // returns 1, 1, nil +// CellCoordinates("Z3") // returns 26, 3, nil // func CellNameToCoordinates(cell string) (int, int, error) { const msg = "cannot convert cell %q to coordinates: %v" @@ -193,25 +178,12 @@ func CellNameToCoordinates(cell string) (int, int, error) { return col, row, nil } -// MustCellNameToCoordinates converts alpha-numeric cell name -// to [X, Y] coordinates or panics. +// CoordinatesToCellName converts [X, Y] coordinates to alpha-numeric cell +// name or returns an error. // // Example: -// MustCellNameToCoordinates("A1") // returns 1, 1 -// MustCellNameToCoordinates("Z3") // returns 26, 3 // -func MustCellNameToCoordinates(cell string) (int, int) { - c, r, err := CellNameToCoordinates(cell) - if err != nil { - panic(err) - } - return c, r -} - -// CoordinatesToCellName converts [X, Y] coordinates to alpha-numeric cell name or returns an error. -// -// Example: -// CoordinatesToCellName(1, 1) // returns "A1", nil +// CoordinatesToCellName(1, 1) // returns "A1", nil // func CoordinatesToCellName(col, row int) (string, error) { if col < 1 || row < 1 { @@ -224,19 +196,6 @@ func CoordinatesToCellName(col, row int) (string, error) { return fmt.Sprintf("%s%d", colname, row), nil } -// MustCoordinatesToCellName converts [X, Y] coordinates to alpha-numeric cell name or panics. -// -// Example: -// MustCoordinatesToCellName(1, 1) // returns "A1" -// -func MustCoordinatesToCellName(col, row int) string { - n, err := CoordinatesToCellName(col, row) - if err != nil { - panic(err) - } - return n -} - // boolPtr returns a pointer to a bool with the given value. func boolPtr(b bool) *bool { return &b } -- cgit v1.2.1