summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--axlsx.gemspec4
-rw-r--r--lib/axlsx/workbook/workbook.rb1
-rw-r--r--lib/axlsx/workbook/worksheet/cell.rb28
-rw-r--r--lib/axlsx/workbook/worksheet/outline_pr.rb33
-rw-r--r--lib/axlsx/workbook/worksheet/sheet_pr.rb10
-rw-r--r--test/workbook/tc_shared_strings_table.rb2
-rw-r--r--test/workbook/worksheet/tc_outline_pr.rb19
-rw-r--r--test/workbook/worksheet/tc_worksheet.rb10
8 files changed, 89 insertions, 18 deletions
diff --git a/axlsx.gemspec b/axlsx.gemspec
index 8e3cd9ca..b4cec557 100644
--- a/axlsx.gemspec
+++ b/axlsx.gemspec
@@ -17,9 +17,9 @@ Gem::Specification.new do |s|
s.files = Dir.glob("{lib/**/*,examples/**/*.rb,examples/**/*.jpeg}") + %w{ LICENSE README.md Rakefile CHANGELOG.md .yardopts .yardopts_guide }
s.test_files = Dir.glob("{test/**/*}")
- s.add_runtime_dependency 'nokogiri', '>= 1.4.1'
+ s.add_runtime_dependency 'nokogiri', '>= 1.6.6'
s.add_runtime_dependency 'rubyzip', '~> 1.1.7'
- s.add_runtime_dependency "htmlentities", "~> 4.3.1"
+ s.add_runtime_dependency "htmlentities", "~> 4.3.4"
s.add_runtime_dependency "mimemagic", "~> 0.3"
s.add_development_dependency 'yard'
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/cell.rb b/lib/axlsx/workbook/worksheet/cell.rb
index 3136d0e0..cd832f7b 100644
--- a/lib/axlsx/workbook/worksheet/cell.rb
+++ b/lib/axlsx/workbook/worksheet/cell.rb
@@ -37,14 +37,14 @@ module Axlsx
# to get less GC cycles
type = options.delete(:type) || cell_type_from_value(value)
self.type = type unless type == :string
-
+
val = options.delete(:style)
self.style = val unless val.nil? || val == 0
val = options.delete(:formula_value)
self.formula_value = val unless val.nil?
-
- parse_options(options)
+
+ parse_options(options)
self.value = value
value.cell = self if contains_rich_text?
@@ -64,7 +64,7 @@ module Axlsx
:family, :b, :i, :strike, :outline,
:shadow, :condense, :extend, :u,
:vertAlign, :sz, :color, :scheme].freeze
-
+
CELL_TYPES = [:date, :time, :float, :integer, :richtext,
:string, :boolean, :iso_8601].freeze
@@ -93,7 +93,7 @@ module Axlsx
def type
defined?(@type) ? @type : :string
end
-
+
# @see type
def type=(v)
RestrictionValidator.validate :cell_type, CELL_TYPES, v
@@ -104,7 +104,7 @@ module Axlsx
# The value of this cell.
# @return [String, Integer, Float, Time, Boolean] casted value based on cell's type attribute.
attr_reader :value
-
+
# @see value
def value=(v)
#TODO: consider doing value based type determination first?
@@ -115,12 +115,12 @@ module Axlsx
# @return [Boolean]
def is_text_run?
defined?(@is_text_run) && @is_text_run && !contains_rich_text?
- end
-
+ end
+
def contains_rich_text?
type == :richtext
end
-
+
# Indicates if the cell is good for shared string table
def plain_string?
type == :string && # String typed
@@ -347,7 +347,7 @@ module Axlsx
# returns the name of the cell
attr_reader :name
-
+
def autowidth
return if is_formula? || value.nil?
if contains_rich_text?
@@ -363,7 +363,7 @@ module Axlsx
string_width(value, font_size)
end
end
-
+
# Returns the sanatized value
# TODO find a better way to do this as it accounts for 30% of
# processing time in benchmarking...
@@ -376,17 +376,17 @@ module Axlsx
end
private
-
+
def styles
row.worksheet.styles
end
-
+
# Returns the width of a string according to the current style
# This is still not perfect...
# - scaling is not linear as font sizes increase
def string_width(string, font_size)
font_scale = font_size / 10.0
- (string.to_s.count(Worksheet::THIN_CHARS) + 3.0) * (font_size/10.0)
+ (string.to_s.count(Worksheet::THIN_CHARS) + 3.0) * font_scale
end
# we scale the font size if bold style is applied to either the style font or
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..fd6dad2b 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
+ end
# @see tab_color
def tab_color=(v)
diff --git a/test/workbook/tc_shared_strings_table.rb b/test/workbook/tc_shared_strings_table.rb
index 1656dfbd..25a0a0b2 100644
--- a/test/workbook/tc_shared_strings_table.rb
+++ b/test/workbook/tc_shared_strings_table.rb
@@ -49,7 +49,7 @@ class TestSharedStringsTable < Test::Unit::TestCase
assert @p.workbook.shared_strings.unique_cells.has_key?(nasties)
# test that none of the control characters are in the XML output for shared strings
- assert_no_match /#{Axlsx::CONTROL_CHARS}/, @p.workbook.shared_strings.to_xml_string
+ assert_no_match(/#{Axlsx::CONTROL_CHARS}/, @p.workbook.shared_strings.to_xml_string)
# assert that the shared string was normalized to remove the control characters
assert_not_nil @p.workbook.shared_strings.to_xml_string.index("helloworld")
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
diff --git a/test/workbook/worksheet/tc_worksheet.rb b/test/workbook/worksheet/tc_worksheet.rb
index eb668d7f..f8bd69ae 100644
--- a/test/workbook/worksheet/tc_worksheet.rb
+++ b/test/workbook/worksheet/tc_worksheet.rb
@@ -573,5 +573,15 @@ class TestWorksheet < Test::Unit::TestCase
assert_raise(ArgumentError) { @wb.add_worksheet(:name => 'Sheet1') }
assert_equal(1, @wb.worksheets.size)
end
+
+ def test_worksheet_only_includes_outline_pr_when_set
+ doc = Nokogiri::XML(@ws.to_xml_string)
+ assert_equal(doc.xpath('//xmlns:worksheet/xmlns:sheetPr/xmlns:outlinePr').size, 0)
+ @ws.sheet_pr.outline_pr.summary_below = false
+ @ws.sheet_pr.outline_pr.summary_right = true
+ doc = Nokogiri::XML(@ws.to_xml_string)
+ assert_equal(doc.xpath('//xmlns:worksheet/xmlns:sheetPr/xmlns:outlinePr').size, 1)
+ assert_equal(doc.xpath('//xmlns:worksheet/xmlns:sheetPr/xmlns:outlinePr[@summaryBelow=0][@summaryRight=1]').size, 1)
+ end
end