summaryrefslogtreecommitdiff
path: root/comment.go
diff options
context:
space:
mode:
authorxuri <xuri.me@gmail.com>2018-06-28 10:05:57 +0800
committerGitHub <noreply@github.com>2018-06-28 10:05:57 +0800
commit07d568aa442f49d5d59703945319cd444154466e (patch)
tree1d60aa4c5fe532c1f4b40e22b931c64375d594b3 /comment.go
parent13cf7a3b0316f7ca0f7554d22b0f06b53b41a168 (diff)
parent74c6091cfc4e023975018fb434a3a492fdcb5c76 (diff)
Merge pull request #241 from nad2000/issues/238
improved comment formatting
Diffstat (limited to 'comment.go')
-rw-r--r--comment.go26
1 files changed, 19 insertions, 7 deletions
diff --git a/comment.go b/comment.go
index b597da1..9548d78 100644
--- a/comment.go
+++ b/comment.go
@@ -3,6 +3,7 @@ package excelize
import (
"encoding/json"
"encoding/xml"
+ "fmt"
"strconv"
"strings"
)
@@ -49,14 +50,23 @@ func (f *File) AddComment(sheet, cell, format string) error {
}
commentsXML := "xl/comments" + strconv.Itoa(commentID) + ".xml"
f.addComment(commentsXML, cell, formatSet)
- f.addDrawingVML(commentID, drawingVML, cell)
+ var colCount int
+ for i, l := range strings.Split(formatSet.Text, "\n") {
+ if ll := len(l); ll > colCount {
+ if i == 0 {
+ ll += len(formatSet.Author)
+ }
+ colCount = ll
+ }
+ }
+ f.addDrawingVML(commentID, drawingVML, cell, strings.Count(formatSet.Text, "\n")+1, colCount)
f.addContentTypePart(commentID, "comments")
return err
}
// addDrawingVML provides function to create comment as
// xl/drawings/vmlDrawing%d.vml by given commit ID and cell.
-func (f *File) addDrawingVML(commentID int, drawingVML, cell string) {
+func (f *File) addDrawingVML(commentID int, drawingVML, cell string, lineCount, colCount int) {
col := string(strings.Map(letterOnlyMapF, cell))
row, _ := strconv.Atoi(strings.Map(intOnlyMapF, cell))
xAxis := row - 1
@@ -83,7 +93,7 @@ func (f *File) addDrawingVML(commentID int, drawingVML, cell string) {
},
VPath: &vPath{
Gradientshapeok: "t",
- Connecttype: "rect",
+ Connecttype: "miter",
},
},
}
@@ -113,10 +123,12 @@ func (f *File) addDrawingVML(commentID int, drawingVML, cell string) {
},
ClientData: &xClientData{
ObjectType: "Note",
- Anchor: "3, 15, 8, 6, 4, 54, 13, 2",
- AutoFill: "False",
- Row: xAxis,
- Column: yAxis,
+ Anchor: fmt.Sprintf(
+ "%d, 23, %d, 0, %d, %d, %d, 5",
+ 1+yAxis, 1+xAxis, 2+yAxis+lineCount, colCount+yAxis, 2+xAxis+lineCount),
+ AutoFill: "True",
+ Row: xAxis,
+ Column: yAxis,
},
}
s, _ := xml.Marshal(sp)