summaryrefslogtreecommitdiff
path: root/comment.go
diff options
context:
space:
mode:
Diffstat (limited to 'comment.go')
-rw-r--r--comment.go32
1 files changed, 27 insertions, 5 deletions
diff --git a/comment.go b/comment.go
index 8bf4fd3..9031aad 100644
--- a/comment.go
+++ b/comment.go
@@ -1,3 +1,12 @@
+// Copyright 2016 - 2018 The excelize Authors. All rights reserved. Use of
+// this source code is governed by a BSD-style license that can be found in
+// the LICENSE file.
+//
+// Package excelize providing a set of functions that allow you to write to
+// and read from XLSX files. Support reads and writes XLSX file generated by
+// Microsoft Excelâ„¢ 2007 and later. Support save file without losing original
+// charts of XLSX. This library needs Go version 1.8 or later.
+
package excelize
import (
@@ -21,8 +30,8 @@ func parseFormatCommentsSet(formatSet string) (*formatComment, error) {
// GetComments retrieves 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{}
+func (f *File) GetComments() (comments map[string][]Comment) {
+ comments = map[string][]Comment{}
for n := range f.sheetMap {
commentID := f.GetSheetIndex(n)
commentsXML := "xl/comments" + strconv.Itoa(commentID) + ".xml"
@@ -30,7 +39,20 @@ func (f *File) GetComments() (comments map[string]*xlsxComments) {
if ok {
d := xlsxComments{}
xml.Unmarshal([]byte(c), &d)
- comments[n] = &d
+ sheetComments := []Comment{}
+ for _, comment := range d.CommentList.Comment {
+ sheetComment := Comment{}
+ if comment.AuthorID < len(d.Authors) {
+ sheetComment.Author = d.Authors[comment.AuthorID].Author
+ }
+ sheetComment.Ref = comment.Ref
+ sheetComment.AuthorID = comment.AuthorID
+ for _, text := range comment.Text.R {
+ sheetComment.Text += text.T
+ }
+ sheetComments = append(sheetComments, sheetComment)
+ }
+ comments[n] = sheetComments
}
}
return
@@ -160,7 +182,7 @@ func (f *File) addDrawingVML(commentID int, drawingVML, cell string, lineCount,
c, ok := f.XLSX[drawingVML]
if ok {
d := decodeVmlDrawing{}
- _ = xml.Unmarshal([]byte(c), &d)
+ _ = xml.Unmarshal(namespaceStrictToTransitional(c), &d)
for _, v := range d.Shape {
s := xlsxShape{
ID: "_x0000_s1025",
@@ -230,7 +252,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(namespaceStrictToTransitional(c), &d)
comments.CommentList.Comment = append(comments.CommentList.Comment, d.CommentList.Comment...)
}
comments.CommentList.Comment = append(comments.CommentList.Comment, cmt)