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::CHAR_WIDTHS, Utility::COL_MAX, Utility::PERL_TRUE_VALUES, 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.
-
#font_family ⇒ Object
readonly
Returns the value of attribute font_family.
-
#font_size ⇒ Object
readonly
Returns the value of attribute font_size.
-
#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.
-
#writer ⇒ Object
writeonly
Sets the attribute writer.
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.
- #font_name ⇒ Object
-
#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.
Methods included from Utility
#absolute_char, #check_dimensions, #check_dimensions_and_update_max_min_values, #check_parameter, #convert_date_time, #convert_font_args, #dash_types, delete_files, #escape_url, #fill_properties, #float_to_str, #get_font_latin_attributes, #get_font_style_attributes, #get_image_properties, #layout_properties, #legend_properties, #line_fill_properties, #line_properties, #palette_color, #params_to_font, #pattern_properties, #pixels_to_points, #process_bmp, #process_gif, #process_jpg, #process_png, #process_workbook_options, #ptrue?, #put_deprecate_message, #quote_sheetname, #r_id_attributes, #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, #value_or_raise, #write_a_body_pr, #write_a_def_rpr, #write_a_end_para_rpr, #write_a_lst_style, #write_a_p_formula, #write_a_p_pr_formula, #write_a_solid_fill, #write_a_srgb_clr, #write_anchor, #write_auto_fill, #write_color, #write_comment_path, #write_def_rpr_r_pr_common, #write_div, #write_fill, #write_font, #write_stroke, #write_tx_pr, #write_xml_declaration, #xl_cell_to_rowcol, #xl_col_to_name, #xl_range, #xl_range_formula, #xl_rowcol_to_cell, #xl_string_pixel_width, #xml_str
Constructor Details
#initialize(workbook, worksheet, row, col, string, options = {}) ⇒ Comment
Returns a new instance of Comment.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/write_xlsx/package/comments.rb', line 21 def initialize(workbook, worksheet, row, col, string, = {}) ||= {} @workbook = workbook @worksheet = worksheet @row = row @col = col (row, col, ) @string = string[0, STR_MAX] @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.
19 20 21 |
# File 'lib/write_xlsx/package/comments.rb', line 19 def @author end |
#col ⇒ Object (readonly)
Returns the value of attribute col.
17 18 19 |
# File 'lib/write_xlsx/package/comments.rb', line 17 def col @col end |
#color ⇒ Object (readonly)
Returns the value of attribute color.
17 18 19 |
# File 'lib/write_xlsx/package/comments.rb', line 17 def color @color end |
#font_family ⇒ Object (readonly)
Returns the value of attribute font_family.
18 19 20 |
# File 'lib/write_xlsx/package/comments.rb', line 18 def font_family @font_family end |
#font_size ⇒ Object (readonly)
Returns the value of attribute font_size.
18 19 20 |
# File 'lib/write_xlsx/package/comments.rb', line 18 def font_size @font_size end |
#row ⇒ Object (readonly)
Returns the value of attribute row.
17 18 19 |
# File 'lib/write_xlsx/package/comments.rb', line 17 def row @row end |
#string ⇒ Object (readonly)
Returns the value of attribute string.
17 18 19 |
# File 'lib/write_xlsx/package/comments.rb', line 17 def string @string end |
#vertices ⇒ Object (readonly)
Returns the value of attribute vertices.
17 18 19 |
# File 'lib/write_xlsx/package/comments.rb', line 17 def vertices @vertices end |
#visible ⇒ Object
Returns the value of attribute visible.
19 20 21 |
# File 'lib/write_xlsx/package/comments.rb', line 19 def visible @visible end |
#writer=(value) ⇒ Object (writeonly)
Sets the attribute writer
215 216 217 |
# File 'lib/write_xlsx/package/comments.rb', line 215 def writer=(value) @writer = value end |
Instance Method Details
#backgrount_color(color) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/write_xlsx/package/comments.rb', line 44 def backgrount_color(color) color_id = Format.color(color) if color_id.to_s =~ /^#[0-9A-F]{6}/i @color = color_id.to_s elsif color_id == 0 @color = '#ffffe1' else rgb = @workbook.palette[color_id - 8] @color = "##{rgb_color(rgb)} [#{color_id}]" end end |
#default_start_col(col) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/write_xlsx/package/comments.rb', line 81 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
66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/write_xlsx/package/comments.rb', line 66 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
94 95 96 97 98 99 100 101 |
# File 'lib/write_xlsx/package/comments.rb', line 94 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
103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/write_xlsx/package/comments.rb', line 103 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.
158 159 160 161 162 |
# File 'lib/write_xlsx/package/comments.rb', line 158 def fill_attributes [ ['color2', '#ffffe1'] ] end |
#font_name ⇒ Object
217 218 219 |
# File 'lib/write_xlsx/package/comments.rb', line 217 def font_name @font 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.
59 60 61 62 63 64 |
# File 'lib/write_xlsx/package/comments.rb', line 59 def rgb_color(rgb) r, g, b = rgb result = sprintf("%02x%02x%02x", r, g, b) result = "#{::Regexp.last_match(1)}#{::Regexp.last_match(2)}#{::Regexp.last_match(3)}" if result =~ /^([0-9a-f])\1([0-9a-f])\2([0-9a-f])\3$/ result end |
#style_addition ⇒ Object
128 129 130 |
# File 'lib/write_xlsx/package/comments.rb', line 128 def style_addition ['visibility:', visibility] end |
#type ⇒ Object
124 125 126 |
# File 'lib/write_xlsx/package/comments.rb', line 124 def type '#_x0000_t202' end |
#v_shape_attributes(id, z_index) ⇒ Object
116 117 118 119 120 121 122 |
# File 'lib/write_xlsx/package/comments.rb', line 116 def v_shape_attributes(id, z_index) attr = v_shape_attributes_base(id) attr << ['style', (v_shape_style_base(z_index, vertices) + style_addition).join] attr << ['fillcolor', color] attr << ['o:insetmode', 'auto'] attr end |
#visibility ⇒ Object
151 152 153 |
# File 'lib/write_xlsx/package/comments.rb', line 151 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 212 213 |
# File 'lib/write_xlsx/package/comments.rb', line 194 def write_client_data attributes = [ %w[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.
167 168 169 170 171 172 173 174 175 |
# File 'lib/write_xlsx/package/comments.rb', line 167 def write_shadow attributes = [ %w[on t], %w[color black], %w[obscured t] ] @writer.empty_tag('v:shadow', attributes) end |
#write_shape(writer, id, z_index) ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/write_xlsx/package/comments.rb', line 132 def write_shape(writer, id, z_index) @writer = writer attributes = v_shape_attributes(id, z_index) @writer.tag_elements('v:shape', attributes) do # 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.
180 181 182 183 184 185 186 187 188 189 |
# File 'lib/write_xlsx/package/comments.rb', line 180 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 |