lib/write_xlsx/package/table.rb in write_xlsx-0.72.3.beta1 vs lib/write_xlsx/package/table.rb in write_xlsx-0.73.0
- old
+ new
@@ -22,14 +22,15 @@
@format = nil
@user_data = param[id-1] if param
end
end
- def initialize(worksheet, id, *args)
+ attr_reader :id, :name
+
+ def initialize(worksheet, *args)
@worksheet = worksheet
@writer = Package::XMLWriterSimple.new
- @id = id
@row1, @row2, @col1, @col2, @param = handle_args(*args)
@columns = []
@col_formats = []
@@ -144,10 +145,15 @@
end
i += 1
end
end
+ def prepare(id)
+ @id = id
+ @name ||= "Table#{id}"
+ end
+
private
def handle_args(*args)
# Check for a cell reference in A1 notation and substitute row and column
row1, col1, row2, col2, param = row_col_notation(args)
@@ -262,16 +268,11 @@
@style = "TableStyleMedium9"
end
end
def set_the_table_name
- if @param[:name]
- @name = @param[:name]
- else
- # Set a default name.
- @name = "Table#{@id}"
- end
+ @name = @param[:name] if @param[:name]
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)
@@ -285,10 +286,10 @@
schema = 'http://schemas.openxmlformats.org/'
xmlns = "#{schema}spreadsheetml/2006/main"
attributes = [
['xmlns', xmlns],
- ['id', @id],
+ ['id', id],
['name', @name],
['displayName', @name],
['ref', @range]
]