lib/write_xlsx/package/table.rb in write_xlsx-0.72.2 vs lib/write_xlsx/package/table.rb in write_xlsx-0.72.3.beta1
- old
+ new
@@ -55,21 +55,18 @@
#
# Assemble and writes the XML file.
#
def assemble_xml_file
- write_xml_declaration
- # Write the table element.
- @writer.tag_elements('table', write_table_attributes) do
- write_auto_filter
- write_table_columns
- write_table_style_info
+ write_xml_declaration do
+ # Write the table element.
+ @writer.tag_elements('table', write_table_attributes) do
+ write_auto_filter
+ write_table_columns
+ write_table_style_info
+ end
end
-
- # Close the XML writer object and filehandle.
- @writer.crlf
- @writer.close
end
def add_the_table_columns
col_id = 0
(@col1..@col2).each do |col_num|
@@ -282,58 +279,51 @@
def set_the_autofilter_range
@autofilter = @a_range if ptrue?(@param[:autofilter])
end
- #
- # Write the XML declaration.
- #
- def write_xml_declaration
- @writer.xml_decl('UTF-8', 1)
- end
-
def write_table_attributes
schema = 'http://schemas.openxmlformats.org/'
xmlns = "#{schema}spreadsheetml/2006/main"
attributes = [
- 'xmlns', xmlns,
- 'id', @id,
- 'name', @name,
- 'displayName', @name,
- 'ref', @range
+ ['xmlns', xmlns],
+ ['id', @id],
+ ['name', @name],
+ ['displayName', @name],
+ ['ref', @range]
]
unless ptrue?(@header_row_count)
- attributes << 'headerRowCount' << 0
+ attributes << ['headerRowCount', 0]
end
if ptrue?(@totals_row_shown)
- attributes << 'totalsRowCount' << 1
+ attributes << ['totalsRowCount', 1]
else
- attributes << 'totalsRowShown' << 0
+ attributes << ['totalsRowShown', 0]
end
end
#
# Write the <autoFilter> element.
#
def write_auto_filter
return unless ptrue?(@autofilter)
- attributes = ['ref', @autofilter]
+ attributes = [ ['ref', @autofilter] ]
@writer.empty_tag('autoFilter', attributes)
end
#
# Write the <tableColumns> element.
#
def write_table_columns
count = @columns.size
- attributes = ['count', count]
+ attributes = [ ['count', count] ]
@writer.tag_elements('tableColumns', attributes) do
@columns.each {|col_data| write_table_column(col_data)}
end
end
@@ -341,22 +331,22 @@
#
# Write the <tableColumn> element.
#
def write_table_column(col_data)
attributes = [
- 'id', col_data.id,
- 'name', col_data.name
+ ['id', col_data.id],
+ ['name', col_data.name]
]
if ptrue?(col_data.total_string)
- attributes << :totalsRowLabel << col_data.total_string
+ attributes << [:totalsRowLabel, col_data.total_string]
elsif ptrue?(col_data.total_function)
- attributes << :totalsRowFunction << col_data.total_function
+ attributes << [:totalsRowFunction, col_data.total_function]
end
if col_data.format
- attributes << :dataDxfId << col_data.format
+ attributes << [:dataDxfId, col_data.format]
end
if ptrue?(col_data.formula)
@writer.tag_elements('tableColumn', attributes) do
# Write the calculatedColumnFormula element.
@@ -370,14 +360,14 @@
#
# Write the <tableStyleInfo> element.
#
def write_table_style_info
attributes = [
- 'name', @style,
- 'showFirstColumn', @show_first_col,
- 'showLastColumn', @show_last_col,
- 'showRowStripes', @show_row_stripes,
- 'showColumnStripes', @show_col_stripes
+ ['name', @style],
+ ['showFirstColumn', @show_first_col],
+ ['showLastColumn', @show_last_col],
+ ['showRowStripes', @show_row_stripes],
+ ['showColumnStripes', @show_col_stripes]
]
@writer.empty_tag('tableStyleInfo', attributes)
end