summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRandy Morgan <[email protected]>2012-09-30 09:07:36 +0900
committerRandy Morgan <[email protected]>2012-09-30 09:07:36 +0900
commit7d7650287ca27c599f62895ba0d84a8339ed9da1 (patch)
tree0293469e2e0e10cce7621aae6de9971413ce54ce
parent1232e91ae034f13a2e183b1c20d7af0e9d19112f (diff)
downloadcaxlsx-7d7650287ca27c599f62895ba0d84a8339ed9da1.tar.gz
caxlsx-7d7650287ca27c599f62895ba0d84a8339ed9da1.zip
Extracted and completed support for PageSetUpPr
-rw-r--r--lib/axlsx/workbook/workbook.rb1
-rw-r--r--lib/axlsx/workbook/worksheet/page_set_up_pr.rb47
-rw-r--r--test/workbook/worksheet/tc_page_set_up_pr.rb15
-rw-r--r--test/workbook/worksheet/tc_sheet_pr.rb27
4 files changed, 90 insertions, 0 deletions
diff --git a/lib/axlsx/workbook/workbook.rb b/lib/axlsx/workbook/workbook.rb
index f587c34c..956856ae 100644
--- a/lib/axlsx/workbook/workbook.rb
+++ b/lib/axlsx/workbook/workbook.rb
@@ -7,6 +7,7 @@ require 'axlsx/workbook/worksheet/protected_range.rb'
require 'axlsx/workbook/worksheet/protected_ranges.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/page_setup.rb'
require 'axlsx/workbook/worksheet/print_options.rb'
require 'axlsx/workbook/worksheet/cfvo.rb'
diff --git a/lib/axlsx/workbook/worksheet/page_set_up_pr.rb b/lib/axlsx/workbook/worksheet/page_set_up_pr.rb
new file mode 100644
index 00000000..52ff0c7d
--- /dev/null
+++ b/lib/axlsx/workbook/worksheet/page_set_up_pr.rb
@@ -0,0 +1,47 @@
+module Axlsx
+
+ # Page setup properties of the worksheet
+ # This class name is not a typo, its spec.
+ class PageSetUpPr
+
+ # creates a new page setup properties object
+ # @param [Hash] options
+ # @option [Boolean] auto_page_breaks Flag indicating whether the sheet displays Automatic Page Breaks.
+ # @option [Boolean] fit_to_page Flag indicating whether the Fit to Page print option is enabled.
+ def initialize(options = {})
+ options.each do |key, value|
+ self.send("#{key}=",value) if self.respond_to?("#{key}=")
+ end
+ end
+
+ attr_reader :auto_page_breaks
+ attr_reader :fit_to_page
+
+ # Flag indicating whether the Fit to Page print option is enabled.
+ # @param [Boolean] value
+ # @return [Boolean]
+ def fit_to_page=(value)
+ Axlsx.validate_boolean value
+ @fit_to_page = value
+ end
+
+ # Flag indicating whether the sheet displays Automatic Page Breaks.
+ # @param [Boolean] value
+ # @return [Boolean]
+ def auto_page_breaks=(value)
+ Axlsx.validate_boolean value
+ @auto_page_breaks = value
+ end
+
+ # serialize to xml
+ def to_xml_string(str='')
+ str << '<pageSetUpPr ' << serialized_attributes << '/>'
+ end
+
+ private
+
+ def serialized_attributes
+ instance_values.map { |key, value| "#{Axlsx.camel(key, false)}='#{value}'" }.join(' ')
+ end
+ end
+end
diff --git a/test/workbook/worksheet/tc_page_set_up_pr.rb b/test/workbook/worksheet/tc_page_set_up_pr.rb
new file mode 100644
index 00000000..d04097d0
--- /dev/null
+++ b/test/workbook/worksheet/tc_page_set_up_pr.rb
@@ -0,0 +1,15 @@
+require 'tc_helper.rb'
+
+class TestPageSetUpPr < Test::Unit::TestCase
+ def setup
+ @page_setup_pr = Axlsx::PageSetUpPr.new(:fit_to_page => true, :auto_page_breaks => true)
+ end
+
+ def test_fit_to_page
+ assert_equal true, @page_setup_pr.fit_to_page
+ end
+
+ def test_auto_page_breaks
+ assert_equal true, @page_setup_pr.auto_page_breaks
+ end
+end
diff --git a/test/workbook/worksheet/tc_sheet_pr.rb b/test/workbook/worksheet/tc_sheet_pr.rb
new file mode 100644
index 00000000..43f2941d
--- /dev/null
+++ b/test/workbook/worksheet/tc_sheet_pr.rb
@@ -0,0 +1,27 @@
+require 'tc_helper.rb'
+
+
+class TestSheetPr < Test::Unit::TestCase
+
+ def setup
+ worksheet = Axlsx::Package.new.workbook.add_worksheet
+ @options = {
+ :sync_horizontal => false,
+ :sync_vertical => false,
+ :transtion_evaluation => true,
+ :transition_entry => true,
+ :published => false,
+ :filter_mode => true,
+ :enable_format_conditions_calculation => false,
+ :code_name => '007',
+ :sync_ref => 'foo'
+ }
+ @sheet_pr = Axlsx::SheetPr.new(worksheet, @options)
+ end
+
+ def test_initialization
+ @options.each do |key, value|
+ assert_equal value, @sheet_pr.send(key)
+ end
+ end
+end