Paxa / fast_excel

Ultra Fast Excel Writer for Ruby
MIT License
336 stars 59 forks source link

Could auto width coexist with set width #85

Open crystianwendel opened 2 years ago

crystianwendel commented 2 years ago

I think it would be nice if auto width could coexist with fixed width.

I use auto width most of the time, but sometimes a single column content can make a mess if it's too large. I would like to set width of some columns, and still have autowidth for the rest of them.

In my project, i did this as a monkey patch, but i could make a PR if you think this could me useful.

def initialize(struct)
  @fixed_witdh_columns = []
  @is_open = true
  @col_formats = {}
  @last_row_number = -1
  super(struct)
end

def set_column_width(col, width)
  @fixed_witdh_columns << col
  set_column(col, col, width, @col_formats[col])
end

def close
  return unless auto_width?

  @column_widths.each do |num, width|
    next if @fixed_witdh_columns.include?(num)

    set_column_width(num, width + 0.2)
  end
end