Method: Axlsx::RichTextRun#autowidth

Defined in:
lib/axlsx/workbook/worksheet/rich_text_run.rb

#autowidth(widtharray) ⇒ Array

Tries to work out the width of the longest line in the run

Parameters:

  • widtharray (Array)

    this array is populated with the widths of each line in the run.

Returns:

  • (Array)


163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/axlsx/workbook/worksheet/rich_text_run.rb', line 163

def autowidth(widtharray)
  return if value.nil?
  if styles.cellXfs[style].alignment && styles.cellXfs[style].alignment.wrap_text
    first = true
    value.to_s.split(/\r?\n/, -1).each do |line|
      if first
        first = false
      else
        widtharray << 0
      end
      widtharray[-1] += string_width(line, font_size)
    end
  else
    widtharray[-1] += string_width(value.to_s, font_size)
  end
  widtharray
end