Class: Writexlsx::Package::Comment
- Inherits:
-
Object
- Object
- Writexlsx::Package::Comment
- Includes:
- Utility
- Defined in:
- lib/write_xlsx/package/comments.rb
Constant Summary collapse
- DEFAULT_COLOR =
what color ?
81- DEFAULT_WIDTH =
128- DEFAULT_HEIGHT =
74
Constants included from Utility
Utility::COL_MAX, Utility::ROW_MAX, Utility::SHEETNAME_MAX, Utility::STR_MAX
Instance Attribute Summary collapse
-
#author ⇒ Object
Returns the value of attribute author.
-
#col ⇒ Object
readonly
Returns the value of attribute col.
-
#color ⇒ Object
readonly
Returns the value of attribute color.
-
#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
Returns the value of attribute visible.
Instance Method Summary collapse
- #backgrount_color(color) ⇒ Object
- #default_start_col(col) ⇒ Object
- #default_start_row(row) ⇒ Object
- #default_x_offset(col) ⇒ Object
- #default_y_offset(row) ⇒ Object
-
#fill_attributes ⇒ Object
Write the <v:fill> element.
-
#initialize(workbook, worksheet, row, col, string, options = {}) ⇒ Comment
constructor
A new instance of Comment.
-
#rgb_color(rgb) ⇒ Object
Minor modification to allow comparison testing.
- #style_addition ⇒ Object
- #type ⇒ Object
- #v_shape_attributes(id, z_index) ⇒ Object
- #visibility ⇒ Object
-
#write_client_data ⇒ Object
Write the <x:ClientData> element.
-
#write_shadow ⇒ Object
Write the <v:shadow> element.
- #write_shape(writer, id, z_index) ⇒ Object
-
#write_textbox ⇒ Object
Write the <v:textbox> element.
- #writer=(w) ⇒ Object
Methods included from Utility
#absolute_char, #check_dimensions, #check_dimensions_and_update_max_min_values, #check_parameter, #convert_date_time, delete_files, #float_to_str, #pixels_to_points, #ptrue?, #put_deprecate_message, #row_col_notation, #shape_style_base, #store_col_max_min_values, #store_row_max_min_values, #substitute_cellref, #underline_attributes, #v_shape_attributes_base, #v_shape_style_base, #write_anchor, #write_auto_fill, #write_color, #write_comment_path, #write_div, #write_fill, #write_font, #write_stroke, #xl_cell_to_rowcol, #xl_col_to_name, #xl_range, #xl_range_formula, #xl_rowcol_to_cell, #xml_str
Constructor Details
#initialize(workbook, worksheet, row, col, string, options = {}) ⇒ Comment
Returns a new instance of Comment.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/write_xlsx/package/comments.rb', line 19 def initialize(workbook, worksheet, row, col, string, = {}) ||= {} @workbook = workbook @worksheet = worksheet @row = row @col = col @string = string[0, STR_MAX] = [:author] @color = backgrount_color([:color] || DEFAULT_COLOR) @start_cell = [:start_cell] @start_row, @start_col = if @start_cell substitute_cellref(@start_cell) else [ [:start_row], [:start_col] ] end @start_row ||= default_start_row(row) @start_col ||= default_start_col(col) @visible = [:visible] @x_offset = [:x_offset] || default_x_offset(col) @y_offset = [:y_offset] || default_y_offset(row) @x_scale = [:x_scale] || 1 @y_scale = [:y_scale] || 1 @width = (0.5 + ([:width] || DEFAULT_WIDTH) * @x_scale).to_i @height = (0.5 + ([:height] || DEFAULT_HEIGHT) * @y_scale).to_i @vertices = @worksheet.position_object_pixels( @start_col, @start_row, @x_offset, @y_offset, @width, @height ) << [@width, @height] end |
Instance Attribute Details
#author ⇒ Object
Returns the value of attribute author.
17 18 19 |
# File 'lib/write_xlsx/package/comments.rb', line 17 def end |
#col ⇒ Object (readonly)
Returns the value of attribute col.
16 17 18 |
# File 'lib/write_xlsx/package/comments.rb', line 16 def col @col end |
#color ⇒ Object (readonly)
Returns the value of attribute color.
16 17 18 |
# File 'lib/write_xlsx/package/comments.rb', line 16 def color @color end |
#row ⇒ Object (readonly)
Returns the value of attribute row.
16 17 18 |
# File 'lib/write_xlsx/package/comments.rb', line 16 def row @row end |
#string ⇒ Object (readonly)
Returns the value of attribute string.
16 17 18 |
# File 'lib/write_xlsx/package/comments.rb', line 16 def string @string end |
#vertices ⇒ Object (readonly)
Returns the value of attribute vertices.
16 17 18 |
# File 'lib/write_xlsx/package/comments.rb', line 16 def vertices @vertices end |
#visible ⇒ Object
Returns the value of attribute visible.
17 18 19 |
# File 'lib/write_xlsx/package/comments.rb', line 17 def visible @visible end |
Instance Method Details
#backgrount_color(color) ⇒ Object
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/write_xlsx/package/comments.rb', line 49 def backgrount_color(color) color_id = Format.get_color(color) if color_id == 0 @color = '#ffffe1' else rgb = @workbook.palette[color_id - 8] @color = "##{rgb_color(rgb)} [#{color_id}]\n" end end |
#default_start_col(col) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/write_xlsx/package/comments.rb', line 85 def default_start_col(col) case col when COL_MAX - 3 COL_MAX - 6 when COL_MAX - 2 COL_MAX - 5 when COL_MAX - 1 COL_MAX - 4 else col + 1 end end |
#default_start_row(row) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/write_xlsx/package/comments.rb', line 70 def default_start_row(row) case row when 0 0 when ROW_MAX - 3 ROW_MAX - 7 when ROW_MAX - 2 ROW_MAX - 6 when ROW_MAX - 1 ROW_MAX - 5 else row - 1 end end |
#default_x_offset(col) ⇒ Object
98 99 100 101 102 103 104 105 |
# File 'lib/write_xlsx/package/comments.rb', line 98 def default_x_offset(col) case col when COL_MAX - 3, COL_MAX - 2, COL_MAX - 1 49 else 15 end end |
#default_y_offset(row) ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/write_xlsx/package/comments.rb', line 107 def default_y_offset(row) case row when 0 2 when ROW_MAX - 3, ROW_MAX - 2 16 when ROW_MAX - 1 14 else 10 end end |
#fill_attributes ⇒ Object
Write the <v:fill> element.
162 163 164 |
# File 'lib/write_xlsx/package/comments.rb', line 162 def fill_attributes ['color2', '#ffffe1'] end |
#rgb_color(rgb) ⇒ Object
Minor modification to allow comparison testing. Change RGB colors from long format, ffcc00 to short format fc0 used by VML.
62 63 64 65 66 67 68 |
# File 'lib/write_xlsx/package/comments.rb', line 62 def rgb_color(rgb) result = sprintf("%02x%02x%02x", *rgb) if result =~ /^([0-9a-f])\1([0-9a-f])\2([0-9a-f])\3$/ result = "#{$1}#{$2}#{$3}" end result end |
#style_addition ⇒ Object
130 131 132 |
# File 'lib/write_xlsx/package/comments.rb', line 130 def style_addition ['visibility:', visibility] end |
#type ⇒ Object
126 127 128 |
# File 'lib/write_xlsx/package/comments.rb', line 126 def type '#_x0000_t202' end |
#v_shape_attributes(id, z_index) ⇒ Object
120 121 122 123 124 |
# File 'lib/write_xlsx/package/comments.rb', line 120 def v_shape_attributes(id, z_index) v_shape_attributes_base(id, z_index) << 'fillcolor' << color << 'o:insetmode' << 'auto' end |
#visibility ⇒ Object
155 156 157 |
# File 'lib/write_xlsx/package/comments.rb', line 155 def visibility ptrue?(visible) ? 'visible' : 'hidden' end |
#write_client_data ⇒ Object
Write the <x:ClientData> element.
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/write_xlsx/package/comments.rb', line 194 def write_client_data attributes = ['ObjectType', 'Note'] @writer.tag_elements('x:ClientData', attributes) do @writer.empty_tag('x:MoveWithCells') @writer.empty_tag('x:SizeWithCells') # Write the x:Anchor element. write_anchor # Write the x:AutoFill element. write_auto_fill # Write the x:Row element. @writer.data_element('x:Row', row) # Write the x:Column element. @writer.data_element('x:Column', col) # Write the x:Visible element. @writer.empty_tag('x:Visible') if ptrue?(visible) end end |
#write_shadow ⇒ Object
Write the <v:shadow> element.
169 170 171 172 173 174 175 176 177 |
# File 'lib/write_xlsx/package/comments.rb', line 169 def write_shadow attributes = [ 'on', 't', 'color', 'black', 'obscured', 't' ] @writer.empty_tag('v:shadow', attributes) end |
#write_shape(writer, id, z_index) ⇒ Object
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/write_xlsx/package/comments.rb', line 134 def write_shape(writer, id, z_index) @writer = writer attributes = v_shape_attributes(id, z_index) @writer.tag_elements('v:shape', attributes) do writer = @writer # Write the v:fill element. write_fill # Write the v:shadow element. write_shadow # Write the v:path element. write_comment_path(nil, 'none') # Write the v:textbox element. write_textbox # Write the x:ClientData element. write_client_data end end |
#write_textbox ⇒ Object
Write the <v:textbox> element.
182 183 184 185 186 187 188 189 |
# File 'lib/write_xlsx/package/comments.rb', line 182 def write_textbox attributes = ['style', 'mso-direction-alt:auto'] @writer.tag_elements('v:textbox', attributes) do # Write the div element. write_div('left') end end |
#writer=(w) ⇒ Object
213 214 215 |
# File 'lib/write_xlsx/package/comments.rb', line 213 def writer=(w) @writer = w end |