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 --- excelize.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'excelize.go') diff --git a/excelize.go b/excelize.go index 7a50460..857f3ac 100644 --- a/excelize.go +++ b/excelize.go @@ -98,11 +98,16 @@ func OpenReader(r io.Reader) (*File, error) { // setDefaultTimeStyle provides a function to set default numbers format for // time.Time type cell value by given worksheet name, cell coordinates and // number format code. -func (f *File) setDefaultTimeStyle(sheet, axis string, format int) { - if f.GetCellStyle(sheet, axis) == 0 { +func (f *File) setDefaultTimeStyle(sheet, axis string, format int) error { + s, err := f.GetCellStyle(sheet, axis) + if err != nil { + return err + } + if s == 0 { style, _ := f.NewStyle(`{"number_format": ` + strconv.Itoa(format) + `}`) f.SetCellStyle(sheet, axis, axis, style) } + return err } // workSheetReader provides a function to get the pointer to the structure @@ -218,7 +223,8 @@ func (f *File) GetMergeCells(sheet string) []MergeCell { for i := range xlsx.MergeCells.Cells { ref := xlsx.MergeCells.Cells[i].Ref axis := strings.Split(ref, ":")[0] - mergeCells = append(mergeCells, []string{ref, f.GetCellValue(sheet, axis)}) + val, _ := f.GetCellValue(sheet, axis) + mergeCells = append(mergeCells, []string{ref, val}) } } -- cgit v1.2.1