class Axlsx::Comment

A comment is the text data for a comment

Attributes

comments[R]

The owning Comments object @return [Comments]

ref[R]

The string based cell position reference (e.g. 'A1') that determines the positioning of this comment @return [String|Cell]

Public Class Methods

new(comments, options={}) { |self| ... } click to toggle source

Creates a new comment object @param [Comments] comments The comment collection this comment belongs to @param [Hash] options @option [String] author the author of the comment @option [String] text The text for the comment @option [String] ref The refence (e.g. 'A3' where this comment will be anchored. @option [Boolean] visible This controls the visiblity of the associated vml_shape.

# File lib/axlsx/workbook/worksheet/comment.rb, line 16
def initialize(comments, options={})
  raise ArgumentError, "A comment needs a parent comments object" unless comments.is_a?(Comments)
  @visible = true
  @comments = comments
  parse_options options
  yield self if block_given?
end

Public Instance Methods

author_index() click to toggle source

The index of this author in a unique sorted list of all authors in the comment. @return [Integer]

# File lib/axlsx/workbook/worksheet/comment.rb, line 49
def author_index
  @comments.author_index(author)
end
ref=(v) click to toggle source

@see ref

# File lib/axlsx/workbook/worksheet/comment.rb, line 54
def ref=(v)
  Axlsx::DataTypeValidator.validate :comment_ref, [String, Cell], v
  @ref = v if v.is_a?(String)
  @ref = v.r if v.is_a?(Cell)
end
to_xml_string(str = "") click to toggle source

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

# File lib/axlsx/workbook/worksheet/comment.rb, line 63
def to_xml_string(str = "")
  str << ('<comment ref="' << ref << '" authorId="' << author_index.to_s << '">')
  str << '<text>'
  unless author.to_s == ""
    str << '<r><rPr><b/><color indexed="81"/></rPr>'
    str << ("<t>" << ::CGI.escapeHTML(author.to_s) << ":\n</t></r>")
  end
  str << '<r>'
  str << '<rPr><color indexed="81"/></rPr>'
  str << ('<t>' << ::CGI.escapeHTML(text) << '</t></r></text>')
  str << '</comment>'
end
vml_shape() click to toggle source

The vml shape that will render this comment @return [VmlShape]

# File lib/axlsx/workbook/worksheet/comment.rb, line 42
def vml_shape
  @vml_shape ||= initialize_vml_shape
end

Private Instance Methods

initialize_vml_shape() click to toggle source

initialize the vml shape based on this comment's ref/position in the worksheet. by default, all columns are 5 columns wide and 5 rows high

# File lib/axlsx/workbook/worksheet/comment.rb, line 80
def initialize_vml_shape
  pos = Axlsx::name_to_indices(ref)
  @vml_shape = VmlShape.new(:row => pos[1], :column => pos[0], :visible => @visible) do |vml|
    vml.left_column = vml.column
    vml.right_column = vml.column + 2 
    vml.top_row = vml.row
     vml.bottom_row = vml.row + 4
  end
end