summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorshifakhan <[email protected]>2015-05-23 16:20:22 +0530
committershifakhan <[email protected]>2015-05-23 16:57:57 +0530
commita1006751413997ff5be88bd1321859d2f5dd566c (patch)
treec1f5fe8c5d64dfdb07aaff0c2511a1855885aa93
parent1bec39cebaef6a98481f52587ecc0483b4defc08 (diff)
downloadcaxlsx-a1006751413997ff5be88bd1321859d2f5dd566c.tar.gz
caxlsx-a1006751413997ff5be88bd1321859d2f5dd566c.zip
Option to change tab color
-rwxr-xr-xexamples/example.rb12
-rw-r--r--lib/axlsx/workbook/worksheet/sheet_pr.rb10
2 files changed, 22 insertions, 0 deletions
diff --git a/examples/example.rb b/examples/example.rb
index 15d34ed6..fb4fc924 100755
--- a/examples/example.rb
+++ b/examples/example.rb
@@ -51,6 +51,7 @@ examples << :no_autowidth
examples << :cached_formula
examples << :page_breaks
examples << :rich_text
+examples << :tab_color
p = Axlsx::Package.new
wb = p.workbook
@@ -843,3 +844,14 @@ if examples.include? :rich_text
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
+##``` \ No newline at end of file
diff --git a/lib/axlsx/workbook/worksheet/sheet_pr.rb b/lib/axlsx/workbook/worksheet/sheet_pr.rb
index f271419b..e0056770 100644
--- a/lib/axlsx/workbook/worksheet/sheet_pr.rb
+++ b/lib/axlsx/workbook/worksheet/sheet_pr.rb
@@ -40,12 +40,17 @@ module Axlsx
# @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
@@ -56,6 +61,11 @@ module Axlsx
@page_setup_pr ||= PageSetUpPr.new
end
+ # @see tab_color
+ def tab_color=(v)
+ @tab_color ||= Color.new(:rgb => v)
+ end
+
private
def update_properties