From 9e463b4614348b3ddc04b1fedd5d662845ce0fb9 Mon Sep 17 00:00:00 2001 From: xuri <xuri.me@gmail.com> Date: Sun, 27 May 2018 11:25:55 +0800 Subject: - Add error return value for functions: `AddChart()`, `AddComment()`, `AddPicture()`, `AddShape()`, `AddTable()` and `SetConditionalFormat()` - go test has been updated --- shape.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'shape.go') diff --git a/shape.go b/shape.go index 0b93752..96cedb4 100644 --- a/shape.go +++ b/shape.go @@ -9,7 +9,7 @@ import ( // parseFormatShapeSet provides function to parse the format settings of the // shape with default value. -func parseFormatShapeSet(formatSet string) *formatShape { +func parseFormatShapeSet(formatSet string) (*formatShape, error) { format := formatShape{ Width: 160, Height: 160, @@ -23,8 +23,8 @@ func parseFormatShapeSet(formatSet string) *formatShape { YScale: 1.0, }, } - json.Unmarshal([]byte(formatSet), &format) - return &format + err := json.Unmarshal([]byte(formatSet), &format) + return &format, err } // AddShape provides the method to add shape in a sheet by given worksheet @@ -245,8 +245,11 @@ func parseFormatShapeSet(formatSet string) *formatShape { // wavyHeavy // wavyDbl // -func (f *File) AddShape(sheet, cell, format string) { - formatSet := parseFormatShapeSet(format) +func (f *File) AddShape(sheet, cell, format string) error { + formatSet, err := parseFormatShapeSet(format) + if err != nil { + return err + } // Read sheet data. xlsx := f.workSheetReader(sheet) // Add first shape for given sheet, create xl/drawings/ and xl/drawings/_rels/ folder. @@ -266,6 +269,7 @@ func (f *File) AddShape(sheet, cell, format string) { } f.addDrawingShape(sheet, drawingXML, cell, formatSet) f.addContentTypePart(drawingID, "drawings") + return err } // addDrawingShape provides function to add preset geometry by given sheet, -- cgit v1.2.1