Class: Writeexcel::Worksheet::Comment
- Inherits:
-
Object
- Object
- Writeexcel::Worksheet::Comment
- Defined in:
- lib/writeexcel/comments.rb
Instance Attribute Summary collapse
-
#author ⇒ Object
readonly
Returns the value of attribute author.
-
#author_encoding ⇒ Object
readonly
Returns the value of attribute author_encoding.
-
#col ⇒ Object
readonly
Returns the value of attribute col.
-
#color ⇒ Object
readonly
Returns the value of attribute color.
-
#encoding ⇒ Object
readonly
Returns the value of attribute encoding.
-
#row ⇒ Object
readonly
Returns the value of attribute row.
-
#string ⇒ Object
readonly
Returns the value of attribute string.
-
#vertices ⇒ Object
readonly
Returns the value of attribute vertices.
-
#visible ⇒ Object
readonly
Returns the value of attribute visible.
Instance Method Summary collapse
-
#initialize(worksheet, row, col, string, options = {}) ⇒ Comment
constructor
A new instance of Comment.
-
#obj_comment_record(obj_id) ⇒ Object
OBJ record that is part of cell comments.
- #store_comment_record(i, num_objects, num_comments, spid) ⇒ Object
-
#store_mso_opt_comment(spid, visible = nil, colour = 0x50) ⇒ Object
Write the Escher Opt record that is part of MSODRAWING.
-
#store_note_record(obj_id) ⇒ Object
Write the worksheet NOTE record that is part of cell comments.
Constructor Details
#initialize(worksheet, row, col, string, options = {}) ⇒ Comment
Returns a new instance of Comment.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/writeexcel/comments.rb', line 50 def initialize(worksheet, row, col, string, = {}) @worksheet = worksheet @row, @col = row, col @params = params_with() @string, @params[:encoding] = string_and_encoding(string, @params[:encoding], 'comment') # Limit the string to the max number of chars (not bytes). max_len = 32767 max_len = max_len * 2 if @params[:encoding] != 0 if @string.bytesize > max_len @string = @string[0 .. max_len] end @encoding = @params[:encoding] @author = @params[:author] @author_encoding = @params[:author_encoding] @visible = @params[:visible] @color = @params[:color] @vertices = calc_vertices end |
Instance Attribute Details
#author ⇒ Object (readonly)
Returns the value of attribute author.
48 49 50 |
# File 'lib/writeexcel/comments.rb', line 48 def @author end |
#author_encoding ⇒ Object (readonly)
Returns the value of attribute author_encoding.
48 49 50 |
# File 'lib/writeexcel/comments.rb', line 48 def @author_encoding end |
#col ⇒ Object (readonly)
Returns the value of attribute col.
48 49 50 |
# File 'lib/writeexcel/comments.rb', line 48 def col @col end |
#color ⇒ Object (readonly)
Returns the value of attribute color.
48 49 50 |
# File 'lib/writeexcel/comments.rb', line 48 def color @color end |
#encoding ⇒ Object (readonly)
Returns the value of attribute encoding.
48 49 50 |
# File 'lib/writeexcel/comments.rb', line 48 def encoding @encoding end |
#row ⇒ Object (readonly)
Returns the value of attribute row.
48 49 50 |
# File 'lib/writeexcel/comments.rb', line 48 def row @row end |
#string ⇒ Object (readonly)
Returns the value of attribute string.
48 49 50 |
# File 'lib/writeexcel/comments.rb', line 48 def string @string end |
#vertices ⇒ Object (readonly)
Returns the value of attribute vertices.
48 49 50 |
# File 'lib/writeexcel/comments.rb', line 48 def vertices @vertices end |
#visible ⇒ Object (readonly)
Returns the value of attribute visible.
48 49 50 |
# File 'lib/writeexcel/comments.rb', line 48 def visible @visible end |
Instance Method Details
#obj_comment_record(obj_id) ⇒ Object
OBJ record that is part of cell comments.
obj_id # Object ID number.
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/writeexcel/comments.rb', line 158 def obj_comment_record(obj_id) #:nodoc: record = 0x005D # Record identifier length = 0x0034 # Bytes to follow obj_type = 0x0019 # Object type (comment). data = '' # Record data. sub_record = 0x0000 # Sub-record identifier. sub_length = 0x0000 # Length of sub-record. sub_data = '' # Data of sub-record. = 0x4011 reserved = 0x0000 # Add ftCmo (common object data) subobject sub_record = 0x0015 # ftCmo sub_length = 0x0012 sub_data = [obj_type, obj_id, , reserved, reserved, reserved].pack( "vvvVVV") data = [sub_record, sub_length].pack("vv") + sub_data # Add ftNts (note structure) subobject sub_record = 0x000D # ftNts sub_length = 0x0016 sub_data = [reserved,reserved,reserved,reserved,reserved,reserved].pack( "VVVVVv") data += [sub_record, sub_length].pack("vv") + sub_data # Add ftEnd (end of object) subobject sub_record = 0x0000 # ftNts sub_length = 0x0000 data += [sub_record, sub_length].pack("vv") # Pack the record. header = [record, length].pack("vv") header + data end |
#store_comment_record(i, num_objects, num_comments, spid) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/writeexcel/comments.rb', line 71 def store_comment_record(i, num_objects, num_comments, spid) str_len = string.bytesize str_len = str_len / 2 if encoding != 0 # Num of chars not bytes. spid = store_comment_mso_drawing_record(i, num_objects, num_comments, spid, visible, color, vertices) store_obj_comment(num_objects + i + 1) store_mso_drawing_text_box store_txo(str_len) store_txo_continue_1(string, encoding) formats = [[0, 9], [str_len, 0]] store_txo_continue_2(formats) spid end |
#store_mso_opt_comment(spid, visible = nil, colour = 0x50) ⇒ Object
Write the Escher Opt record that is part of MSODRAWING.
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/writeexcel/comments.rb', line 128 def store_mso_opt_comment(spid, visible = nil, colour = 0x50) #:nodoc: type = 0xF00B version = 3 instance = 9 data = '' length = 54 # Use the visible flag if set by the user or else use the worksheet value. # Note that the value used is the opposite of Comment#note_record. # if visible visible = visible != 0 ? 0x0000 : 0x0002 else visible = @worksheet.comments_visible? ? 0x0000 : 0x0002 end data = [spid].pack('V') + ['0000BF00080008005801000000008101'].pack("H*") + [colour].pack("C") + ['000008830150000008BF011000110001'+'02000000003F0203000300BF03'].pack("H*") + [visible].pack('v') + ['0A00'].pack('H*') @worksheet.add_mso_generic(type, version, instance, data, length) end |
#store_note_record(obj_id) ⇒ Object
Write the worksheet NOTE record that is part of cell comments.
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/writeexcel/comments.rb', line 88 def store_note_record(obj_id) #:nodoc: = = ruby_19 { = [].pack('a*') if .ascii_only? } record = 0x001C # Record identifier length = 0x000C # Bytes to follow = '' unless = 0 unless # Use the visible flag if set by the user or else use the worksheet value. # The flag is also set in store_mso_opt_comment() but with the opposite # value. if visible comment_visible = visible != 0 ? 0x0002 : 0x0000 else comment_visible = @worksheet.comments_visible? ? 0x0002 : 0x0000 end # Get the number of chars in the author string (not bytes). num_chars = .bytesize num_chars = num_chars / 2 if != 0 && # Null terminate the author string. = ruby_18 { + "\0" } || ruby_19 { .force_encoding('BINARY') + "\0".force_encoding('BINARY') } # Pack the record. data = [@row, @col, comment_visible, obj_id, num_chars, ].pack("vvvvvC") length = data.bytesize + .bytesize header = [record, length].pack("vv") append(header, data, ) end |