Comments

Cell comments are a way of adding notation to cells.

Xlsx2Go supports string version of comments, as well as custom version via special type. Read about types below.

	//to add comment to cell
	sheet.CellByRef("N28").SetComment("Never hear the 'No comment' again.")

	//to remove comment
	sheet.CellByRef("N28").RemoveComment()

	//to retrieve text of comment
	comments := sheet.CellByRef("N28").Comment()

String comment

As was shown, the simplest way to add comment is to use string version. At the same time, that version has some limitations - you can't use rich text, set author, width, height and etc.

	//to add string comment
	sheet.CellByRef("B2").SetValue("Any comments?")
	sheet.CellByRef("B2").SetComment("No comment!")

Custom comment

While with string version of comment you can add comments really easy, sometimes we need additional settings like width, height, author or even rich text. For these cases you can use special type and configure comment as you wish.

Example

package code

import (
	"github.com/plandem/xlsx"
	"github.com/plandem/xlsx/format/styles"
	"github.com/plandem/xlsx/types/comment"
)

func Example_comments() {
	xl := xlsx.New()

	sheet := xl.AddSheet("")

	//red alert box comment
	cmt := comment.New(
		comment.Width(250),
		comment.Height(50),
		comment.Background("#FFAAAA"),
		comment.Shadow("#FF0000"),
		comment.Stroke("#CC0000"),
		comment.Author("Gate Keeper"),
		comment.Text(
			styles.New(
				styles.Font.Bold,
				styles.Font.Size(16),
			),
			"STOP",
			"\nDanger zone, do not proceed",
		),
	)

	sheet.CellByRef("A2").SetValue("Hello?")
	sheet.CellByRef("A2").SetComment(cmt)

	xl.SaveAs("./foo.xlsx")
}

Check Rich Text for more information about rich texts.

Last Updated: 7/17/2019, 7:27:15 PM