Class: Axlsx::Comment

Inherits:
Object
  • Object
show all
Defined in:
lib/axlsx/workbook/worksheet/comment.rb

Overview

A comment is the text data for a comment

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(comments, options = {}) {|_self| ... } ⇒ Comment

TODO r (Rich Text Run) rPh (Phonetic Text Run) phoneticPr (Phonetic Properties)

Yields:

  • (_self)

Yield Parameters:

Raises:

  • (ArgumentError)


29
30
31
32
33
34
35
36
# File 'lib/axlsx/workbook/worksheet/comment.rb', line 29

def initialize(comments, options={})
  raise ArgumentError, "A comment needs a parent comments object" unless comments.is_a?(Comments)
  @comments = comments
  options.each do |o|
    self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
  end
  yield self if block_given?
end

Instance Attribute Details

#authorString

The author of this comment

Returns:

  • (String)

See Also:



13
14
15
# File 'lib/axlsx/workbook/worksheet/comment.rb', line 13

def author
  @author
end

#commentsComments (readonly)

The owning Comments object

Returns:



17
18
19
# File 'lib/axlsx/workbook/worksheet/comment.rb', line 17

def comments
  @comments
end

#refString

The string based cell position reference (e.g. 'A1') that determines the positioning of this comment

Returns:

  • (String)


22
23
24
# File 'lib/axlsx/workbook/worksheet/comment.rb', line 22

def ref
  @ref
end

#textString

The text to render

Returns:

  • (String)


8
9
10
# File 'lib/axlsx/workbook/worksheet/comment.rb', line 8

def text
  @text
end

Instance Method Details

#author_indexInteger

The index of this author in a unique sorted list of all authors in the comment.

Returns:

  • (Integer)


48
49
50
# File 'lib/axlsx/workbook/worksheet/comment.rb', line 48

def author_index
  @comments.authors.index(author)
end

#to_xml_string(str = "") ⇒ String

serialize the object

Parameters:

  • str (String) (defaults to: "")

Returns:

  • (String)


73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/axlsx/workbook/worksheet/comment.rb', line 73

def to_xml_string(str = "")
  author = @comments.authors[author_index]
  str << '<comment ref="' << ref << '" authorId="' << author_index.to_s << '">'
  str << '<text><r>'
  str << '<rPr> <b/><color indexed="81"/></rPr>'
  str << '<t>' << author.to_s << ':
</t></r>'
  str << '<r>'
  str << '<rPr><color indexed="81"/></rPr>'
  str << '<t>' << text << '</t></r></text>'
  str << '</comment>'
end

#vml_shapeVmlShape

The vml shape that will render this comment

Returns:



40
41
42
# File 'lib/axlsx/workbook/worksheet/comment.rb', line 40

def vml_shape
  @vml_shape ||= initialize_vml_shape
end