lib/axlsx/workbook/worksheet/cell.rb in axlsx-1.1.8 vs lib/axlsx/workbook/worksheet/cell.rb in axlsx-1.2.0

- old
+ new

@@ -316,13 +316,36 @@ end str << '</c>' end def is_formula? - @type == :string && @value.start_with?('=') + @type == :string && @value.to_s.start_with?('=') end + # This is still not perfect... + # - scaling is not linear as font sizes increst + # - different fonts have different mdw and char widths + def autowidth + return if is_formula? || value == nil + mdw = 1.78 #This is the widest width of 0..9 in arial@10px) + font_scale = (font_size/10.0).to_f + ((value.to_s.count(Worksheet.thin_chars) * mdw + 5) / mdw * 256) / 256.0 * font_scale + end + + # returns the absolute or relative string style reference for + # this cell. + # @param [Boolean] absolute -when false a relative reference will be + # returned. + # @return [String] + def reference(absolute=true) + absolute ? r_abs : r + end + private + + def font_size + sz || @styles.fonts[@styles.cellXfs[style].fontId].sz + end # Utility method for setting inline style attributes def set_run_style( validator, attr, value) return unless INLINE_STYLES.include?(attr.to_s) Axlsx.send(validator, value) unless validator == nil