lib/write_xlsx/package/table.rb in write_xlsx-0.85.11 vs lib/write_xlsx/package/table.rb in write_xlsx-0.86.0

- old
+ new

@@ -8,20 +8,21 @@ class Table include Writexlsx::Utility class ColumnData attr_reader :id - attr_accessor :name, :format, :formula + attr_accessor :name, :format, :formula, :name_format attr_accessor :total_string, :total_function def initialize(id, param = {}) @id = id @name = "Column#{id}" @total_string = '' @total_function = '' @formula = '' @format = nil + @name_format = nil @user_data = param[id-1] if param end end attr_reader :id, :name @@ -91,14 +92,18 @@ if user_data = @param[:columns][col_id] # Map user defined values to internal values. if user_data[:header] && !user_data[:header].empty? col_data.name = user_data[:header] end + + # Get the header format if defined. + col_data.name_format = user_data[:header_format] + # Handle the column formula. handle_the_column_formula( - col_data, col_num, user_data[:formula], user_data[:format] - ) + col_data, col_num, user_data[:formula], user_data[:format] + ) # Handle the function for the total row. if user_data[:total_function] handle_the_function_for_the_table_row( @row2, col_data, col_num, user_data @@ -121,11 +126,13 @@ end end def write_the_column_headers_to_the_worksheet(col_num, col_data) if @param[:header_row] != 0 - @worksheet.write_string(@row1, col_num, col_data.name) + @worksheet.write_string( + @row1, col_num, col_data.name, col_data.name_format + ) end end def write_the_cell_data_if_supplied return unless @param[:data] @@ -266,10 +273,15 @@ @style = "TableStyleMedium9" end end def set_the_table_name - @name = @param[:name] if @param[:name] + if @param[:name] + name = @param[:name] + + raise "Name '#{name} in add_table cannot contain spaces" if name =~ /\s/ + @name = @param[:name] + end end def set_the_table_and_autofilter_ranges @range = xl_range(@row1, @row2, @col1, @col2) @a_range = xl_range(@row1, @last_data_row, @col1, @col2)