summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJonathan Tron <[email protected]>2015-07-04 11:56:39 +0200
committerJonathan Tron <[email protected]>2015-07-04 11:56:39 +0200
commitdbb456aa65c7637233da174a5d515c80fe04aefd (patch)
treee3bc414a75b2a56ae08287759a17e6d1821ae74c
parent5a343241ed5ae7226ce691256118e51b44c60f87 (diff)
parent0c0d9d6e6efa95cf9e4ce1cb562345d9c5be2526 (diff)
downloadcaxlsx-dbb456aa65c7637233da174a5d515c80fe04aefd.tar.gz
caxlsx-dbb456aa65c7637233da174a5d515c80fe04aefd.zip
Merge branch 'shifakhan-worksheet_tab_colour'
-rwxr-xr-xexamples/example.rb18
-rw-r--r--lib/axlsx/workbook/worksheet/sheet_pr.rb14
-rw-r--r--test/workbook/worksheet/tc_sheet_pr.rb30
3 files changed, 55 insertions, 7 deletions
diff --git a/examples/example.rb b/examples/example.rb
index 15d34ed6..72066140 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
@@ -676,7 +677,7 @@ end
## Book Views
#
-## Book views let you specify which sheet the show as active when the user opens the work book as well as a bunch of other
+## Book views let you specify which sheet the show as active when the user opens the work book as well as a bunch of other
## tuning values for the UI @see Axlsx::WorkbookView
## ```ruby
if examples.include? :book_view
@@ -843,3 +844,18 @@ if examples.include? :rich_text
p.serialize 'rich_text.xlsx'
end
#```
+
+##Change tab color of sheet
+
+#```ruby
+if examples.include? :tab_color
+ p = Axlsx::Package.new
+ p.use_shared_strings = true
+ wb = p.workbook
+ 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
+ p.serialize 'tab_color.xlsx'
+end
+##```
diff --git a/lib/axlsx/workbook/worksheet/sheet_pr.rb b/lib/axlsx/workbook/worksheet/sheet_pr.rb
index f271419b..a299bc0f 100644
--- a/lib/axlsx/workbook/worksheet/sheet_pr.rb
+++ b/lib/axlsx/workbook/worksheet/sheet_pr.rb
@@ -8,7 +8,7 @@ module Axlsx
serializable_attributes :sync_horizontal,
:sync_vertical,
- :transtion_evaluation,
+ :transition_evaluation,
:transition_entry,
:published,
:filter_mode,
@@ -20,7 +20,7 @@ module Axlsx
# waving magic show to set up the attriubte accessors
boolean_attr_accessor :sync_horizontal,
:sync_vertical,
- :transtion_evaluation,
+ :transition_evaluation,
:transition_entry,
:published,
:filter_mode,
@@ -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
diff --git a/test/workbook/worksheet/tc_sheet_pr.rb b/test/workbook/worksheet/tc_sheet_pr.rb
index 43f2941d..be45438b 100644
--- a/test/workbook/worksheet/tc_sheet_pr.rb
+++ b/test/workbook/worksheet/tc_sheet_pr.rb
@@ -5,23 +5,45 @@ class TestSheetPr < Test::Unit::TestCase
def setup
worksheet = Axlsx::Package.new.workbook.add_worksheet
- @options = {
+ @options = {
:sync_horizontal => false,
:sync_vertical => false,
- :transtion_evaluation => true,
+ :transition_evaluation => true,
:transition_entry => true,
:published => false,
:filter_mode => true,
:enable_format_conditions_calculation => false,
:code_name => '007',
- :sync_ref => 'foo'
+ :sync_ref => 'foo',
+ :tab_color => 'FFFF6666'
}
@sheet_pr = Axlsx::SheetPr.new(worksheet, @options)
end
def test_initialization
@options.each do |key, value|
- assert_equal value, @sheet_pr.send(key)
+ if key==:tab_color
+ stored_value = @sheet_pr.send(key)
+ assert_equal Axlsx::Color, stored_value.class
+ assert_equal value, stored_value.rgb
+ else
+ assert_equal value, @sheet_pr.send(key)
+ end
end
end
+
+ def test_to_xml_string
+ doc = Nokogiri::XML(@sheet_pr.to_xml_string)
+ assert_equal(doc.xpath("//sheetPr[@syncHorizontal='0']").size, 1)
+ assert_equal(doc.xpath("//sheetPr[@syncVertical='0']").size, 1)
+ assert_equal(doc.xpath("//sheetPr[@transitionEvaluation='1']").size, 1)
+ assert_equal(doc.xpath("//sheetPr[@transitionEntry='1']").size, 1)
+ assert_equal(doc.xpath("//sheetPr[@published='0']").size, 1)
+ assert_equal(doc.xpath("//sheetPr[@filterMode='1']").size, 1)
+ assert_equal(doc.xpath("//sheetPr[@enableFormatConditionsCalculation='0']").size, 1)
+ assert_equal(doc.xpath("//sheetPr[@codeName='007']").size, 1)
+ assert_equal(doc.xpath("//sheetPr[@syncRef='foo']").size, 1)
+ assert_equal(doc.xpath("//sheetPr/tabColor[@rgb='FFFF6666']").size, 1)
+ assert_equal(doc.xpath("//sheetPr/pageSetUpPr[@fitToPage='0']").size, 1)
+ end
end