From 741810a8635d51b639a9a279211386a75a7b046f Mon Sep 17 00:00:00 2001 From: Rad Cirskis Date: Sat, 23 Jun 2018 23:35:27 +1200 Subject: improved commenting formatting --- comment.go | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'comment.go') diff --git a/comment.go b/comment.go index b597da1..b1853ad 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, 1+yAxis+lineCount, (colCount*991)/175+5, 2+xAxis), + AutoFill: "True", + Row: xAxis, + Column: yAxis, }, } s, _ := xml.Marshal(sp) -- cgit v1.2.1 From 74c6091cfc4e023975018fb434a3a492fdcb5c76 Mon Sep 17 00:00:00 2001 From: xuri Date: Thu, 28 Jun 2018 10:03:53 +0800 Subject: Update comment.go make the comment box's height auto and having the minimum height. --- comment.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'comment.go') diff --git a/comment.go b/comment.go index b1853ad..9548d78 100644 --- a/comment.go +++ b/comment.go @@ -125,7 +125,7 @@ func (f *File) addDrawingVML(commentID int, drawingVML, cell string, lineCount, ObjectType: "Note", Anchor: fmt.Sprintf( "%d, 23, %d, 0, %d, %d, %d, 5", - 1+yAxis, 1+xAxis, 1+yAxis+lineCount, (colCount*991)/175+5, 2+xAxis), + 1+yAxis, 1+xAxis, 2+yAxis+lineCount, colCount+yAxis, 2+xAxis+lineCount), AutoFill: "True", Row: xAxis, Column: yAxis, -- cgit v1.2.1 From e3050d21e7c645ba8ee88c9e0f32dd241e1c4cc3 Mon Sep 17 00:00:00 2001 From: Rad Cirskis Date: Sat, 30 Jun 2018 22:37:14 +1200 Subject: added retieval of worksheet comments --- comment.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'comment.go') diff --git a/comment.go b/comment.go index 9548d78..bab7370 100644 --- a/comment.go +++ b/comment.go @@ -19,6 +19,23 @@ func parseFormatCommentsSet(formatSet string) (*formatComment, error) { return &format, err } +// GetComments retrievs 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{} + for n := range f.sheetMap { + commentID := f.GetSheetIndex(n) + commentsXML := "xl/comments" + strconv.Itoa(commentID) + ".xml" + c, ok := f.XLSX[commentsXML] + if ok { + d := xlsxComments{} + xml.Unmarshal([]byte(c), &d) + comments[n] = &d + } + } + 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 -- cgit v1.2.1 From 79dfe1c3070b3c4af14a40acaa5bd8cb477acd3e Mon Sep 17 00:00:00 2001 From: xuri Date: Fri, 13 Jul 2018 17:40:47 +0800 Subject: GoDoc updated. --- comment.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'comment.go') diff --git a/comment.go b/comment.go index bab7370..92dd71d 100644 --- a/comment.go +++ b/comment.go @@ -15,11 +15,11 @@ func parseFormatCommentsSet(formatSet string) (*formatComment, error) { Author: "Author:", Text: " ", } - err := json.Unmarshal([]byte(formatSet), &format) + err := json.Unmarshal(parseFormatSet(formatSet), &format) return &format, err } -// GetComments retrievs all comments and returns a map +// 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{} -- cgit v1.2.1 From a3571ee39bec82d15d9a183aed7f7db39e0a160f Mon Sep 17 00:00:00 2001 From: xuri Date: Tue, 17 Jul 2018 15:28:22 +0800 Subject: Bugfix: create worksheet cause file issue. Relate issue #249. --- comment.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'comment.go') diff --git a/comment.go b/comment.go index 92dd71d..ab10310 100644 --- a/comment.go +++ b/comment.go @@ -15,7 +15,7 @@ func parseFormatCommentsSet(formatSet string) (*formatComment, error) { Author: "Author:", Text: " ", } - err := json.Unmarshal(parseFormatSet(formatSet), &format) + err := json.Unmarshal([]byte(formatSet), &format) return &format, err } -- cgit v1.2.1 From ec37b114c3b704a84c66fcf3e135c9df88ffb24d Mon Sep 17 00:00:00 2001 From: xuri Date: Mon, 6 Aug 2018 10:21:24 +0800 Subject: Fixes #256 and format document. --- comment.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'comment.go') diff --git a/comment.go b/comment.go index ab10310..8bf4fd3 100644 --- a/comment.go +++ b/comment.go @@ -8,8 +8,8 @@ import ( "strings" ) -// parseFormatCommentsSet provides function to parse the format settings of the -// comment with default value. +// parseFormatCommentsSet provides a function to parse the format settings of +// the comment with default value. func parseFormatCommentsSet(formatSet string) (*formatComment, error) { format := formatComment{ Author: "Author:", @@ -19,8 +19,8 @@ func parseFormatCommentsSet(formatSet string) (*formatComment, error) { return &format, err } -// GetComments retrieves all comments and returns a map -// of worksheet name to the worksheet comments. +// 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{} for n := range f.sheetMap { @@ -81,7 +81,7 @@ func (f *File) AddComment(sheet, cell, format string) error { return err } -// addDrawingVML provides function to create comment as +// addDrawingVML provides a 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, lineCount, colCount int) { col := string(strings.Map(letterOnlyMapF, cell)) @@ -178,8 +178,8 @@ func (f *File) addDrawingVML(commentID int, drawingVML, cell string, lineCount, f.XLSX[drawingVML] = v } -// addComment provides function to create chart as xl/comments%d.xml by given -// cell and format sets. +// addComment provides a 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 @@ -238,8 +238,8 @@ func (f *File) addComment(commentsXML, cell string, formatSet *formatComment) { f.saveFileList(commentsXML, v) } -// countComments provides function to get comments files count storage in the -// folder xl. +// countComments provides a function to get comments files count storage in +// the folder xl. func (f *File) countComments() int { count := 0 for k := range f.XLSX { -- cgit v1.2.1 From b4a6e61ec34d4a0db1110907cc969f0d7d38991a Mon Sep 17 00:00:00 2001 From: xuri Date: Wed, 12 Sep 2018 15:47:56 +0800 Subject: Fix golint errors under confidence 0.1 --- comment.go | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'comment.go') diff --git a/comment.go b/comment.go index 8bf4fd3..32ed02f 100644 --- a/comment.go +++ b/comment.go @@ -1,3 +1,11 @@ +// 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. +// +// 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 import ( -- cgit v1.2.1 From 6ced438f39030e8a9a521548d4112dd002dc2ebe Mon Sep 17 00:00:00 2001 From: xuri Date: Fri, 14 Sep 2018 00:24:49 +0800 Subject: New function `AddPictureFromBytes()` has been added, this resolve #259 and close #271. --- comment.go | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'comment.go') diff --git a/comment.go b/comment.go index 32ed02f..94aad6c 100644 --- a/comment.go +++ b/comment.go @@ -29,8 +29,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" @@ -38,7 +38,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 -- cgit v1.2.1 From 2f146c923ccd19c5ecc1f732b5b09d591fb935a3 Mon Sep 17 00:00:00 2001 From: xuri Date: Fri, 14 Sep 2018 00:35:47 +0800 Subject: Comments style changed. --- comment.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'comment.go') diff --git a/comment.go b/comment.go index 94aad6c..241261c 100644 --- a/comment.go +++ b/comment.go @@ -1,11 +1,13 @@ -// 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. -// -// 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. + +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 import ( -- cgit v1.2.1 From 13a9769cc5bde486c52d8e45661ff8108cd786ae Mon Sep 17 00:00:00 2001 From: xuri Date: Fri, 14 Sep 2018 00:44:23 +0800 Subject: Comments style changed. --- comment.go | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'comment.go') diff --git a/comment.go b/comment.go index 241261c..c87e08c 100644 --- a/comment.go +++ b/comment.go @@ -1,13 +1,11 @@ -/* -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. - -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. -*/ +// 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 ( -- cgit v1.2.1 From 3e004d900b103379c2d62657a3070de4a2e8585a Mon Sep 17 00:00:00 2001 From: xuri Date: Fri, 14 Sep 2018 00:58:48 +0800 Subject: Comments style changed. --- comment.go | 1 + 1 file changed, 1 insertion(+) (limited to 'comment.go') diff --git a/comment.go b/comment.go index c87e08c..2bfd785 100644 --- a/comment.go +++ b/comment.go @@ -6,6 +6,7 @@ // 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 ( -- cgit v1.2.1