lib/axlsx/workbook/worksheet/table.rb in axlsx-1.3.1 vs lib/axlsx/workbook/worksheet/table.rb in axlsx-1.3.2
- old
+ new
@@ -3,23 +3,12 @@
# Table
# @note Worksheet#add_table is the recommended way to create tables for your worksheets.
# @see README for examples
class Table
+ include Axlsx::OptionsParser
- # The reference to the table data
- # @return [String]
- attr_reader :ref
-
- # The name of the table.
- # @return [String]
- attr_reader :name
-
- # The style for the table.
- # @return [TableStyle]
- attr_reader :style
-
# Creates a new Table object
# @param [String] ref The reference to the table data like 'A1:G24'.
# @param [Worksheet] sheet The sheet containing the table data.
# @option options [Cell, String] name
# @option options [TableStyle] style
@@ -28,16 +17,26 @@
@sheet = sheet
@style = nil
@sheet.workbook.tables << self
@table_style_info = TableStyleInfo.new(options[:style_info]) if options[:style_info]
@name = "Table#{index+1}"
- options.each do |o|
- self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
- end
+ parse_options options
yield self if block_given?
end
+ # The reference to the table data
+ # @return [String]
+ attr_reader :ref
+
+ # The name of the table.
+ # @return [String]
+ attr_reader :name
+
+ # The style for the table.
+ # @return [TableStyle]
+ attr_reader :style
+
# The index of this chart in the workbooks charts collection
# @return [Integer]
def index
@sheet.workbook.tables.index(self)
end
@@ -61,11 +60,11 @@
DataTypeValidator.validate "#{self.class}.name", [String], v
if v.is_a?(String)
@name = v
end
end
-
+
# TableStyleInfo for the table.
# initialization can be fed via the :style_info option
def table_style_info
@table_style_info ||= TableStyleInfo.new
end
@@ -81,11 +80,10 @@
str << '<tableColumns count="' << header_cells.length.to_s << '">'
header_cells.each_with_index do |cell,index|
str << '<tableColumn id ="' << (index+1).to_s << '" name="' << cell.value << '"/>'
end
str << '</tableColumns>'
- #TODO implement tableStyleInfo
- table_style_info.to_xml_string(str) # '<tableStyleInfo showFirstColumn="0" showLastColumn="0" showRowStripes="1" showColumnStripes="0" name="TableStyleMedium9" />'
+ table_style_info.to_xml_string(str)
str << '</table>'
end
# The style for the table.
# TODO