diff options
author | xuri <xuri.me@gmail.com> | 2020-03-31 00:02:00 +0800 |
---|---|---|
committer | xuri <xuri.me@gmail.com> | 2020-03-31 00:02:00 +0800 |
commit | 3ce4b91be96589847823b6c1b6c123ba7880310f (patch) | |
tree | 1df0f8183d528cccafa677990b2f7624475837ae /comment.go | |
parent | 3f89c6e9799c9c82af1305f080416c53d19e64c1 (diff) |
Resolve #345, fix missing comments by GetComments
Diffstat (limited to 'comment.go')
-rw-r--r-- | comment.go | 13 |
1 files changed, 7 insertions, 6 deletions
@@ -16,6 +16,7 @@ import ( "fmt" "io" "log" + "path/filepath" "strconv" "strings" ) @@ -35,8 +36,8 @@ func parseFormatCommentsSet(formatSet string) (*formatComment, error) { // the worksheet comments. func (f *File) GetComments() (comments map[string][]Comment) { comments = map[string][]Comment{} - for n := range f.sheetMap { - if d := f.commentsReader("xl" + strings.TrimPrefix(f.getSheetComments(f.GetSheetIndex(n)), "..")); d != nil { + for n, path := range f.sheetMap { + if d := f.commentsReader("xl" + strings.TrimPrefix(f.getSheetComments(filepath.Base(path)), "..")); d != nil { sheetComments := []Comment{} for _, comment := range d.CommentList.Comment { sheetComment := Comment{} @@ -60,9 +61,9 @@ func (f *File) GetComments() (comments map[string][]Comment) { } // getSheetComments provides the method to get the target comment reference by -// given worksheet index. -func (f *File) getSheetComments(sheetID int) string { - var rels = "xl/worksheets/_rels/sheet" + strconv.Itoa(sheetID) + ".xml.rels" +// given worksheet file path. +func (f *File) getSheetComments(sheetFile string) string { + var rels = "xl/worksheets/_rels/" + sheetFile + ".rels" if sheetRels := f.relsReader(rels); sheetRels != nil { for _, v := range sheetRels.Relationships { if v.Type == SourceRelationshipComments { @@ -107,7 +108,6 @@ func (f *File) AddComment(sheet, cell, format string) error { f.addSheetLegacyDrawing(sheet, rID) } commentsXML := "xl/comments" + strconv.Itoa(commentID) + ".xml" - f.addComment(commentsXML, cell, formatSet) var colCount int for i, l := range strings.Split(formatSet.Text, "\n") { if ll := len(l); ll > colCount { @@ -121,6 +121,7 @@ func (f *File) AddComment(sheet, cell, format string) error { if err != nil { return err } + f.addComment(commentsXML, cell, formatSet) f.addContentTypePart(commentID, "comments") return err } |