Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to change tab color #396

Merged
merged 1 commit into from
Jul 4, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions examples/example.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
examples << :cached_formula
examples << :page_breaks
examples << :rich_text
examples << :tab_color

p = Axlsx::Package.new
wb = p.workbook
Expand Down Expand Up @@ -843,3 +844,14 @@
p.serialize 'rich_text.xlsx'
end
#```

##Change tab color of sheet

#```ruby
if examples.include? :tab_color
wb.add_worksheet(:name => "Change Tab Color") do |sheet|
sheet.add_row ["Check", "out", "the", "Tab Color", "below!"]
sheet.sheet_pr.tab_color = "FFFF6666"
end
end
##```
10 changes: 10 additions & 0 deletions lib/axlsx/workbook/worksheet/sheet_pr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,17 @@ def initialize(worksheet, options={})
# @return [Worksheet]
attr_reader :worksheet

# The tab color of the sheet.
# @return [Color]
attr_reader :tab_color

# Serialize the object
# @param [String] str serialized output will be appended to this object if provided.
# @return [String]
def to_xml_string(str = '')
update_properties
str << "<sheetPr #{serialized_attributes}>"
tab_color.to_xml_string(str, 'tabColor') if tab_color
page_setup_pr.to_xml_string(str)
str << "</sheetPr>"
end
Expand All @@ -56,6 +61,11 @@ def page_setup_pr
@page_setup_pr ||= PageSetUpPr.new
end

# @see tab_color
def tab_color=(v)
@tab_color ||= Color.new(:rgb => v)
end

private

def update_properties
Expand Down