Skip to content

Commit

Permalink
Adding cleaner method to remove worksheet
Browse files Browse the repository at this point in the history
This takes account of removing defined names that refer to the deleted sheet, but doesn't consider any other formulae etc
  • Loading branch information
mezza committed May 11, 2015
1 parent ee79cd6 commit 339bd0a
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/rubyXL/convenience_methods.rb
Expand Up @@ -26,6 +26,18 @@ def add_worksheet(name = nil)
worksheets << new_worksheet
new_worksheet
end

# Remove the worksheet with the supplied name
#
# @param [String] The name for the worksheet to be deleted
#
# There may be formula/references/links to the deleted sheet, which will be reported when opening the resulting file
def remove_worksheet(name = nil)
unless name.nil?
worksheets.delete_if{|ws| ws.sheet_name == name}
defined_names.delete_if{|dn| dn.reference =~ Regexp.new("^#{name}!")}
end
end

def each
worksheets.each{ |i| yield i }
Expand Down

0 comments on commit 339bd0a

Please sign in to comment.