class Axlsx::Comments

Comments is a collection of Comment objects for a worksheet

Attributes

vml_drawing[R]

the vml_drawing that holds the shapes for comments @return [VmlDrawing]

worksheet[R]

The worksheet that these comments belong to @return [Worksheet]

Public Class Methods

new(worksheet) click to toggle source

Creates a new Comments object @param [Worksheet] worksheet The sheet that these comments belong to.

Calls superclass method Axlsx::SimpleTypedList::new
# File lib/axlsx/workbook/worksheet/comments.rb, line 28
def initialize(worksheet)
  raise ArgumentError, "you must provide a worksheet" unless worksheet.is_a?(Worksheet)
  super(Comment)
  @worksheet = worksheet
  @vml_drawing = VmlDrawing.new(self)
end

Public Instance Methods

add_comment(options={}) { |last| ... } click to toggle source

Adds a new comment to the worksheet that owns these comments. @note the author, text and ref options are required @option options [String] author The name of the author for this comment @option options [String] text The text for this comment @option options [Stirng|Cell] ref The cell that this comment is attached to.

# File lib/axlsx/workbook/worksheet/comments.rb, line 40
def add_comment(options={})
  raise ArgumentError, "Comment require an author" unless options[:author]
  raise ArgumentError, "Comment requires text" unless options[:text]
  raise ArgumentError, "Comment requires ref" unless options[:ref]
  self << Comment.new(self, options)
  yield last if block_given?
  last
end
authors() click to toggle source

A sorted list of the unique authors in the contained comments @return [Array]

# File lib/axlsx/workbook/worksheet/comments.rb, line 51
def authors
  map { |comment| comment.author.to_s }.uniq.sort
end
index() click to toggle source

The index of this collection in the workbook. Effectively the index of the worksheet. @return [Integer]

# File lib/axlsx/workbook/worksheet/comments.rb, line 16
def index
  @worksheet.index
end
pn() click to toggle source

The part name for this object @return [String]

# File lib/axlsx/workbook/worksheet/comments.rb, line 22
def pn
  "#{COMMENT_PN % (index+1)}"
end
relationships() click to toggle source

The relationships required by this object @return [Array]

# File lib/axlsx/workbook/worksheet/comments.rb, line 57
def relationships
  [Relationship.new(self, VML_DRAWING_R, "../#{vml_drawing.pn}"),
   Relationship.new(self, COMMENT_R, "../#{pn}")]
end
to_xml_string(str="") click to toggle source

serialize the object @param [String] str @return [String]

# File lib/axlsx/workbook/worksheet/comments.rb, line 65
def to_xml_string(str="")
  str << '<?xml version="1.0" encoding="UTF-8"?>'
  str << ('<comments xmlns="' << XML_NS << '"><authors>')
  authors.each do  |author|
    str << ('<author>' << author.to_s << '</author>')
  end
  str << '</authors><commentList>'
  each do |comment|
    comment.to_xml_string str
  end
  str << '</commentList></comments>'

end