summaryrefslogtreecommitdiff
path: root/comment.go
diff options
context:
space:
mode:
authorxuri <xuri.me@gmail.com>2019-02-23 16:20:44 +0800
committerxuri <xuri.me@gmail.com>2019-02-23 16:20:44 +0800
commitc223815cfe88e2cdfe3631860a6936e94229f779 (patch)
treeda3b08657169568121e3cd2fdfd3ac622819b8f2 /comment.go
parent0072bb731043f89ce978778b9d7fdc6160e29de0 (diff)
Resolve #345, get comments by target reference
Diffstat (limited to 'comment.go')
-rw-r--r--comment.go18
1 files changed, 15 insertions, 3 deletions
diff --git a/comment.go b/comment.go
index 07f70b5..42e7d45 100644
--- a/comment.go
+++ b/comment.go
@@ -33,9 +33,7 @@ func parseFormatCommentsSet(formatSet string) (*formatComment, error) {
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"
- c, ok := f.XLSX[commentsXML]
+ c, ok := f.XLSX["xl"+strings.TrimPrefix(f.getSheetComments(f.GetSheetIndex(n)), "..")]
if ok {
d := xlsxComments{}
xml.Unmarshal([]byte(c), &d)
@@ -58,6 +56,20 @@ func (f *File) GetComments() (comments map[string][]Comment) {
return
}
+// 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"
+ var sheetRels xlsxWorkbookRels
+ _ = xml.Unmarshal(namespaceStrictToTransitional(f.readXML(rels)), &sheetRels)
+ for _, v := range sheetRels.Relationships {
+ if v.Type == SourceRelationshipComments {
+ return v.Target
+ }
+ }
+ 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