lib/write_xlsx/worksheet.rb in write_xlsx-0.0.3 vs lib/write_xlsx/worksheet.rb in write_xlsx-0.0.4
- old
+ new
@@ -107,150 +107,150 @@
attr_reader :row, :col, :token, :xf
attr_reader :result, :range, :link_type, :url, :tip
#
- # Write the <cell> element. This is the innermost loop so efficiency is
+ # attributes for the <cell> element. This is the innermost loop so efficiency is
# important where possible.
#
- def write_cell(worksheet) #:nodoc:
- xf_index = 0
- xf_index = xf.get_xf_index if xf.respond_to?(:get_xf_index)
-
+ def cell_attributes #:nodoc:
+ xf_index = xf ? xf.get_xf_index : 0
attributes = ['r', xl_rowcol_to_cell(row, col)]
# Add the cell format index.
if xf_index != 0
attributes << 's' << xf_index
- elsif worksheet.set_rows[row] && worksheet.set_rows[row][1]
- row_xf = worksheet.set_rows[row][1]
+ elsif @worksheet.set_rows[row] && @worksheet.set_rows[row][1]
+ row_xf = @worksheet.set_rows[row][1]
attributes << 's' << row_xf.get_xf_index
- elsif worksheet.col_formats[col]
- col_xf = worksheet.col_formats[col]
+ elsif @worksheet.col_formats[col]
+ col_xf = @worksheet.col_formats[col]
attributes << 's' << col_xf.get_xf_index
end
attributes
end
end
class NumberCellData < CellData # :nodoc:
- def initialize(row, col, num, xf)
+ def initialize(worksheet, row, col, num, xf)
+ @worksheet = worksheet
@row, @col, @token, @xf = row, col, num, xf
end
def data
@token
end
- def write_cell(worksheet)
- attributes = super(worksheet)
- worksheet.writer.start_tag('c', attributes)
- worksheet.write_cell_value(token)
- worksheet.writer.end_tag('c')
+ def write_cell
+ @worksheet.writer.tag_elements('c', cell_attributes) do
+ @worksheet.write_cell_value(token)
+ end
end
end
class StringCellData < CellData # :nodoc:
- def initialize(row, col, index, xf)
+ def initialize(worksheet, row, col, index, xf)
+ @worksheet = worksheet
@row, @col, @token, @xf = row, col, index, xf
end
def data
{ :sst_id => token }
end
- def write_cell(worksheet)
- attributes = super(worksheet)
+ def write_cell
+ attributes = cell_attributes
attributes << 't' << 's'
- worksheet.writer.start_tag('c', attributes)
- worksheet.write_cell_value(token)
- worksheet.writer.end_tag('c')
+ @worksheet.writer.tag_elements('c', attributes) do
+ @worksheet.write_cell_value(token)
+ end
end
end
class FormulaCellData < CellData # :nodoc:
- def initialize(row, col, formula, xf, result)
+ def initialize(worksheet, row, col, formula, xf, result)
+ @worksheet = worksheet
@row, @col, @token, @xf, @result = row, col, formula, xf, result
end
def data
@result || 0
end
- def write_cell(worksheet)
- attributes = super(worksheet)
- worksheet.writer.start_tag('c', attributes)
- worksheet.write_cell_formula(token)
- worksheet.write_cell_value(result || 0)
- worksheet.writer.end_tag('c')
+ def write_cell
+ @worksheet.writer.tag_elements('c', cell_attributes) do
+ @worksheet.write_cell_formula(token)
+ @worksheet.write_cell_value(result || 0)
+ end
end
end
class FormulaArrayCellData < CellData # :nodoc:
- def initialize(row, col, formula, xf, range, result)
+ def initialize(worksheet, row, col, formula, xf, range, result)
+ @worksheet = worksheet
@row, @col, @token, @xf, @range, @result = row, col, formula, xf, range, result
end
def data
@result || 0
end
- def write_cell(worksheet)
- attributes = super(worksheet)
- worksheet.writer.start_tag('c', attributes)
- worksheet.write_cell_array_formula(token, range)
- worksheet.write_cell_value(result)
- worksheet.writer.end_tag('c')
+ def write_cell
+ @worksheet.writer.tag_elements('c', cell_attributes) do
+ @worksheet.write_cell_array_formula(token, range)
+ @worksheet.write_cell_value(result)
+ end
end
end
class HyperlinkCellData < CellData # :nodoc:
- def initialize(row, col, index, xf, link_type, url, str, tip)
+ def initialize(worksheet, row, col, index, xf, link_type, url, str, tip)
+ @worksheet = worksheet
@row, @col, @token, @xf, @link_type, @url, @str, @tip =
row, col, index, xf, link_type, url, str, tip
end
def data
{ :sst_id => token }
end
- def write_cell(worksheet)
- attributes = super(worksheet)
+ def write_cell
+ attributes = cell_attributes
attributes << 't' << 's'
- worksheet.writer.start_tag('c', attributes)
- worksheet.write_cell_value(token)
- worksheet.writer.end_tag('c')
+ @worksheet.writer.tag_elements('c', attributes) do
+ @worksheet.write_cell_value(token)
+ end
if link_type == 1
# External link with rel file relationship.
- worksheet.hlink_count += 1
- worksheet.hlink_refs <<
+ @worksheet.hlink_count += 1
+ @worksheet.hlink_refs <<
[
link_type, row, col,
- worksheet.hlink_count, @str, @tip
+ @worksheet.hlink_count, @str, @tip
]
- worksheet.external_hyper_links << [ '/hyperlink', @url, 'External' ]
+ @worksheet.external_hyper_links << [ '/hyperlink', @url, 'External' ]
elsif link_type
# External link with rel file relationship.
- worksheet.hlink_refs << [link_type, row, col, @url, @str, @tip ]
+ @worksheet.hlink_refs << [link_type, row, col, @url, @str, @tip ]
end
end
end
class BlankCellData < CellData # :nodoc:
- def initialize(row, col, index, xf)
+ def initialize(worksheet, row, col, index, xf)
+ @worksheet = worksheet
@row, @col, @xf = row, col, xf
end
def data
''
end
- def write_cell(worksheet)
- attributes = super(worksheet)
- worksheet.writer.empty_tag('c', attributes)
+ def write_cell
+ @worksheet.writer.empty_tag('c', cell_attributes)
end
end
class PrintStyle # :nodoc:
attr_accessor :margin_left, :margin_right, :margin_top, :margin_bottom # :nodoc:
@@ -722,18 +722,18 @@
# Check that cols are valid and store max and min values with default row.
# NOTE: The check shouldn't modify the row dimensions and should only modify
# the column dimensions in certain cases.
ignore_row = 1
ignore_col = 1
- ignore_col = 0 if format.respond_to?(:get_xf_index) # Column has a format.
+ ignore_col = 0 if format.respond_to?(:xf_index) # Column has a format.
ignore_col = 0 if width && hidden && hidden != 0 # Column has a width but is hidden
check_dimensions_and_update_max_min_values(0, firstcol, ignore_row, ignore_col)
check_dimensions_and_update_max_min_values(0, lastcol, ignore_row, ignore_col)
# Set the limits for the outline levels (0 <= x <= 7).
- level = 0 unless level
+ level ||= 0
level = 0 if level < 0
level = 7 if level > 7
@outline_col_level = level if level > @outline_col_level
@@ -2070,17 +2070,15 @@
def write_number(*args)
# Check for a cell reference in A1 notation and substitute row and column
row, col, num, xf = row_col_notation(args)
raise WriteXLSXInsufficientArgumentError if [row, col, num].include?(nil)
- type = 'n'
-
# Check that row and col are valid and store max and min values
check_dimensions(row, col)
store_row_col_max_min_values(row, col)
- store_data_to_table(NumberCellData.new(row, col, num, xf))
+ store_data_to_table(NumberCellData.new(self, row, col, num, xf))
end
#
# :call-seq:
# write_string(row, column, string [, format ] )
@@ -2119,11 +2117,11 @@
check_dimensions(row, col)
store_row_col_max_min_values(row, col)
index = shared_string_index(str[0, STR_MAX])
- store_data_to_table(StringCellData.new(row, col, index, xf))
+ store_data_to_table(StringCellData.new(self, row, col, index, xf))
end
#
# :call-seq:
# write_rich_string(row, column, (string | format, string)+, [,cell_format] )
@@ -2220,16 +2218,15 @@
# Check for a cell reference in A1 notation and substitute row and column
row, col, *rich_strings = row_col_notation(args)
raise WriteXLSXInsufficientArgumentError if [row, col, rich_strings[0]].include?(nil)
# If the last arg is a format we use it as the cell format.
- if rich_strings[-1].respond_to?(:get_xf_index)
+ if rich_strings[-1].respond_to?(:xf_index)
xf = rich_strings.pop
else
- xf = nil
+ xf = nil
end
- type = 's' # The data type.
# Check that row and col are valid and store max and min values
check_dimensions(row, col)
store_row_col_max_min_values(row, col)
@@ -2238,15 +2235,15 @@
writer = Package::XMLWriterSimple.new
fragments, length = rich_strings_fragments(rich_strings)
# If the first token is a string start the <r> element.
- writer.start_tag('r') if !fragments[0].respond_to?(:get_xf_index)
+ writer.start_tag('r') if !fragments[0].respond_to?(:xf_index)
# Write the XML elements for the format string fragments.
fragments.each do |token|
- if token.respond_to?(:get_xf_index)
+ if token.respond_to?(:xf_index)
# Write the font run.
writer.start_tag('r')
write_font(writer, token)
else
# Write the string fragment part, with whitespace handling.
@@ -2259,11 +2256,11 @@
end
# Add the XML string to the shared string table.
index = shared_string_index(writer.string)
- store_data_to_table(StringCellData.new(row, col, index, xf))
+ store_data_to_table(StringCellData.new(self, row, col, index, xf))
end
#
# :call-seq:
# write_blank(row, col, format)
@@ -2301,11 +2298,11 @@
# Check that row and col are valid and store max and min values
check_dimensions(row, col)
store_row_col_max_min_values(row, col)
- store_data_to_table(BlankCellData.new(row, col, nil, xf))
+ store_data_to_table(BlankCellData.new(self, row, col, nil, xf))
end
#
# :call-seq:
# write_formula(row, column, formula [ , format [ , value ] ] )
@@ -2341,20 +2338,18 @@
# Check for a cell reference in A1 notation and substitute row and column
row, col, formula, format, value = row_col_notation(args)
raise WriteXLSXInsufficientArgumentError if [row, col, formula].include?(nil)
if formula =~ /^\{=.*\}$/
- return write_array_formula(row, col, row, col, formula, format, value)
- end
+ write_array_formula(row, col, row, col, formula, format, value)
+ else
+ check_dimensions(row, col)
+ store_row_col_max_min_values(row, col)
+ formula.sub!(/^=/, '')
- # Check that row and col are valid and store max and min values
- check_dimensions(row, col)
- store_row_col_max_min_values(row, col)
-
- formula.sub!(/^=/, '')
-
- store_data_to_table(FormulaCellData.new(row, col, formula, format, value))
+ store_data_to_table(FormulaCellData.new(self, row, col, formula, format, value))
+ end
end
#
# :call-seq:
# write_array_formula(row1, col1, row2, col2, formula [ , format [ , value ] ] )
@@ -2423,11 +2418,11 @@
# Remove array formula braces and the leading =.
formula.sub!(/^\{(.*)\}$/, '\1')
formula.sub!(/^=/, '')
- store_data_to_table(FormulaArrayCellData.new(row1, col1, formula, xf, range, value))
+ store_data_to_table(FormulaArrayCellData.new(self, row1, col1, formula, xf, range, value))
end
# The outline_settings() method is used to control the appearance of
# outlines in Excel. Outlines are described in "OUTLINES AND GROUPING IN EXCEL".
#
@@ -2545,11 +2540,10 @@
# Check for a cell reference in A1 notation and substitute row and column
row, col, url, xf, str, tip = row_col_notation(args)
xf, str = str, xf if str.respond_to?(:xf_index)
raise WriteXLSXInsufficientArgumentError if [row, col, url].include?(nil)
- type = 'l' # XML data type
link_type = 1
# Remove the URI scheme from internal links.
if url =~ /^internal:/
url.sub!(/^internal:/, '')
@@ -2559,11 +2553,11 @@
url.sub!(/^external:/, '')
link_type = 3
end
# The displayed string defaults to the url string.
- str = url unless str
+ str ||= url
# For external links change the directory separator from Unix to Dos.
if link_type == 3
url.gsub!(%r|/|, '\\')
str.gsub!(%r|/|, '\\')
@@ -2597,11 +2591,11 @@
# Treat as a default external link now that the data has been modified.
link_type = 1
end
- store_data_to_table(HyperlinkCellData.new(row, col, index, xf, link_type, url, str, tip))
+ store_data_to_table(HyperlinkCellData.new(self, row, col, index, xf, link_type, url, str, tip))
end
#
# :call-seq:
# write_date_time (row, col, date_string [ , format ] )
@@ -2654,13 +2648,16 @@
check_dimensions(row, col)
store_row_col_max_min_values(row, col)
date_time = convert_date_time(str)
- # If the date isn't valid then write it as a string.
- return write_string(args) unless date_time
- store_data_to_table(NumberCellData.new(row, col, date_time, xf))
+ if date_time
+ store_data_to_table(NumberCellData.new(self, row, col, date_time, xf))
+ else
+ # If the date isn't valid then write it as a string.
+ write_string(args) unless date_time
+ end
end
#
# :call-seq:
# insert_chart(row, column, chart [ , x, y, scale_x, scale_y ] )
@@ -3046,11 +3043,11 @@
#
def merge_range(*args)
row_first, col_first, row_last, col_last, string, format, *extra_args = row_col_notation(args)
raise "Incorrect number of arguments" if [row_first, col_first, row_last, col_last, format].include?(nil)
- raise "Fifth parameter must be a format object" unless format.respond_to?(:get_xf_index)
+ raise "Fifth parameter must be a format object" unless format.respond_to?(:xf_index)
raise "Can't merge single cell" if row_first == row_last && col_first == col_last
# Swap last row/col with first row/col as necessary
row_first, row_last = row_last, row_first if row_first > row_last
col_first, col_last = col_last, col_first if col_first > col_last
@@ -3079,11 +3076,11 @@
format = others.pop
else
row_first, col_first, row_last, col_last, token, format, *others = row_col_notation(args)
end
- raise "Format object missing or in an incorrect position" unless format.respond_to?(:get_xf_index)
+ raise "Format object missing or in an incorrect position" unless format.respond_to?(:xf_index)
raise "Can't merge single cell" if row_first == row_last && col_first == col_last
# Swap last row/col with first row/col as necessary
row_first, row_last = row_last, row_first if row_first > row_last
col_first, col_last = col_last, col_first if col_first > col_last
@@ -4342,20 +4339,10 @@
param[:dropdown] ||= 1
param[:show_input] ||= 1
param[:show_error] ||= 1
end
- # Minor modification to allow comparison testing. Change RGB colors
- # from long format, ffcc00 to short format fc0 used by VML.
- def rgb_color(rgb)
- result = sprintf("%02x%02x%02x", *rgb)
- if result =~ /^([0-9a-f])\1([0-9a-f])\2([0-9a-f])\3$/
- result = "#{$1}#{$2}#{$3}"
- end
- result
- end
-
# List of valid input parameters.
def valid_validation_parameter
[
:validate,
:criteria,
@@ -4404,11 +4391,11 @@
last = 'format'
pos = 0
fragments = []
rich_strings.each do |token|
- if token.respond_to?(:get_xf_index)
+ if token.respond_to?(:xf_index)
raise AugumentError, "Can't allow 2 formats in a row" if last == 'format' && pos > 0
# Token is a format object. Add it to the fragment list.
fragments << token
last = 'format'
@@ -4835,14 +4822,14 @@
return if !fit_page? && !filter_on? && !tab_color?
attributes = []
(attributes << 'filterMode' << 1) if filter_on?
if fit_page? || tab_color?
- @writer.start_tag('sheetPr', attributes)
- write_tab_color
- write_page_set_up_pr
- @writer.end_tag('sheetPr')
+ @writer.tag_elements('sheetPr', attributes) do
+ write_tab_color
+ write_page_set_up_pr
+ end
else
@writer.empty_tag('sheetPr', attributes)
end
end
@@ -4890,13 +4877,11 @@
end
#
# Write the <sheetViews> element.
#
def write_sheet_views #:nodoc:
- @writer.start_tag('sheetViews', [])
- write_sheet_view
- @writer.end_tag('sheetViews')
+ @writer.tag_elements('sheetViews', []) { write_sheet_view }
end
def write_sheet_view #:nodoc:
attributes = []
# Hide screen gridlines if required
@@ -4924,14 +4909,14 @@
attributes << 'workbookViewId' << 0
if @panes.empty? && @selections.empty?
@writer.empty_tag('sheetView', attributes)
else
- @writer.start_tag('sheetView', attributes)
- write_panes
- write_selections
- @writer.end_tag('sheetView')
+ @writer.tag_elements('sheetView', attributes) do
+ write_panes
+ write_selections
+ end
end
end
#
# Write the <selection> elements.
@@ -4970,14 +4955,13 @@
#
def write_cols #:nodoc:
# Exit unless some column have been formatted.
return if @colinfo.empty?
- @writer.start_tag('cols')
- @colinfo.each {|col_info| write_col_info(*col_info) }
-
- @writer.end_tag('cols')
+ @writer.tag_elements('cols') do
+ @colinfo.each {|col_info| write_col_info(*col_info) }
+ end
end
#
# Write the <col> element.
#
@@ -4987,27 +4971,19 @@
width = args[2] # Col width in user units.
format = args[3] # Format index.
hidden = args[4] || 0 # Hidden flag.
level = args[5] || 0 # Outline level.
collapsed = args[6] || 0 # Outline level.
+ xf_index = format ? format.get_xf_index : 0
custom_width = true
- xf_index = 0
- xf_index = format.get_xf_index if format.respond_to?(:get_xf_index)
+ custom_width = false if width.nil? && hidden == 0
+ custom_width = false if width == 8.43
- # Set the Excel default col width.
if width.nil?
- if hidden == 0
- width = 8.43
- custom_width = false
- else
- width = 0
- end
- else
- # Width is defined but same as default.
- custom_width = false if width == 8.43
- end
+ width = hidden == 0 ? 8.43 : 0
+ end
# Convert column width from user units to character width.
max_digit_width = 7.0 # For Calabri 11.
padding = 5.0
if width && width > 0
@@ -5034,13 +5010,11 @@
def write_sheet_data #:nodoc:
if !@dim_rowmin
# If the dimensions aren't defined then there is no data to write.
@writer.empty_tag('sheetData')
else
- @writer.start_tag('sheetData')
- write_rows
- @writer.end_tag('sheetData')
+ @writer.tag_elements('sheetData') { write_rows }
end
end
#
# Write out the worksheet data as a series of rows and cells.
@@ -5110,11 +5084,11 @@
!@set_rows[row_num] && !@cell_data_table[row_num] && !@comments.has_comment_in_row?(row_num)
end
def write_cell_column_dimension(row_num) # :nodoc:
(@dim_colmin .. @dim_colmax).each do |col_num|
- @cell_data_table[row_num][col_num].write_cell(self) if @cell_data_table[row_num][col_num]
+ @cell_data_table[row_num][col_num].write_cell if @cell_data_table[row_num][col_num]
end
end
#
# Write the <row> element.
@@ -5123,16 +5097,14 @@
height ||= 15
hidden ||= 0
level ||= 0
collapsed ||= 0
empty_row ||= 0
- xf_index = 0
+ xf_index = format ? format.get_xf_index : 0
attributes = ['r', r + 1]
- xf_index = format.get_xf_index if format
-
(attributes << 'spans' << spans) if spans
(attributes << 's' << xf_index) if xf_index != 0
(attributes << 'customFormat' << 1 ) if format
(attributes << 'ht' << height) if height != 15
(attributes << 'hidden' << 1 ) if !!hidden && hidden != 0
@@ -5360,13 +5332,11 @@
#
# Write the <extLst> element.
#
def write_ext_lst #:nodoc:
- @writer.start_tag('extLst')
- write_ext
- @writer.end_tag('extLst')
+ @writer.tag_elements('extLst') { write_ext }
end
#
# Write the <ext> element.
#
@@ -5377,13 +5347,11 @@
attributes = [
'xmlns:mx', xmlnsmx,
'uri', uri
]
- @writer.start_tag('ext', attributes)
- write_mx_plv
- @writer.end_tag('ext')
+ @writer.tag_elements('ext', attributes) { write_mx_plv }
end
#
# Write the <mx:PLV> element.
#
@@ -5407,16 +5375,14 @@
def write_merge_cells #:nodoc:
return if @merge.empty?
attributes = ['count', @merge.size]
- @writer.start_tag('mergeCells', attributes)
-
- # Write the mergeCell element.
- @merge.each { |merged_range| write_merge_cell(merged_range) }
-
- @writer.end_tag('mergeCells')
+ @writer.tag_elements('mergeCells', attributes) do
+ # Write the mergeCell element.
+ @merge.each { |merged_range| write_merge_cell(merged_range) }
+ end
end
#
# Write the <mergeCell> element.
@@ -5461,24 +5427,23 @@
# Write the <headerFooter> element.
#
def write_header_footer #:nodoc:
return unless header_footer_changed?
- @writer.start_tag('headerFooter')
- write_odd_header if @header && @header != ''
- write_odd_footer if @footer && @footer != ''
- @writer.end_tag('headerFooter')
+ @writer.tag_elements('headerFooter') do
+ write_odd_header if @header && @header != ''
+ write_odd_footer if @footer && @footer != ''
+ end
end
#
# Write the <oddHeader> element.
#
def write_odd_header #:nodoc:
@writer.data_element('oddHeader', @header)
end
- # _write_odd_footer()
#
# Write the <oddFooter> element.
#
def write_odd_footer #:nodoc:
@writer.data_element('oddFooter', @footer)
@@ -5513,13 +5478,13 @@
return if page_breaks.empty?
attributes = ['count', count, 'manualBreakCount', count]
- @writer.start_tag(tag, attributes)
- page_breaks.each { |num| write_brk(num, max) }
- @writer.end_tag(tag)
+ @writer.tag_elements(tag, attributes) do
+ page_breaks.each { |num| write_brk(num, max) }
+ end
end
#
# Write the <brk> element.
#
def write_brk(id, max) #:nodoc:
@@ -5540,13 +5505,13 @@
attributes = ['ref', @autofilter_ref]
if filter_on?
# Autofilter defined active filters.
- @writer.start_tag('autoFilter', attributes)
- write_autofilters
- @writer.end_tag('autoFilter')
+ @writer.tag_elements('autoFilter', attributes) do
+ write_autofilters
+ end
else
# Autofilter defined without active filters.
@writer.empty_tag('autoFilter', attributes)
end
end
@@ -5574,20 +5539,19 @@
# Write the <filterColumn> element.
#
def write_filter_column(col_id, type, *filters) #:nodoc:
attributes = ['colId', col_id]
- @writer.start_tag('filterColumn', attributes)
- if type == 1
- # Type == 1 is the new XLSX style filter.
- write_filters(*filters)
- else
- # Type == 0 is the classic "custom" filter.
- write_custom_filters(*filters)
+ @writer.tag_elements('filterColumn', attributes) do
+ if type == 1
+ # Type == 1 is the new XLSX style filter.
+ write_filters(*filters)
+ else
+ # Type == 0 is the classic "custom" filter.
+ write_custom_filters(*filters)
+ end
end
-
- @writer.end_tag('filterColumn')
end
#
# Write the <filters> element.
#
@@ -5595,13 +5559,13 @@
if filters.size == 1 && filters[0] == 'blanks'
# Special case for blank cells only.
@writer.empty_tag('filters', ['blank', 1])
else
# General case.
- @writer.start_tag('filters')
- filters.each { |filter| write_filter(filter) }
- @writer.end_tag('filters')
+ @writer.tag_elements('filters') do
+ filters.each { |filter| write_filter(filter) }
+ end
end
end
#
# Write the <filter> element.
@@ -5615,13 +5579,11 @@
# Write the <customFilters> element.
#
def write_custom_filters(*tokens) #:nodoc:
if tokens.size == 2
# One filter expression only.
- @writer.start_tag('customFilters')
- write_custom_filter(*tokens)
- @writer.end_tag('customFilters')
+ @writer.tag_elements('customFilters') { write_custom_filter(*tokens) }
else
# Two filter expressions.
# Check if the "join" operand is "and" or "or".
if tokens[2] == 0
@@ -5629,14 +5591,14 @@
else
attributes = ['and', 0]
end
# Write the two custom filters.
- @writer.start_tag('customFilters', attributes)
- write_custom_filter(tokens[0], tokens[1])
- write_custom_filter(tokens[3], tokens[4])
- @writer.end_tag('customFilters')
+ @writer.tag_elements('customFilters', attributes) do
+ write_custom_filter(tokens[0], tokens[1])
+ write_custom_filter(tokens[3], tokens[4])
+ end
end
end
#
@@ -5673,23 +5635,21 @@
# and external links.
#
def write_hyperlinks #:nodoc:
return if @hlink_refs.empty?
- @writer.start_tag('hyperlinks')
+ @writer.tag_elements('hyperlinks') do
+ @hlink_refs.each do |aref|
+ type, *args = aref
- @hlink_refs.each do |aref|
- type, *args = aref
-
- if type == 1
- write_hyperlink_external(*args)
- elsif type == 2
- write_hyperlink_internal(*args)
+ if type == 1
+ write_hyperlink_external(*args)
+ elsif type == 2
+ write_hyperlink_internal(*args)
+ end
end
end
-
- @writer.end_tag('hyperlinks')
end
#
# Write the <hyperlink> element for external links.
#
@@ -5796,46 +5756,43 @@
#
# Write the <font> element.
#
def write_font(writer, format) #:nodoc:
- writer.start_tag('rPr')
+ writer.tag_elements('rPr') do
+ writer.empty_tag('b') if format.bold?
+ writer.empty_tag('i') if format.italic?
+ writer.empty_tag('strike') if format.strikeout?
+ writer.empty_tag('outline') if format.outline?
+ writer.empty_tag('shadow') if format.shadow?
- writer.empty_tag('b') if format.bold?
- writer.empty_tag('i') if format.italic?
- writer.empty_tag('strike') if format.strikeout?
- writer.empty_tag('outline') if format.outline?
- writer.empty_tag('shadow') if format.shadow?
+ # Handle the underline variants.
+ write_underline(writer, format.underline) if format.underline?
- # Handle the underline variants.
- write_underline(writer, format.underline) if format.underline?
+ write_vert_align(writer, 'superscript') if format.font_script == 1
+ write_vert_align(writer, 'subscript') if format.font_script == 2
- write_vert_align(writer, 'superscript') if format.font_script == 1
- write_vert_align(writer, 'subscript') if format.font_script == 2
+ writer.empty_tag('sz', ['val', format.size])
- writer.empty_tag('sz', ['val', format.size])
+ theme = format.theme
+ color = format.color
+ if !theme.nil? && theme != 0
+ write_color(writer, 'theme', theme)
+ elsif !color.nil? && color != 0
+ color = get_palette_color(color)
+ write_color(writer, 'rgb', color)
+ else
+ write_color(writer, 'theme', 1)
+ end
- theme = format.theme
- color = format.color
- if !theme.nil? && theme != 0
- write_color(writer, 'theme', theme)
- elsif !color.nil? && color != 0
- color = get_palette_color(color)
+ writer.empty_tag('rFont', ['val', format.font])
+ writer.empty_tag('family', ['val', format.font_family])
- write_color(writer, 'rgb', color)
- else
- write_color(writer, 'theme', 1)
+ if format.font == 'Calibri' && format.hyperlink == 0
+ writer.empty_tag('scheme', ['val', format.font_scheme])
+ end
end
-
- writer.empty_tag('rFont', ['val', format.font])
- writer.empty_tag('family', ['val', format.font_family])
-
- if format.font == 'Calibri' && format.hyperlink == 0
- writer.empty_tag('scheme', ['val', format.font_scheme])
- end
-
- writer.end_tag('rPr')
end
#
# Write the underline font element.
#
@@ -5868,13 +5825,13 @@
def write_data_validations #:nodoc:
return if @validations.empty?
attributes = ['count', @validations.size]
- @writer.start_tag('dataValidations', attributes)
- @validations.each { |validation| write_data_validation(validation) }
- @writer.end_tag('dataValidations')
+ @writer.tag_elements('dataValidations', attributes) do
+ @validations.each { |validation| write_data_validation(validation) }
+ end
end
#
# Write the <dataValidation> element.
#
@@ -5920,19 +5877,16 @@
attributes << 'error' << param[:error_message] if param[:error_message]
attributes << 'promptTitle' << param[:input_title] if param[:input_title]
attributes << 'prompt' << param[:input_message] if param[:input_message]
attributes << 'sqref' << sqref
- @writer.start_tag('dataValidation', attributes)
-
- # Write the formula1 element.
- write_formula_1(param[:value])
-
- # Write the formula2 element.
- write_formula_2(param[:maximum]) if param[:maximum]
-
- @writer.end_tag('dataValidation')
+ @writer.tag_elements('dataValidation', attributes) do
+ # Write the formula1 element.
+ write_formula_1(param[:value])
+ # Write the formula2 element.
+ write_formula_2(param[:maximum]) if param[:maximum]
+ end
end
#
# Write the <formula1> element.
#
@@ -5975,15 +5929,13 @@
# Write the <conditionalFormatting> element.
#
def write_conditional_formatting(range, params) #:nodoc:
attributes = ['sqref', range]
- @writer.start_tag('conditionalFormatting', attributes)
-
- params.each { |param| write_cf_rule(param) }
-
- @writer.end_tag('conditionalFormatting')
+ @writer.tag_elements('conditionalFormatting', attributes) do
+ params.each { |param| write_cf_rule(param) }
+ end
end
#
# Write the <cfRule> element.
#
@@ -5994,21 +5946,19 @@
attributes << 'dxfId' << param[:format]
end
attributes << 'priority' << param[:priority]
attributes << 'operator' << param[:criteria]
- @writer.start_tag('cfRule', attributes)
-
- if param[:type] == 'cellIs'
- if param[:minimum] && param[:maximum]
- write_formula_tag(param[:minimum])
- write_formula_tag(param[:maximum])
- else
- write_formula_tag(param[:value])
+ @writer.tag_elements('cfRule', attributes) do
+ if param[:type] == 'cellIs'
+ if param[:minimum] && param[:maximum]
+ write_formula_tag(param[:minimum])
+ write_formula_tag(param[:maximum])
+ else
+ write_formula_tag(param[:value])
+ end
end
end
-
- @writer.end_tag('cfRule')
end
def store_data_to_table(cell_data) #:nodoc:
row, col = cell_data.row, cell_data.col
if @cell_data_table[row]