lib/rubyXL/convenience_methods.rb in rubyXL-3.3.6 vs lib/rubyXL/convenience_methods.rb in rubyXL-3.3.7

- old
+ new

@@ -182,9 +182,57 @@ end module WorksheetConvenienceMethods + def insert_cell(row = 0, col = 0, data = nil, formula = nil, shift = nil) + validate_workbook + ensure_cell_exists(row, col) + + case shift + when nil then # No shifting at all + when :right then + sheet_data.rows[row].insert_cell_shift_right(nil, col) + when :down then + add_row(sheet_data.size, :cells => Array.new(sheet_data.rows[row].size)) + (sheet_data.size - 1).downto(row+1) { |index| + sheet_data.rows[index].cells[col] = sheet_data.rows[index-1].cells[col] + } + else + raise 'invalid shift option' + end + + return add_cell(row,col,data,formula) + end + + # by default, only sets cell to nil + # if :left is specified, method will shift row contents to the right of the deleted cell to the left + # if :up is specified, method will shift column contents below the deleted cell upward + def delete_cell(row_index = 0, column_index=0, shift=nil) + validate_workbook + validate_nonnegative(row_index) + validate_nonnegative(column_index) + + row = sheet_data[row_index] + old_cell = row && row[column_index] + + case shift + when nil then + row.cells[column_index] = nil if row + when :left then + row.delete_cell_shift_left(column_index) if row + when :up then + (row_index...(sheet_data.size - 1)).each { |index| + c = sheet_data.rows[index].cells[column_index] = sheet_data.rows[index + 1].cells[column_index] + c.row -= 1 if c.is_a?(Cell) + } + else + raise 'invalid shift option' + end + + return old_cell + end + def get_row_fill(row = 0) (row = sheet_data.rows[row]) && row.get_fill_color end def get_row_font_name(row = 0)