lib/write_xlsx/worksheet.rb in write_xlsx-0.65.1 vs lib/write_xlsx/worksheet.rb in write_xlsx-0.69.0

- old
+ new

@@ -788,11 +788,11 @@ # If the first and last cell are the same write a single cell. if row_first == row_last && col_first == col_last sqref = active_cell else - sqref = xl_range(row_first, col_first, row_last, col_last) + sqref = xl_range(row_first, row_last, col_first, col_last) end end # Selection isn't set for cell A1. return if sqref == 'A1' @@ -5461,29 +5461,29 @@ def set_comments_author(author) put_deprecate_message("#{self}.set_comments_author") self.comments_author = author end - def comments_count # :nodoc: - @comments.size - end - def has_vml? # :nodoc: @has_vml end def has_comments? # :nodoc: !@comments.empty? end + def has_shapes? + @has_shapes + end + def is_chartsheet? # :nodoc: !!@is_chartsheet end - def set_external_vml_links(comment_id) # :nodoc: + def set_external_vml_links(vml_drawing_id) # :nodoc: @external_vml_links << - ['/vmlDrawing', "../drawings/vmlDrawing#{comment_id}.vml"] + ['/vmlDrawing', "../drawings/vmlDrawing#{vml_drawing_id}.vml"] end def set_external_comment_links(comment_id) # :nodoc: @external_comment_links << ['/comments', "../comments#{comment_id}.xml"] @@ -5660,11 +5660,11 @@ def comments_visible? # :nodoc: !!@comments_visible end - def comments_array # :nodoc: + def sorted_comments # :nodoc: @comments.sorted_comments end # # Write the cell value <v> element. @@ -5732,32 +5732,25 @@ # # Turn the HoH that stores the comments into an array for easier handling # and set the external links for comments and buttons. # - def prepare_vml_objects(vml_data_id, vml_shape_id, comment_id) - @external_vml_links << - [ '/vmlDrawing', "../drawings/vmlDrawing#{comment_id}.vml"] + def prepare_vml_objects(vml_data_id, vml_shape_id, vml_drawing_id, comment_id) + set_external_vml_links(vml_drawing_id) + set_external_comment_links(comment_id) if has_comments? - if has_comments? - @comments_array = @comments.sorted_comments - @external_comment_links << - [ '/comments', "../comments#{comment_id}.xml" ] - end - - count = @comments.size - start_data_id = vml_data_id - # The VML o:idmap data id contains a comma separated range when there is # more than one 1024 block of comments, like this: data="1,2". - (1 .. (count / 1024)).each do |i| - vml_data_id = "#{vml_data_id},#{start_data_id + i}" + (1 .. num_comments_block).each do |i| + vml_data_id = "#{vml_data_id},#{vml_data_id + i}" end @vml_data_id = vml_data_id @vml_shape_id = vml_shape_id + end - count + def num_comments_block + @comments.size / 1024 end def tables_count @tables.size end @@ -6242,10 +6235,11 @@ # Create a Drawing object to use with worksheet unless one already exists. unless drawing? @drawing = Drawing.new @drawing.embedded = 1 @external_drawing_links << ['/drawing', "../drawings/drawing#{drawing_id}.xml"] + @has_shapes = true end # Validate the he shape against various rules. shape.validate(index) shape.calc_position_emus(self) @@ -6591,61 +6585,23 @@ span_index = row_num / 16 span = @row_spans[span_index] # Write the cells if the row contains data. if @cell_data_table[row_num] - if !@set_rows[row_num] - write_row_element(row_num, span) - else - write_row_element(row_num, span, *(@set_rows[row_num])) + args = @set_rows[row_num] || [] + write_row_element(row_num, span, *args) do + write_cell_column_dimension(row_num) end - - write_cell_column_dimension(row_num) - @writer.end_tag('row') elsif @comments[row_num] write_empty_row(row_num, span, *(@set_rows[row_num])) else # Row attributes only. write_empty_row(row_num, span, *(@set_rows[row_num])) end end end - # - # Write out the worksheet data as a single row with cells. This method is - # used when memory optimisation is on. A single row is written and the data - # table is reset. That way only one row of data is kept in memory at any one - # time. We don't write span data in the optimised case since it is optional. - # - def write_single_row(current_row = 0) #:nodoc: - row_num = @previous_row - - # Set the new previous row as the current row. - @previous_row = current_row - - # Skip row if it doesn't contain row formatting, cell data or a comment. - return not_contain_formatting_or_data?(row_num) - - # Write the cells if the row contains data. - if @cell_data_table[row_num] - if !@set_rows[row_num] - write_row(row_num) - else - write_row(row_num, nil, @set_rows[row_num]) - end - - write_cell_column_dimension(row_num) - @writer.end_tag('row') - else - # Row attributes or comments only. - write_empty_row(row_num, nil, @set_rows[row_num]) - end - - # Reset table. - @cell_data_table = {} - end - def not_contain_formatting_or_data?(row_num) # :nodoc: !@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: @@ -6655,16 +6611,28 @@ end # # Write the <row> element. # - def write_row_element(r, spans = nil, height = nil, format = nil, hidden = false, level = 0, collapsed = false, empty_row = false) #:nodoc: + def write_row_element(*args) # :nodoc: + @writer.tag_elements('row', row_attributes(args)) do + yield + end + end + + # + # Write and empty <row> element, i.e., attributes only, no cell data. + # + def write_empty_row(*args) #:nodoc: + @writer.empty_tag('row', row_attributes(args)) + end + + def row_attributes(args) + r, spans, height, format, hidden, level, collapsed, empty_row = args height ||= @default_row_height hidden ||= 0 level ||= 0 - collapsed ||= 0 - empty_row ||= 0 xf_index = format ? format.get_xf_index : 0 attributes = ['r', r + 1] (attributes << 'spans' << spans) if spans @@ -6677,27 +6645,14 @@ (attributes << 'collapsed' << 1 ) if ptrue?(collapsed) if @excel_version == 2010 attributes << 'x14ac:dyDescent' << '0.25' end - if ptrue?(empty_row) - @writer.empty_tag('row', attributes) - else - @writer.start_tag('row', attributes) - end + attributes end # - # Write and empty <row> element, i.e., attributes only, no cell data. - # - def write_empty_row(*args) #:nodoc: - new_args = args.dup - new_args[7] = 1 - write_row_element(*new_args) - end - - # # Write the frozen or split <pane> elements. # def write_panes #:nodoc: return if @panes.empty? @@ -7146,14 +7101,13 @@ # # Write the <outlinePr> element. # def write_outline_pr - attributes = [] - return unless outline_changed? + attributes = [] attributes << "applyStyles" << 1 if @outline_style != 0 attributes << "summaryBelow" << 0 if @outline_below == 0 attributes << "summaryRight" << 0 if @outline_right == 0 attributes << "showOutlineSymbols" << 0 if @outline_on == 0 @@ -7226,19 +7180,19 @@ # # Write the <tablePart> element. # def write_table_part(id) - @writer.empty_tag('tablePart', ['r:id', "rId#{id}"]) + @writer.empty_tag('tablePart', r_id_attributes(id)) end def increment_rel_id_and_write_r_id(tag) @rel_count += 1 write_r_id(tag, @rel_count) end def write_r_id(tag, id) - @writer.empty_tag(tag, ['r:id', "rId#{id}"]) + @writer.empty_tag(tag, r_id_attributes(id)) end # # Write the <extLst> element and sparkline subelements. #