lib/write_xlsx/package/table.rb in write_xlsx-0.64.1 vs lib/write_xlsx/package/table.rb in write_xlsx-0.65.0
- old
+ new
@@ -22,11 +22,11 @@
@format = nil
@user_data = param[id-1] if param
end
end
- attr_reader :id
+# attr_reader :id
def initialize(worksheet, id, *args)
@worksheet = worksheet
@writer = Package::XMLWriterSimple.new
@id = id
@@ -59,21 +59,16 @@
# Assemble and writes the XML file.
#
def assemble_xml_file
write_xml_declaration
# Write the table element.
- write_table
- # Write the autoFilter element.
- write_auto_filter
- # Write the tableColumns element.
- write_table_columns
- # Write the tableStyleInfo element.
- write_table_style_info
+ @writer.tag_elements('table', write_table_attributes) do
+ write_auto_filter
+ write_table_columns
+ write_table_style_info
+ end
- # Close the table tag
- @writer.end_tag('table')
-
# Close the XML writer object and filehandle.
@writer.crlf
@writer.close
end
@@ -288,11 +283,11 @@
def set_the_table_name
if @param[:name]
@name = @param[:name]
else
# Set a default name.
- @name = "Table#{id}"
+ @name = "Table#{@id}"
end
end
def set_the_table_and_autofilter_ranges
@range = xl_range(@row1, @row2, @col1, @col2)
@@ -308,20 +303,17 @@
#
def write_xml_declaration
@writer.xml_decl('UTF-8', 1)
end
- #
- # Write the <table> element.
- #
- def write_table
+ def write_table_attributes
schema = 'http://schemas.openxmlformats.org/'
xmlns = "#{schema}spreadsheetml/2006/main"
attributes = [
'xmlns', xmlns,
- 'id', id,
+ 'id', @id,
'name', @name,
'displayName', @name,
'ref', @range
]
@@ -332,10 +324,9 @@
if ptrue?(@totals_row_shown)
attributes << 'totalsRowCount' << 1
else
attributes << 'totalsRowShown' << 0
end
- @writer.start_tag('table', attributes)
end
#
# Write the <autoFilter> element.
#