summaryrefslogtreecommitdiff
path: root/comment.go
diff options
context:
space:
mode:
authorxuri <xuri.me@gmail.com>2018-05-27 11:25:55 +0800
committerxuri <xuri.me@gmail.com>2018-05-27 11:25:55 +0800
commit9e463b4614348b3ddc04b1fedd5d662845ce0fb9 (patch)
tree4ca438f66dcf3baa7d36727a3dd77400bc70aa57 /comment.go
parentaaced358f135ea871428bba87bb945cc170eee0f (diff)
- Add error return value for functions: `AddChart()`, `AddComment()`, `AddPicture()`, `AddShape()`, `AddTable()` and `SetConditionalFormat()`
- go test has been updated
Diffstat (limited to 'comment.go')
-rw-r--r--comment.go18
1 files changed, 11 insertions, 7 deletions
diff --git a/comment.go b/comment.go
index 41b4d6b..b597da1 100644
--- a/comment.go
+++ b/comment.go
@@ -9,13 +9,13 @@ import (
// parseFormatCommentsSet provides function to parse the format settings of the
// comment with default value.
-func parseFormatCommentsSet(formatSet string) *formatComment {
+func parseFormatCommentsSet(formatSet string) (*formatComment, error) {
format := formatComment{
Author: "Author:",
Text: " ",
}
- json.Unmarshal([]byte(formatSet), &format)
- return &format
+ err := json.Unmarshal([]byte(formatSet), &format)
+ return &format, err
}
// AddComment provides the method to add comment in a sheet by given worksheet
@@ -25,8 +25,11 @@ func parseFormatCommentsSet(formatSet string) *formatComment {
//
// xlsx.AddComment("Sheet1", "A30", `{"author":"Excelize: ","text":"This is a comment."}`)
//
-func (f *File) AddComment(sheet, cell, format string) {
- formatSet := parseFormatCommentsSet(format)
+func (f *File) AddComment(sheet, cell, format string) error {
+ formatSet, err := parseFormatCommentsSet(format)
+ if err != nil {
+ return err
+ }
// Read sheet data.
xlsx := f.workSheetReader(sheet)
commentID := f.countComments() + 1
@@ -48,6 +51,7 @@ func (f *File) AddComment(sheet, cell, format string) {
f.addComment(commentsXML, cell, formatSet)
f.addDrawingVML(commentID, drawingVML, cell)
f.addContentTypePart(commentID, "comments")
+ return err
}
// addDrawingVML provides function to create comment as
@@ -127,7 +131,7 @@ func (f *File) addDrawingVML(commentID int, drawingVML, cell string) {
c, ok := f.XLSX[drawingVML]
if ok {
d := decodeVmlDrawing{}
- xml.Unmarshal([]byte(c), &d)
+ _ = xml.Unmarshal([]byte(c), &d)
for _, v := range d.Shape {
s := xlsxShape{
ID: "_x0000_s1025",
@@ -197,7 +201,7 @@ func (f *File) addComment(commentsXML, cell string, formatSet *formatComment) {
c, ok := f.XLSX[commentsXML]
if ok {
d := xlsxComments{}
- xml.Unmarshal([]byte(c), &d)
+ _ = xml.Unmarshal([]byte(c), &d)
comments.CommentList.Comment = append(comments.CommentList.Comment, d.CommentList.Comment...)
}
comments.CommentList.Comment = append(comments.CommentList.Comment, cmt)