class Axlsx::Comments
Attributes
the vml_drawing
that holds the shapes for comments @return [VmlDrawing]
The worksheet that these comments belong to @return [Worksheet]
Public Class Methods
Creates a new Comments
object @param [Worksheet] worksheet The sheet that these comments belong to.
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
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
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
The part name for this object @return [String]
# File lib/axlsx/workbook/worksheet/comments.rb, line 22 def pn "#{COMMENT_PN % (index+1)}" end
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
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