From e3050d21e7c645ba8ee88c9e0f32dd241e1c4cc3 Mon Sep 17 00:00:00 2001 From: Rad Cirskis Date: Sat, 30 Jun 2018 22:37:14 +1200 Subject: [PATCH 1/2] added retieval of worksheet comments --- comment.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/comment.go b/comment.go index 9548d78..bab7370 100644 --- a/comment.go +++ b/comment.go @@ -19,6 +19,23 @@ func parseFormatCommentsSet(formatSet string) (*formatComment, error) { return &format, err } +// GetComments retrievs all comments and returns a map +// of worksheet name to the worksheet comments. +func (f *File) GetComments() (comments map[string]*xlsxComments) { + comments = map[string]*xlsxComments{} + for n := range f.sheetMap { + commentID := f.GetSheetIndex(n) + commentsXML := "xl/comments" + strconv.Itoa(commentID) + ".xml" + c, ok := f.XLSX[commentsXML] + if ok { + d := xlsxComments{} + xml.Unmarshal([]byte(c), &d) + comments[n] = &d + } + } + return +} + // AddComment provides the method to add comment in a sheet by given worksheet // index, cell and format set (such as author and text). Note that the max // author length is 255 and the max text length is 32512. For example, add a From 1a953b6601df2484a39203edff59943e41e3f438 Mon Sep 17 00:00:00 2001 From: Rad Cirskis Date: Sat, 30 Jun 2018 22:55:14 +1200 Subject: [PATCH 2/2] added unit tests --- excelize_test.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/excelize_test.go b/excelize_test.go index aca33b4..0bcb16d 100644 --- a/excelize_test.go +++ b/excelize_test.go @@ -816,6 +816,11 @@ func TestAddComments(t *testing.T) { if err != nil { t.Error(err) } + allComments := xlsx.GetComments() + if len(allComments) != 2 { + t.Error("Expected 2 comment entry elements.") + } + } func TestAutoFilter(t *testing.T) {