Method: Writeexcel::Format#copy

Defined in:
lib/writeexcel/format.rb

#copy(other) ⇒ Object

:call-seq:

copy(format)

Copy the attributes of another Format object.

This method is used to copy all of the properties from one Format object to another:

lorry1 = workbook.add_format
lorry1.set_bold
lorry1.set_italic
lorry1.set_color('red')     # lorry1 is bold, italic and red

lorry2 = workbook.add_format
lorry2.copy(lorry1)
lorry2.set_color('yellow')  # lorry2 is bold, italic and yellow

The copy() method is only useful if you are using the method interface to Format properties. It generally isn’t required if you are setting Format properties directly using hashes.

Note: this is not a copy constructor, both objects must exist prior to copying.



124
125
126
127
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/writeexcel/format.rb', line 124

def copy(other)
  # copy properties except xf, merge_range, used_merge
  # Copy properties
  @type           = other.type
  @font_index     = other.font_index
  @font           = other.font
  @size           = other.size
  @bold           = other.bold
  @italic         = other.italic
  @color          = other.color
  @underline      = other.underline
  @font_strikeout = other.font_strikeout
  @font_outline   = other.font_outline
  @font_shadow    = other.font_shadow
  @font_script    = other.font_script
  @font_family    = other.font_family
  @font_charset   = other.font_charset
  @font_encoding  = other.font_encoding

  @num_format     = other.num_format
  @num_format_enc = other.num_format_enc

  @hidden         = other.hidden
  @locked         = other.locked

  @text_h_align   = other.text_h_align
  @text_wrap      = other.text_wrap
  @text_v_align   = other.text_v_align
  @text_justlast  = other.text_justlast
  @rotation       = other.rotation

  @fg_color       = other.fg_color
  @bg_color       = other.bg_color

  @pattern        = other.pattern

  @bottom         = other.bottom
  @top            = other.top
  @left           = other.left
  @right          = other.right

  @bottom_color   = other.bottom_color
  @top_color      = other.top_color
  @left_color     = other.left_color
  @right_color    = other.right_color

  @indent         = other.indent
  @shrink         = other.shrink
  @reading_order  = other.reading_order

  @diag_type      = other.diag_type
  @diag_color     = other.diag_color
  @diag_border    = other.diag_border

  @font_only      = other.font_only
end