Method: Axlsx::Cell#autowidth
- Defined in:
- lib/axlsx/workbook/worksheet/cell.rb
#autowidth ⇒ Float
Attempts to determine the correct width for this cell's content
374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 |
# File 'lib/axlsx/workbook/worksheet/cell.rb', line 374 def autowidth return if is_formula? || value.nil? if contains_rich_text? string_width('', font_size) + value.autowidth elsif styles.cellXfs[style].alignment && styles.cellXfs[style].alignment.wrap_text max_width = 0 value.to_s.split(/\r?\n/).each do |line| width = string_width(line, font_size) max_width = width if width > max_width end max_width else string_width(value, font_size) end end |