- The max author and text in comment limit added;

- go doc and go test updated
This commit is contained in:
Ri Xu 2017-05-13 14:12:43 +08:00
parent d93a156355
commit cf97118bfe
3 changed files with 24 additions and 6 deletions

View File

@ -168,10 +168,15 @@ func parseFormatChartSet(formatSet string) *formatChart {
// show_val
//
// show_bubble_size: Specifies the bubble size shall be shown in a data label. The show_bubble_size property is optional. The default value is false.
//
// show_cat_name: Specifies that the category name shall be shown in the data label. The show_cat_name property is optional. The default value is true.
//
// show_leader_lines: Specifies leader lines shall be shown for data labels. The show_leader_lines property is optional. The default value is false.
//
// show_percent: Specifies that the percentage shall be shown in a data label. The show_percent property is optional. The default value is false.
//
// show_series_name: Specifies that the series name shall be shown in a data label. The show_series_name property is optional. The default value is false.
//
// show_val: Specifies that the value shall be shown in a data label. The show_val property is optional. The default value is false.
//
func (f *File) AddChart(sheet, cell, format string) {

View File

@ -19,10 +19,11 @@ func parseFormatCommentsSet(formatSet string) *formatComment {
}
// AddComment provides the method to add comment in a sheet by given worksheet
// index, cell and format set (such as author and text). For example, add a
// 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
// comment in Sheet1!$A$30:
//
// xlsx.AddComment("Sheet1", "A30", `{"author":"Excelize","text":"This is a comment."}`)
// xlsx.AddComment("Sheet1", "A30", `{"author":"Excelize: ","text":"This is a comment."}`)
//
func (f *File) AddComment(sheet, cell, format string) {
formatSet := parseFormatCommentsSet(format)
@ -147,6 +148,14 @@ func (f *File) addDrawingVML(commentID int, drawingVML, cell string) {
// addComment provides function to create chart as xl/comments%d.xml by given
// cell and format sets.
func (f *File) addComment(commentsXML, cell string, formatSet *formatComment) {
a := formatSet.Author
t := formatSet.Text
if len(a) > 255 {
a = a[0:255]
}
if len(t) > 32512 {
t = t[0:32512]
}
comments := xlsxComments{
Authors: []xlsxAuthor{
xlsxAuthor{
@ -169,7 +178,7 @@ func (f *File) addComment(commentsXML, cell string, formatSet *formatComment) {
RFont: &attrValString{Val: "Calibri"},
Family: &attrValInt{Val: 2},
},
T: formatSet.Author + ": ",
T: a,
},
xlsxR{
RPr: &xlsxRPr{
@ -180,7 +189,7 @@ func (f *File) addComment(commentsXML, cell string, formatSet *formatComment) {
RFont: &attrValString{Val: "Calibri"},
Family: &attrValInt{Val: 2},
},
T: formatSet.Text,
T: t,
},
},
},

View File

@ -529,8 +529,12 @@ func TestAddComments(t *testing.T) {
if err != nil {
t.Log(err)
}
xlsx.AddComment("Sheet1", "A30", `{"author":"Excelize","text":"This is first comment."}`)
xlsx.AddComment("Sheet2", "B7", `{"author":"Excelize","text":"This is second comment."}`)
var s = "c"
for i := 0; i < 32767; i++ {
s += "c"
}
xlsx.AddComment("Sheet1", "A30", `{"author":"`+s+`","text":"`+s+`"}`)
xlsx.AddComment("Sheet2", "B7", `{"author":"Excelize: ","text":"This is a comment."}`)
err = xlsx.Save()
if err != nil {
t.Log(err)