diff options
| author | Bruce Davidson <[email protected]> | 2016-01-13 19:48:00 +0000 |
|---|---|---|
| committer | Bruce Davidson <[email protected]> | 2016-01-13 19:48:00 +0000 |
| commit | c80c8b9d9be5542471d66afcc2ce4ddd80cac1f7 (patch) | |
| tree | f68585b3fa0f85d4b791395d34e8d226b850e209 | |
| parent | 776aaf53cb5c19c854c27f5daedd40431ad5b2ba (diff) | |
| download | caxlsx-c80c8b9d9be5542471d66afcc2ce4ddd80cac1f7.tar.gz caxlsx-c80c8b9d9be5542471d66afcc2ce4ddd80cac1f7.zip | |
Fix #440 - allow control of position of outline summary row/columns
| -rw-r--r-- | lib/axlsx/workbook/workbook.rb | 1 | ||||
| -rw-r--r-- | lib/axlsx/workbook/worksheet/outline_pr.rb | 33 | ||||
| -rw-r--r-- | lib/axlsx/workbook/worksheet/sheet_pr.rb | 10 | ||||
| -rw-r--r-- | test/workbook/worksheet/tc_outline_pr.rb | 19 |
4 files changed, 62 insertions, 1 deletions
diff --git a/lib/axlsx/workbook/workbook.rb b/lib/axlsx/workbook/workbook.rb index ddb13600..4ba44adb 100644 --- a/lib/axlsx/workbook/workbook.rb +++ b/lib/axlsx/workbook/workbook.rb @@ -11,6 +11,7 @@ require 'axlsx/workbook/worksheet/cell_serializer.rb' require 'axlsx/workbook/worksheet/cell.rb' require 'axlsx/workbook/worksheet/page_margins.rb' require 'axlsx/workbook/worksheet/page_set_up_pr.rb' +require 'axlsx/workbook/worksheet/outline_pr.rb' require 'axlsx/workbook/worksheet/page_setup.rb' require 'axlsx/workbook/worksheet/header_footer.rb' require 'axlsx/workbook/worksheet/print_options.rb' diff --git a/lib/axlsx/workbook/worksheet/outline_pr.rb b/lib/axlsx/workbook/worksheet/outline_pr.rb new file mode 100644 index 00000000..ae9ccf38 --- /dev/null +++ b/lib/axlsx/workbook/worksheet/outline_pr.rb @@ -0,0 +1,33 @@ +module Axlsx + + # The OutlinePr class manages serialization of a worksheet's outlinePr element, which provides various + # options to control outlining. + class OutlinePr + include Axlsx::OptionsParser + include Axlsx::Accessors + include Axlsx::SerializedAttributes + + serializable_attributes :summary_below, + :summary_right, + :apply_styles + + # These attributes are all boolean so I'm doing a bit of a hand + # waving magic show to set up the attriubte accessors + boolean_attr_accessor :summary_below, + :summary_right, + :apply_styles + + # Creates a new OutlinePr object + # @param [Worksheet] worksheet The worksheet that owns this OutlinePr object + def initialize(options = {}) + parse_options options + end + + # Serialize the object + # @param [String] str serialized output will be appended to this object if provided. + # @return [String] + def to_xml_string(str = '') + str << "<outlinePr #{serialized_attributes} />" + end + end +end diff --git a/lib/axlsx/workbook/worksheet/sheet_pr.rb b/lib/axlsx/workbook/worksheet/sheet_pr.rb index a299bc0f..fc9f5eac 100644 --- a/lib/axlsx/workbook/worksheet/sheet_pr.rb +++ b/lib/axlsx/workbook/worksheet/sheet_pr.rb @@ -1,6 +1,6 @@ module Axlsx - # The SheetPr class manages serialization fo a worksheet's sheetPr element. + # The SheetPr class manages serialization of a worksheet's sheetPr element. class SheetPr include Axlsx::OptionsParser include Axlsx::Accessors @@ -33,6 +33,7 @@ module Axlsx def initialize(worksheet, options={}) raise ArgumentError, "you must provide a worksheet" unless worksheet.is_a?(Worksheet) @worksheet = worksheet + @outline_pr = nil parse_options options end @@ -51,6 +52,7 @@ module Axlsx update_properties str << "<sheetPr #{serialized_attributes}>" tab_color.to_xml_string(str, 'tabColor') if tab_color + outline_pr.to_xml_string(str) if @outline_pr page_setup_pr.to_xml_string(str) str << "</sheetPr>" end @@ -60,6 +62,12 @@ module Axlsx def page_setup_pr @page_setup_pr ||= PageSetUpPr.new end + + # The OutlinePr for this sheet pr object + # @return [OutlinePr] + def outline_pr + @outline_pr ||= OutlinePr.new( @worksheet ) + end # @see tab_color def tab_color=(v) diff --git a/test/workbook/worksheet/tc_outline_pr.rb b/test/workbook/worksheet/tc_outline_pr.rb new file mode 100644 index 00000000..41a2b4ca --- /dev/null +++ b/test/workbook/worksheet/tc_outline_pr.rb @@ -0,0 +1,19 @@ +require 'tc_helper.rb' + +class TestOutlinePr < Test::Unit::TestCase + def setup + @outline_pr = Axlsx::OutlinePr.new(:summary_below => false, :summary_right => true, :apply_styles => false) + end + + def test_summary_below + assert_equal false, @outline_pr.summary_below + end + + def test_summary_right + assert_equal true, @outline_pr.summary_right + end + + def test_apply_styles + assert_equal false, @outline_pr.apply_styles + end +end |
