summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRandy Morgan (@morgan_randy) <[email protected]>2018-02-15 00:00:30 +0900
committerGitHub <[email protected]>2018-02-15 00:00:30 +0900
commitab9b221ab3ba93e31740fccb1588457bf0536335 (patch)
tree673e1bde4fb8055271dbd1592739a9b30a4f4e5f
parentfd6f8b6f3ad4f7776b66254cd45a1b000f262139 (diff)
parent63e968966e7ff71cf23783fcd9ef02125d43d512 (diff)
downloadcaxlsx-ab9b221ab3ba93e31740fccb1588457bf0536335.tar.gz
caxlsx-ab9b221ab3ba93e31740fccb1588457bf0536335.zip
Merge pull request #575 from randym/release-3.0.0
Release 3.0.0
-rw-r--r--.travis.yml3
-rw-r--r--CHANGELOG.md5
-rw-r--r--Gemfile2
-rw-r--r--README.md8
-rw-r--r--Rakefile1
-rw-r--r--axlsx.gemspec16
-rw-r--r--lib/axlsx.rb1
-rw-r--r--lib/axlsx/drawing/chart.rb4
-rw-r--r--lib/axlsx/drawing/one_cell_anchor.rb3
-rw-r--r--lib/axlsx/drawing/pic.rb2
-rw-r--r--lib/axlsx/drawing/scatter_series.rb6
-rw-r--r--lib/axlsx/drawing/two_cell_anchor.rb7
-rw-r--r--lib/axlsx/package.rb17
-rw-r--r--lib/axlsx/rels/relationships.rb7
-rw-r--r--lib/axlsx/util/constants.rb11
-rw-r--r--lib/axlsx/util/string.rb7
-rw-r--r--lib/axlsx/util/validators.rb9
-rw-r--r--lib/axlsx/version.rb2
-rw-r--r--lib/axlsx/workbook/workbook.rb4
-rw-r--r--lib/axlsx/workbook/workbook_view.rb8
-rw-r--r--lib/axlsx/workbook/worksheet/cell.rb5
-rw-r--r--lib/axlsx/workbook/worksheet/cell_serializer.rb2
-rw-r--r--lib/axlsx/workbook/worksheet/cfvos.rb3
-rw-r--r--lib/axlsx/workbook/worksheet/cols.rb7
-rw-r--r--lib/axlsx/workbook/worksheet/outline_pr.rb2
-rw-r--r--lib/axlsx/workbook/worksheet/pivot_table.rb24
-rw-r--r--lib/axlsx/workbook/worksheet/protected_ranges.rb5
-rw-r--r--lib/axlsx/workbook/worksheet/rich_text.rb26
-rw-r--r--lib/axlsx/workbook/worksheet/rich_text_run.rb60
-rw-r--r--lib/axlsx/workbook/worksheet/tables.rb3
-rw-r--r--lib/axlsx/workbook/worksheet/worksheet.rb48
-rw-r--r--lib/axlsx/workbook/worksheet/worksheet_drawing.rb20
-rw-r--r--test/drawing/tc_chart.rb33
-rw-r--r--test/drawing/tc_drawing.rb4
-rw-r--r--test/drawing/tc_pic.rb7
-rw-r--r--test/drawing/tc_scatter_series.rb21
-rw-r--r--test/drawing/tc_title.rb5
-rw-r--r--test/tc_package.rb7
-rw-r--r--test/workbook/tc_shared_strings_table.rb5
-rw-r--r--test/workbook/tc_workbook.rb19
-rw-r--r--test/workbook/worksheet/tc_cell.rb14
-rw-r--r--test/workbook/worksheet/tc_pivot_table.rb7
-rw-r--r--test/workbook/worksheet/tc_rich_text_run.rb22
-rw-r--r--test/workbook/worksheet/tc_table.rb5
-rw-r--r--test/workbook/worksheet/tc_worksheet.rb74
45 files changed, 297 insertions, 254 deletions
diff --git a/.travis.yml b/.travis.yml
index 657f9173..7f6dc1e4 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -4,7 +4,7 @@ dist: trusty
group: beta
cache: bundler
bundler_args: --without profile
-
+
notifications:
irc: "irc.freenode.org#axlsx"
email:
@@ -17,7 +17,6 @@ matrix:
- rvm: 2.1
- rvm: 2.2.8
- rvm: 2.3.5
- - rvm: 2.0.0
- rvm: 2.4.2
- rvm: rbx-3
- rvm: jruby-19mode
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0639f3ef..901ab193 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,10 @@
CHANGELOG
---------
+- **April.1.17**:3.0.0-pre
+ - Support for ruby versions limited to officially supported version
+ - Updates to dependency gems, especially nokogiri and ruby-zip
+ - Patch options parsing for two cell anchor
+ - Remove support for depreciated worksheet members
- **November.25.12**:1.3.4
- Support for headers and footers for worksheets
- bug fix: Properly escape hyperlink urls
diff --git a/Gemfile b/Gemfile
index 89ed374d..67d33562 100644
--- a/Gemfile
+++ b/Gemfile
@@ -8,7 +8,7 @@ group :test do
else
gem 'rake'
end
- gem 'simplecov'
+ gem 'simplecov', '>= 0.14.1'
gem 'test-unit'
end
diff --git a/README.md b/README.md
index 74c4f822..68a78a64 100644
--- a/README.md
+++ b/README.md
@@ -15,17 +15,17 @@ appreciation for the gem, please don't hesitate to make a donation.
**Author**: Randy Morgan
-**Copyright**: 2011 - 2013
+**Copyright**: 2011 - 2017
**License**: MIT License
-**Latest Version**: 2.0.1
+**Latest Version**: 3.0.0
-**Ruby Version**: 1.9.2, 1.9.3, 2.0.0
+**Ruby Version**: 2.2.7, 2.3.4, 2.4.1
**JRuby Version**: 1.9 modes
-**Rubinius Version**: rubinius 2.0.0dev * lower versions may run, this gem always tests against head.
+**Rubinius Version**: rubinius 3 * lower versions may run, this gem always tests against head.
**Release Date**: September 12th 2013
diff --git a/Rakefile b/Rakefile
index 9f1dd36e..46b1503e 100644
--- a/Rakefile
+++ b/Rakefile
@@ -9,7 +9,6 @@ task :benchmark do
end
task :gendoc do
- #puts 'yard doc generation disabled until JRuby build native extensions for redcarpet or yard removes the dependency.'
system "yardoc"
system "yard stats --list-undoc"
end
diff --git a/axlsx.gemspec b/axlsx.gemspec
index 228d5a98..d1a25429 100644
--- a/axlsx.gemspec
+++ b/axlsx.gemspec
@@ -3,7 +3,7 @@ require File.expand_path('../lib/axlsx/version', __FILE__)
Gem::Specification.new do |s|
s.name = 'axlsx'
s.version = Axlsx::VERSION
- s.author = ["Randy Morgan", "Jurriaan Pruis"]
+ s.authors = ["Randy Morgan", "Jurriaan Pruis"]
s.email = '[email protected]'
s.homepage = 'https://github.com/randym/axlsx'
s.platform = Gem::Platform::RUBY
@@ -17,14 +17,14 @@ 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.6.6'
- s.add_runtime_dependency 'rubyzip', '>= 1.2.1'
- s.add_runtime_dependency "htmlentities", "~> 4.3.4"
- s.add_runtime_dependency "mimemagic", "~> 0.3"
+ s.add_runtime_dependency 'nokogiri', '~> 1.8', '>= 1.8.2'
+ s.add_runtime_dependency 'rubyzip','~> 1.2', '>= 1.2.1'
+ s.add_runtime_dependency "htmlentities", "~> 4.3", '>= 4.3.4'
+ s.add_runtime_dependency "mimemagic", '~> 0.3'
- s.add_development_dependency 'yard'
- s.add_development_dependency 'kramdown'
- s.add_development_dependency 'timecop', "~> 0.6.1"
+ s.add_development_dependency 'yard', "~> 0.9.8"
+ s.add_development_dependency 'kramdown', '~> 1.16', '>= 1.16.2'
+ s.add_development_dependency 'timecop', "~> 0.8.1"
s.required_ruby_version = '>= 1.9.2'
s.require_path = 'lib'
end
diff --git a/lib/axlsx.rb b/lib/axlsx.rb
index 586562f6..23fc6c8b 100644
--- a/lib/axlsx.rb
+++ b/lib/axlsx.rb
@@ -11,7 +11,6 @@ require 'axlsx/util/serialized_attributes'
require 'axlsx/util/options_parser'
# to be included with parsable intitites.
#require 'axlsx/util/parser.rb'
-require 'axlsx/util/string'
require 'axlsx/util/mime_type_utils'
require 'axlsx/stylesheet/styles.rb'
diff --git a/lib/axlsx/drawing/chart.rb b/lib/axlsx/drawing/chart.rb
index de87b91a..d3a7e9ff 100644
--- a/lib/axlsx/drawing/chart.rb
+++ b/lib/axlsx/drawing/chart.rb
@@ -56,7 +56,7 @@ module Axlsx
# Indicates that colors should be varied by datum
# @return [Boolean]
attr_reader :vary_colors
-
+
# Configures the vary_colors options for this chart
# @param [Boolean] v The value to set
def vary_colors=(v) Axlsx::validate_boolean(v); @vary_colors = v; end
@@ -129,6 +129,8 @@ module Axlsx
end
# The size of the Title object of the chart.
+ # @param [String] v The size for the title object
+ # @see Title
def title_size=(v)
@title.text_size = v unless v.to_s.empty?
end
diff --git a/lib/axlsx/drawing/one_cell_anchor.rb b/lib/axlsx/drawing/one_cell_anchor.rb
index 1ae7c1b9..ffa10a7d 100644
--- a/lib/axlsx/drawing/one_cell_anchor.rb
+++ b/lib/axlsx/drawing/one_cell_anchor.rb
@@ -7,7 +7,7 @@ module Axlsx
class OneCellAnchor
include Axlsx::OptionsParser
-
+
# Creates a new OneCellAnchor object and an Pic associated with it.
# @param [Drawing] drawing
# @option options [Array] start_at the col, row to start at
@@ -23,6 +23,7 @@ module Axlsx
drawing.anchors << self
@from = Marker.new
parse_options options
+ start_at(*options[:start_at]) if options[:start_at]
@object = Pic.new(self, options)
end
diff --git a/lib/axlsx/drawing/pic.rb b/lib/axlsx/drawing/pic.rb
index 5a418df0..e8d0ebd7 100644
--- a/lib/axlsx/drawing/pic.rb
+++ b/lib/axlsx/drawing/pic.rb
@@ -115,7 +115,6 @@ module Axlsx
end
# providing access to the anchor's width attribute
- # @param [Integer] v
# @see OneCellAnchor.width
def width
return unless @anchor.is_a?(OneCellAnchor)
@@ -129,7 +128,6 @@ module Axlsx
end
# providing access to update the anchor's height attribute
- # @param [Integer] v
# @see OneCellAnchor.width
# @note this is a noop if you are using a TwoCellAnchor
def height
diff --git a/lib/axlsx/drawing/scatter_series.rb b/lib/axlsx/drawing/scatter_series.rb
index 6b71227c..b9ca2c1d 100644
--- a/lib/axlsx/drawing/scatter_series.rb
+++ b/lib/axlsx/drawing/scatter_series.rb
@@ -27,7 +27,7 @@ module Axlsx
# Line smoothing between data points
# @return [Boolean]
attr_reader :smooth
-
+
# Creates a new ScatterSeries
def initialize(chart, options={})
@xData, @yData = nil
@@ -55,7 +55,7 @@ module Axlsx
Axlsx::validate_boolean(v)
@smooth = v
end
-
+
# @see ln_width
def ln_width=(v)
@ln_width = v
@@ -85,7 +85,7 @@ module Axlsx
end
if ln_width
str << '<c:spPr>'
- str << '<a:ln w="' << ln_width << '"/>'
+ str << '<a:ln w="' << ln_width.to_s << '"/>'
str << '</c:spPr>'
end
@xData.to_xml_string(str) unless @xData.nil?
diff --git a/lib/axlsx/drawing/two_cell_anchor.rb b/lib/axlsx/drawing/two_cell_anchor.rb
index b18268f7..d422c0ce 100644
--- a/lib/axlsx/drawing/two_cell_anchor.rb
+++ b/lib/axlsx/drawing/two_cell_anchor.rb
@@ -37,11 +37,16 @@ module Axlsx
drawing.anchors << self
@from, @to = Marker.new, Marker.new(:col => 5, :row=>10)
parse_options options
+
+ # bit of a hack to work around the fact that the coords for start at and end at
+ # are passed in as an array when specified in intialization options - however
+ start_at(*options[:start_at]) if options[:start_at]
+ end_at(*options[:end_at]) if options[:end_at]
end
# sets the col, row attributes for the from marker.
# @note The recommended way to set the start position for graphical
- # objects is directly thru the object.
+ # objects is directly thru the object.
# @see Chart#start_at
def start_at(x, y=nil)
from.coord x, y
diff --git a/lib/axlsx/package.rb b/lib/axlsx/package.rb
index 5b5ea14a..da661b34 100644
--- a/lib/axlsx/package.rb
+++ b/lib/axlsx/package.rb
@@ -147,11 +147,7 @@ module Axlsx
errors = []
parts.each do |part|
unless part[:schema].nil?
- if part[:doc].is_a? String
- errors.concat validate_single_doc(part[:schema], part[:doc])
- else
- errors.concat validate_single_doc(part[:schema], part[:doc].to_xml_string)
- end
+ errors.concat validate_single_doc(part[:schema], part[:doc].to_xml_string)
end
end
errors
@@ -165,20 +161,13 @@ module Axlsx
def write_parts(zip)
p = parts
p.each do |part|
- #next unless part[:entry] == CORE_PN
unless part[:doc].nil?
zip.put_next_entry(zip_entry_for_part(part))
- if part[:doc].is_a? String
- entry = ['1.9.2', '1.9.3'].include?(RUBY_VERSION) ? part[:doc].force_encoding('BINARY') : part[:doc]
- zip.puts(entry)
- else
- part[:doc].to_xml_string(zip)
- end
+ part[:doc].to_xml_string(zip)
end
unless part[:path].nil?
zip.put_next_entry(zip_entry_for_part(part))
- # binread for 1.9.3
- zip.write IO.respond_to?(:binread) ? IO.binread(part[:path]) : IO.read(part[:path])
+ zip.write IO.read(part[:path])
end
end
zip
diff --git a/lib/axlsx/rels/relationships.rb b/lib/axlsx/rels/relationships.rb
index b855abcd..5d07f612 100644
--- a/lib/axlsx/rels/relationships.rb
+++ b/lib/axlsx/rels/relationships.rb
@@ -10,14 +10,17 @@ require 'axlsx/rels/relationship.rb'
def initialize
super Relationship
end
-
+
# The relationship instance for the given source object, or nil if none exists.
# @see Relationship#source_obj
# @return [Relationship]
def for(source_obj)
find{ |rel| rel.source_obj == source_obj }
end
-
+
+ # serialize relationships
+ # @param [String] str
+ # @return [String]
def to_xml_string(str = '')
str << '<?xml version="1.0" encoding="UTF-8"?>'
str << ('<Relationships xmlns="' << RELS_R << '">')
diff --git a/lib/axlsx/util/constants.rb b/lib/axlsx/util/constants.rb
index 64bae270..aa8eb626 100644
--- a/lib/axlsx/util/constants.rb
+++ b/lib/axlsx/util/constants.rb
@@ -385,13 +385,16 @@ module Axlsx
# @see http://www.codetable.net/asciikeycodes
pattern = "\x0-\x08\x0B\x0C\x0E-\x1F"
pattern = pattern.respond_to?(:encode) ? pattern.encode('UTF-8') : pattern
-
+
# The regular expression used to remove control characters from worksheets
CONTROL_CHARS = pattern.freeze
-
+
+ # ISO 8601 date recognition
ISO_8601_REGEX = /\A(-?(?:[1-9][0-9]*)?[0-9]{4})-(1[0-2]|0[1-9])-(3[0-1]|0[1-9]|[1-2][0-9])T(2[0-3]|[0-1][0-9]):([0-5][0-9]):([0-5][0-9])(\.[0-9]+)?(Z|[+-](?:2[0-3]|[0-1][0-9]):[0-5][0-9])?\Z/.freeze
-
+
+ # FLOAT recognition
FLOAT_REGEX = /\A[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?\Z/.freeze
-
+
+ # Numeric recognition
NUMERIC_REGEX = /\A[+-]?\d+?\Z/.freeze
end
diff --git a/lib/axlsx/util/string.rb b/lib/axlsx/util/string.rb
deleted file mode 100644
index 8def6e5b..00000000
--- a/lib/axlsx/util/string.rb
+++ /dev/null
@@ -1,7 +0,0 @@
-unless String.method_defined? :prepend
- class String
- def prepend(other_str)
- insert(0, other_str)
- end
- end
-end \ No newline at end of file
diff --git a/lib/axlsx/util/validators.rb b/lib/axlsx/util/validators.rb
index 2b4afd8d..71652ef2 100644
--- a/lib/axlsx/util/validators.rb
+++ b/lib/axlsx/util/validators.rb
@@ -56,13 +56,13 @@ module Axlsx
raise ArgumentError, (ERR_TYPE % [v.inspect, name, types.inspect]) unless other.call(v)
end
v_class = v.is_a?(Class) ? v : v.class
- Array(types).each do |t|
+ Array(types).each do |t|
return if v_class <= t
end
raise ArgumentError, (ERR_TYPE % [v.inspect, name, types.inspect])
end
end
-
+
# Requires that the value can be converted to an integer
# @para, [Any] v the value to validate
@@ -78,7 +78,8 @@ module Axlsx
def self.validate_angle(v)
raise ArgumentError, (ERR_ANGLE % v.inspect) unless (v.to_i >= -5400000 && v.to_i <= 5400000)
end
-
+
+ # Validates an unsigned intger
UINT_VALIDATOR = lambda { |arg| arg.respond_to?(:>=) && arg >= 0 }
# Requires that the value is a Integer and is greater or equal to 0
@@ -148,7 +149,7 @@ module Axlsx
RestrictionValidator.validate "cell run style u", [:none, :single, :double, :singleAccounting, :doubleAccounting], v
end
- # validates cell style family which must be between 1 and 5
+ # validates cell style family which must be between 1 and 5
def self.validate_family(v)
RestrictionValidator.validate "cell run style family", 1..5, v
end
diff --git a/lib/axlsx/version.rb b/lib/axlsx/version.rb
index df4bd9ed..10f78875 100644
--- a/lib/axlsx/version.rb
+++ b/lib/axlsx/version.rb
@@ -1,5 +1,5 @@
module Axlsx
# The current version
- VERSION = "2.1.0.pre"
+ VERSION = "3.0.0.pre"
end
diff --git a/lib/axlsx/workbook/workbook.rb b/lib/axlsx/workbook/workbook.rb
index 4ba44adb..7572e51f 100644
--- a/lib/axlsx/workbook/workbook.rb
+++ b/lib/axlsx/workbook/workbook.rb
@@ -280,6 +280,10 @@ require 'axlsx/workbook/worksheet/selection.rb'
worksheet
end
+ # Adds a new WorkbookView
+ # @return WorkbookViews
+ # @option options [Hash] options passed into the added WorkbookView
+ # @see WorkbookView#initialize
def add_view(options={})
views << WorkbookView.new(options)
end
diff --git a/lib/axlsx/workbook/workbook_view.rb b/lib/axlsx/workbook/workbook_view.rb
index 11eae571..e0d38cae 100644
--- a/lib/axlsx/workbook/workbook_view.rb
+++ b/lib/axlsx/workbook/workbook_view.rb
@@ -33,7 +33,7 @@ module Axlsx
# Creates a new BookView object
- # @params [Hash] options A hash of key/value pairs that will be mapped to this instances attributes.
+ # @param [Hash] options A hash of key/value pairs that will be mapped to this instances attributes.
# @option [Symbol] visibility Specifies visible state of the workbook window. The default value for this attribute is :visible.
# @option [Boolean] minimized Specifies a boolean value that indicates whether the workbook window is minimized.
# @option [Boolean] show_horizontal_scroll Specifies a boolean value that indicates whether to display the horizontal scroll bar in the user interface.
@@ -41,7 +41,7 @@ module Axlsx
# @option [Boolean] show_sheet_tabs Specifies a boolean value that indicates whether to display the sheet tabs in the user interface.
# @option [Integer] tab_ratio Specifies ratio between the workbook tabs bar and the horizontal scroll bar.
# @option [Integer] first_sheet Specifies the index to the first sheet in this book view.
- # @option [Integer] active_tab Specifies an unsignedInt that contains the index to the active sheet in this book view.
+ # @option [Integer] active_tab Specifies an unsignedInt that contains the index to the active sheet in this book view.
# @option [Integer] x_window Specifies the X coordinate for the upper left corner of the workbook window. The unit of measurement for this value is twips.
# @option [Integer] y_window Specifies the Y coordinate for the upper left corner of the workbook window. The unit of measurement for this value is twips.
# @option [Integer] window_width Specifies the width of the workbook window. The unit of measurement for this value is twips.
@@ -68,7 +68,9 @@ module Axlsx
:show_sheet_tabs, :auto_filter_date_grouping
-
+ # Serialize the WorkbookView
+ # @param [String] str
+ # @return [String]
def to_xml_string(str = '')
str << '<workbookView '
serialized_attributes str
diff --git a/lib/axlsx/workbook/worksheet/cell.rb b/lib/axlsx/workbook/worksheet/cell.rb
index 777b7812..fb10ad36 100644
--- a/lib/axlsx/workbook/worksheet/cell.rb
+++ b/lib/axlsx/workbook/worksheet/cell.rb
@@ -65,6 +65,7 @@ module Axlsx
:shadow, :condense, :extend, :u,
:vertAlign, :sz, :color, :scheme].freeze
+ # An array of valid cell types
CELL_TYPES = [:date, :time, :float, :integer, :richtext,
:string, :boolean, :iso_8601, :text].freeze
@@ -79,7 +80,7 @@ module Axlsx
# @return [Row]
attr_reader :row
- # The cell's data type. Currently only six types are supported, :date, :time, :float, :integer, :string and :boolean.
+ # The cell's data type.
# Changing the type for a cell will recast the value into that type. If no type option is specified in the constructor, the type is
# automatically determed.
# @see Cell#cell_type_from_value
@@ -348,6 +349,8 @@ module Axlsx
# returns the name of the cell
attr_reader :name
+ # Attempts to determine the correct width for this cell's content
+ # @return [Float]
def autowidth
return if is_formula? || value.nil?
if contains_rich_text?
diff --git a/lib/axlsx/workbook/worksheet/cell_serializer.rb b/lib/axlsx/workbook/worksheet/cell_serializer.rb
index 76a3c386..eb834b08 100644
--- a/lib/axlsx/workbook/worksheet/cell_serializer.rb
+++ b/lib/axlsx/workbook/worksheet/cell_serializer.rb
@@ -159,8 +159,6 @@ module Axlsx
str << ('t="' << serialization_type.to_s << '"') if serialization_type
str << ('><v>' << serialization_value.to_s << '</v>')
end
-
-
end
end
end
diff --git a/lib/axlsx/workbook/worksheet/cfvos.rb b/lib/axlsx/workbook/worksheet/cfvos.rb
index 0b5a21b3..eb44f9d8 100644
--- a/lib/axlsx/workbook/worksheet/cfvos.rb
+++ b/lib/axlsx/workbook/worksheet/cfvos.rb
@@ -8,6 +8,9 @@ module Axlsx
super(Cfvo)
end
+ # Serialize the Cfvo object
+ # @param [String] str
+ # @return [String]
def to_xml_string(str='')
each { |cfvo| cfvo.to_xml_string(str) }
end
diff --git a/lib/axlsx/workbook/worksheet/cols.rb b/lib/axlsx/workbook/worksheet/cols.rb
index d4595f29..c0704343 100644
--- a/lib/axlsx/workbook/worksheet/cols.rb
+++ b/lib/axlsx/workbook/worksheet/cols.rb
@@ -1,6 +1,6 @@
module Axlsx
- # The cols class manages the col object used to manage column widths.
+ # The cols class manages the col object used to manage column widths.
# This is where the magic happens with autowidth
class Cols < SimpleTypedList
@@ -10,11 +10,14 @@ module Axlsx
@worksheet = worksheet
end
+ # Serialize the Cols object
+ # @param [String] str
+ # @return [String]
def to_xml_string(str = '')
return if empty?
str << '<cols>'
each { |item| item.to_xml_string(str) }
- str << '</cols>'
+ str << '</cols>'
end
end
end
diff --git a/lib/axlsx/workbook/worksheet/outline_pr.rb b/lib/axlsx/workbook/worksheet/outline_pr.rb
index ae9ccf38..f25ef4fa 100644
--- a/lib/axlsx/workbook/worksheet/outline_pr.rb
+++ b/lib/axlsx/workbook/worksheet/outline_pr.rb
@@ -18,7 +18,7 @@ module Axlsx
:apply_styles
# Creates a new OutlinePr object
- # @param [Worksheet] worksheet The worksheet that owns this OutlinePr object
+ # @param [Hash] options used to create the outline_pr
def initialize(options = {})
parse_options options
end
diff --git a/lib/axlsx/workbook/worksheet/pivot_table.rb b/lib/axlsx/workbook/worksheet/pivot_table.rb
index fffced0b..55174968 100644
--- a/lib/axlsx/workbook/worksheet/pivot_table.rb
+++ b/lib/axlsx/workbook/worksheet/pivot_table.rb
@@ -170,12 +170,12 @@ module Axlsx
def to_xml_string(str = '')
str << '<?xml version="1.0" encoding="UTF-8"?>'
str << ('<pivotTableDefinition xmlns="' << XML_NS << '" name="' << name << '" cacheId="' << cache_definition.cache_id.to_s << '" dataOnRows="1" applyNumberFormats="0" applyBorderFormats="0" applyFontFormats="0" applyPatternFormats="0" applyAlignmentFormats="0" applyWidthHeightFormats="1" dataCaption="Data" showMultipleLabel="0" showMemberPropertyTips="0" useAutoFormatting="1" indent="0" compact="0" compactData="0" gridDropZones="1" multipleFieldFilters="0">')
- str << ( '<location firstDataCol="1" firstDataRow="1" firstHeaderRow="1" ref="' << ref << '"/>')
- str << ( '<pivotFields count="' << header_cells_count.to_s << '">')
+ str << ('<location firstDataCol="1" firstDataRow="1" firstHeaderRow="1" ref="' << ref << '"/>')
+ str << ('<pivotFields count="' << header_cells_count.to_s << '">')
header_cell_values.each do |cell_value|
- str << pivot_field_for(cell_value,!no_subtotals_on_headers.include?(cell_value))
+ str << pivot_field_for(cell_value, !no_subtotals_on_headers.include?(cell_value))
end
- str << '</pivotFields>'
+ str << '</pivotFields>'
if rows.empty?
str << '<rowFields count="1"><field x="-2"/></rowFields>'
str << '<rowItems count="2"><i><x/></i> <i i="1"><x v="1"/></i></rowItems>'
@@ -263,25 +263,25 @@ module Axlsx
def pivot_field_for(cell_ref, subtotal=true)
if rows.include? cell_ref
if subtotal
- '<pivotField axis="axisRow" compact="0" outline="0" subtotalTop="0" showAll="0" includeNewItemsInFilter="1">' + '<items count="1"><item t="default"/></items>' + '</pivotField>'
+ '<pivotField axis="axisRow" compact="0" outline="0" subtotalTop="0" showAll="0" includeNewItemsInFilter="1"><items count="1"><item t="default"/></items></pivotField>'
else
- '<pivotField axis="axisRow" compact="0" outline="0" subtotalTop="0" showAll="0" includeNewItemsInFilter="1" defaultSubtotal="0">' + '</pivotField>'
+ '<pivotField axis="axisRow" compact="0" outline="0" subtotalTop="0" showAll="0" includeNewItemsInFilter="1" defaultSubtotal="0"></pivotField>'
end
elsif columns.include? cell_ref
- '<pivotField axis="axisCol" compact="0" outline="0" subtotalTop="0" showAll="0" includeNewItemsInFilter="1">' + '<items count="1"><item t="default"/></items>' + '</pivotField>'
+ '<pivotField axis="axisCol" compact="0" outline="0" subtotalTop="0" showAll="0" includeNewItemsInFilter="1"><items count="1"><item t="default"/></items></pivotField>'
elsif pages.include? cell_ref
- '<pivotField axis="axisPage" compact="0" outline="0" subtotalTop="0" showAll="0" includeNewItemsInFilter="1">' + '<items count="1"><item t="default"/></items>' + '</pivotField>'
+ '<pivotField axis="axisPage" compact="0" outline="0" subtotalTop="0" showAll="0" includeNewItemsInFilter="1"><items count="1"><item t="default"/></items></pivotField>'
elsif data_refs.include? cell_ref
- '<pivotField dataField="1" compact="0" outline="0" subtotalTop="0" showAll="0" includeNewItemsInFilter="1">' + '</pivotField>'
+ '<pivotField dataField="1" compact="0" outline="0" subtotalTop="0" showAll="0" includeNewItemsInFilter="1"></pivotField>'
else
- '<pivotField compact="0" outline="0" subtotalTop="0" showAll="0" includeNewItemsInFilter="1">' + '</pivotField>'
+ '<pivotField compact="0" outline="0" subtotalTop="0" showAll="0" includeNewItemsInFilter="1"></pivotField>'
end
end
-
+
def data_refs
data.map { |hash| hash[:ref] }
end
-
+
def header_range
range.gsub(/^(\w+?)(\d+)\:(\w+?)\d+$/, '\1\2:\3\2')
end
diff --git a/lib/axlsx/workbook/worksheet/protected_ranges.rb b/lib/axlsx/workbook/worksheet/protected_ranges.rb
index 46a2546b..d274cf80 100644
--- a/lib/axlsx/workbook/worksheet/protected_ranges.rb
+++ b/lib/axlsx/workbook/worksheet/protected_ranges.rb
@@ -24,11 +24,14 @@ module Axlsx
last
end
+ # Serializes the protected ranges
+ # @param [String] str
+ # @return [String]
def to_xml_string(str = '')
return if empty?
str << '<protectedRanges>'
each { |range| range.to_xml_string(str) }
- str << '</protectedRanges>'
+ str << '</protectedRanges>'
end
end
end
diff --git a/lib/axlsx/workbook/worksheet/rich_text.rb b/lib/axlsx/workbook/worksheet/rich_text.rb
index 9124dfbe..81af32b2 100644
--- a/lib/axlsx/workbook/worksheet/rich_text.rb
+++ b/lib/axlsx/workbook/worksheet/rich_text.rb
@@ -1,32 +1,52 @@
module Axlsx
+
+ # A simple, self serializing class for storing TextRuns
class RichText < SimpleTypedList
+
+ # creates a new RichText collection
+ # @param [String] text -optional The text to use in creating the first RichTextRun
+ # @param [Object] options -optional The options to use in creating the first RichTextRun
+ # @yield [RichText] self
def initialize(text = nil, options={})
super(RichTextRun)
add_run(text, options) unless text.nil?
yield self if block_given?
end
+ # The cell that owns this RichText collection
attr_reader :cell
-
+
+ # Assign the cell for this RichText collection
+ # @param [Cell] cell The cell which all RichTextRuns in the collection will belong to
def cell=(cell)
@cell = cell
each { |run| run.cell = cell }
end
-
+
+ # Calculates the longest autowidth of the RichTextRuns in this collection
+ # @return [Number]
def autowidth
widtharray = [0] # Are arrays the best way of solving this problem?
each { |run| run.autowidth(widtharray) }
widtharray.max
end
+ # Creates and adds a RichTextRun to this collectino
+ # @param [String] text The text to use in creating a new RichTextRun
+ # @param [Object] options The options to use in creating the new RichTextRun
def add_run(text, options={})
self << RichTextRun.new(text, options)
end
-
+
+ # The RichTextRuns we own
+ # @return [RichText]
def runs
self
end
+ # renders the RichTextRuns in this collection
+ # @param [String] str
+ # @return [String]
def to_xml_string(str='')
each{ |run| run.to_xml_string(str) }
str
diff --git a/lib/axlsx/workbook/worksheet/rich_text_run.rb b/lib/axlsx/workbook/worksheet/rich_text_run.rb
index e56dc3ae..40d99bb0 100644
--- a/lib/axlsx/workbook/worksheet/rich_text_run.rb
+++ b/lib/axlsx/workbook/worksheet/rich_text_run.rb
@@ -1,26 +1,29 @@
module Axlsx
+
+ # The RichTextRun class creates and self serializing text run.
class RichTextRun
-
+
include Axlsx::OptionsParser
-
+
attr_reader :value
-
+
+ # A list of allowed inline style attributes used for validation
INLINE_STYLES = [:font_name, :charset,
:family, :b, :i, :strike, :outline,
:shadow, :condense, :extend, :u,
:vertAlign, :sz, :color, :scheme].freeze
-
+
def initialize(value, options={})
self.value = value
- parse_options(options)
+ parse_options(options)
end
-
+
def value=(value)
@value = value
end
-
+
attr_accessor :cell
-
+
# The inline font_name property for the cell
# @return [String]
attr_reader :font_name
@@ -154,19 +157,9 @@ module Axlsx
set_run_style nil, :scheme, v
end
- # The Shared Strings Table index for this cell
- # @return [Integer]
- attr_reader :ssti
-
- # @return [Integer] The cellXfs item index applied to this cell.
- # @raise [ArgumentError] Invalid cellXfs id if the value provided is not within cellXfs items range.
- def style=(v)
- Axlsx::validate_unsigned_int(v)
- count = styles.cellXfs.size
- raise ArgumentError, "Invalid cellXfs id" unless v < count
- @style = v
- end
-
+ # Tries to work out the width of the longest line in the run
+ # @param [Array] widtharray this array is populated with the widths of each line in the run.
+ # @return [Array]
def autowidth(widtharray)
return if value.nil?
if styles.cellXfs[style].alignment && styles.cellXfs[style].alignment.wrap_text
@@ -184,19 +177,22 @@ module Axlsx
end
widtharray
end
-
+
# Utility method for setting inline style attributes
def set_run_style(validator, attr, value)
return unless INLINE_STYLES.include?(attr.to_sym)
Axlsx.send(validator, value) unless validator.nil?
self.instance_variable_set :"@#{attr.to_s}", value
end
-
+
+ # Serializes the RichTextRun
+ # @param [String] str
+ # @return [String]
def to_xml_string(str = '')
valid = RichTextRun::INLINE_STYLES
- data = Hash[self.instance_values.map{ |k, v| [k.to_sym, v] }]
+ data = Hash[self.instance_values.map{ |k, v| [k.to_sym, v] }]
data = data.select { |key, value| valid.include?(key) && !value.nil? }
-
+
str << '<r><rPr>'
data.keys.each do |key|
case key
@@ -211,9 +207,9 @@ module Axlsx
clean_value = Axlsx::trust_input ? @value.to_s : ::CGI.escapeHTML(Axlsx::sanitize(@value.to_s))
str << ('</rPr><t>' << clean_value << '</t></r>')
end
-
+
private
-
+
# Returns the width of a string according to the current style
# This is still not perfect...
# - scaling is not linear as font sizes increase
@@ -221,7 +217,7 @@ module Axlsx
font_scale = font_size / 10.0
string.count(Worksheet::THIN_CHARS) * font_scale
end
-
+
# we scale the font size if bold style is applied to either the style font or
# the cell itself. Yes, it is a bit of a hack, but it is much better than using
# imagemagick and loading metrics for every character.
@@ -230,15 +226,15 @@ module Axlsx
font = styles.fonts[styles.cellXfs[style].fontId] || styles.fonts[0]
(font.b || (defined?(@b) && @b)) ? (font.sz * 1.5) : font.sz
end
-
+
def style
cell.style
end
-
+
def styles
- cell.row.worksheet.styles
+ cell.row.worksheet.styles
end
-
+
# Converts the value to the correct XML representation (fixes issues with
# Numbers)
def xml_value value
diff --git a/lib/axlsx/workbook/worksheet/tables.rb b/lib/axlsx/workbook/worksheet/tables.rb
index 624c96c4..d033212c 100644
--- a/lib/axlsx/workbook/worksheet/tables.rb
+++ b/lib/axlsx/workbook/worksheet/tables.rb
@@ -20,6 +20,9 @@ module Axlsx
map{ |table| Relationship.new(table, TABLE_R, "../#{table.pn}") }
end
+ # renders the tables xml
+ # @param [String] str
+ # @return [String]
def to_xml_string(str = "")
return if empty?
str << "<tableParts count='#{size}'>"
diff --git a/lib/axlsx/workbook/worksheet/worksheet.rb b/lib/axlsx/workbook/worksheet/worksheet.rb
index f094c5cd..6fbd384e 100644
--- a/lib/axlsx/workbook/worksheet/worksheet.rb
+++ b/lib/axlsx/workbook/worksheet/worksheet.rb
@@ -8,7 +8,7 @@ module Axlsx
# definition of characters which are less than the maximum width of 0-9 in the default font for use in String#count.
# This is used for autowidth calculations
THIN_CHARS = '^.acfijklrstxzFIJL()-'.freeze
-
+
# Creates a new worksheet.
# @note the recommended way to manage worksheets is Workbook#add_worksheet
# @see Workbook#add_worksheet
@@ -305,50 +305,6 @@ module Axlsx
@sheet_pr ||= SheetPr.new self
end
- # Indicates if gridlines should be shown in the sheet.
- # This is true by default.
- # @return [Boolean]
- # @deprecated Use SheetView#show_grid_lines= instead.
- def show_gridlines=(v)
- warn('axlsx::DEPRECIATED: Worksheet#show_gridlines= has been depreciated. This value can be set over SheetView#show_grid_lines=.')
- Axlsx::validate_boolean v
- sheet_view.show_grid_lines = v
- end
-
- # @see selected
- # @return [Boolean]
- # @deprecated Use SheetView#tab_selected= instead.
- def selected=(v)
- warn('axlsx::DEPRECIATED: Worksheet#selected= has been depreciated. This value can be set over SheetView#tab_selected=.')
- Axlsx::validate_boolean v
- sheet_view.tab_selected = v
- end
-
- # Indicates if the worksheet should show gridlines or not
- # @return Boolean
- # @deprecated Use SheetView#show_grid_lines instead.
- def show_gridlines
- warn('axlsx::DEPRECIATED: Worksheet#show_gridlines has been depreciated. This value can get over SheetView#show_grid_lines.')
- sheet_view.show_grid_lines
- end
-
- # Indicates if the worksheet is selected in the workbook
- # It is possible to have more than one worksheet selected, however it might cause issues
- # in some older versions of excel when using copy and paste.
- # @return Boolean
- # @deprecated Use SheetView#tab_selected instead.
- def selected
- warn('axlsx::DEPRECIATED: Worksheet#selected has been depreciated. This value can get over SheetView#tab_selected.')
- sheet_view.tab_selected
- end
-
- # (see #fit_to_page)
- # @return [Boolean]
- def fit_to_page=(v)
- warn('axlsx::DEPRECIATED: Worksheet#fit_to_page has been depreciated. This value will automatically be set for you when you use PageSetup#fit_to.')
- fit_to_page?
- end
-
# The name of the worksheet
# The name of a worksheet must be unique in the workbook, and must not exceed 31 characters
# @param [String] name
@@ -630,7 +586,7 @@ module Axlsx
# Returns the cell or cells defined using excel style A1:B3 references.
# @param [String|Integer] cell_def the string defining the cell or range of cells, or the rownumber
# @return [Cell, Array]
- def [] (cell_def)
+ def [](cell_def)
return rows[cell_def] if cell_def.is_a?(Integer)
parts = cell_def.split(':').map{ |part| name_to_cell part }
if parts.size == 1
diff --git a/lib/axlsx/workbook/worksheet/worksheet_drawing.rb b/lib/axlsx/workbook/worksheet/worksheet_drawing.rb
index 08cad1f7..ae03ac0f 100644
--- a/lib/axlsx/workbook/worksheet/worksheet_drawing.rb
+++ b/lib/axlsx/workbook/worksheet/worksheet_drawing.rb
@@ -1,5 +1,5 @@
module Axlsx
-
+
# This is a utility class for serialing the drawing node in a
# worksheet. Drawing objects have their own serialization that exports
# a drawing document. This is only for the single node in the
@@ -17,7 +17,7 @@ module Axlsx
attr_reader :worksheet
attr_reader :drawing
-
+
# adds a chart to the drawing object
# @param [Class] chart_type The type of chart to add
# @param [Hash] options Options to pass on to the drawing and chart
@@ -26,17 +26,17 @@ module Axlsx
@drawing ||= Drawing.new worksheet
drawing.add_chart(chart_type, options)
end
-
+
# adds an image to the drawing object
- # @param [Hash] options Options to pass on to the drawing and image
+ # @param [Hash] options Options to pass on to the drawing and image
# @see Worksheet#add_image
def add_image(options)
- @drawing ||= Drawing.new worksheet
+ @drawing ||= Drawing.new(worksheet)
drawing.add_image(options)
- end
-
+ end
+
# helper method to tell us if the drawing has something in it or not
- # @return [Boolean]
+ # @return [Boolean]
def has_drawing?
@drawing.is_a? Drawing
end
@@ -45,13 +45,13 @@ module Axlsx
# @return [Relationship]
def relationship
return unless has_drawing?
- Relationship.new(self, DRAWING_R, "../#{drawing.pn}")
+ Relationship.new(self, DRAWING_R, "../#{drawing.pn}")
end
# Serialize the drawing for the worksheet
# @param [String] str
def to_xml_string(str = '')
- return unless has_drawing?
+ return unless has_drawing?
str << "<drawing r:id='#{relationship.Id}'/>"
end
end
diff --git a/test/drawing/tc_chart.rb b/test/drawing/tc_chart.rb
index 8b69e73a..64a5435b 100644
--- a/test/drawing/tc_chart.rb
+++ b/test/drawing/tc_chart.rb
@@ -6,7 +6,7 @@ class TestChart < Test::Unit::TestCase
@p = Axlsx::Package.new
ws = @p.workbook.add_worksheet
@row = ws.add_row ["one", 1, Time.now]
- @chart = ws.add_chart Axlsx::Bar3DChart, :title => "fishery"
+ @chart = ws.add_chart Axlsx::Bar3DChart, :title => "fishery", :bg_color => "000000"
end
def teardown
@@ -27,17 +27,30 @@ class TestChart < Test::Unit::TestCase
assert_equal(@chart.title.cell, @row.cells.first)
end
+ def test_style
+ assert_raise(ArgumentError) { @chart.style = 49 }
+ assert_nothing_raised { @chart.style = 2 }
+ assert_equal(@chart.style, 2)
+ end
+
def test_to_from_marker_access
assert(@chart.to.is_a?(Axlsx::Marker))
assert(@chart.from.is_a?(Axlsx::Marker))
end
- def test_style
- assert_raise(ArgumentError) { @chart.style = 49 }
- assert_nothing_raised { @chart.style = 2 }
- assert_equal(@chart.style, 2)
+ def test_bg_color
+ assert_raise(ArgumentError) { @chart.bg_color = 2 }
+ assert_nothing_raised { @chart.bg_color = "FFFFFF" }
+ assert_equal(@chart.bg_color, "FFFFFF")
+
end
-
+
+ def test_title_size
+ assert_raise(ArgumentError) { @chart.title_size = 2 }
+ assert_nothing_raised { @chart.title_size = "100" }
+ assert_equal(@chart.title.text_size, "100")
+ end
+
def test_vary_colors
assert_equal(true, @chart.vary_colors)
assert_raise(ArgumentError) { @chart.vary_colors = 7 }
@@ -63,7 +76,7 @@ class TestChart < Test::Unit::TestCase
@chart.start_at [5,6]
assert_equal(@chart.graphic_frame.anchor.from.col, 5)
assert_equal(@chart.graphic_frame.anchor.from.row, 6)
-
+
end
def test_end_at
@@ -76,7 +89,7 @@ class TestChart < Test::Unit::TestCase
@chart.end_at [10,11]
assert_equal(@chart.graphic_frame.anchor.to.col, 10)
assert_equal(@chart.graphic_frame.anchor.to.row, 11)
-
+
end
def test_add_series
@@ -88,13 +101,13 @@ class TestChart < Test::Unit::TestCase
def test_pn
assert_equal(@chart.pn, "charts/chart1.xml")
end
-
+
def test_d_lbls
assert_equal(nil, @chart.instance_values[:d_lbls])
@chart.d_lbls.d_lbl_pos = :t
assert(@chart.d_lbls.is_a?(Axlsx::DLbls), 'DLbls instantiated on access')
end
-
+
def test_to_xml_string
schema = Nokogiri::XML::Schema(File.open(Axlsx::DRAWING_XSD))
doc = Nokogiri::XML(@chart.to_xml_string)
diff --git a/test/drawing/tc_drawing.rb b/test/drawing/tc_drawing.rb
index 7014f1b2..c9095fe7 100644
--- a/test/drawing/tc_drawing.rb
+++ b/test/drawing/tc_drawing.rb
@@ -59,9 +59,9 @@ class TestDrawing < Test::Unit::TestCase
end
def test_relationships
- chart = @ws.add_chart(Axlsx::Pie3DChart, :title=>"bob", :start_at=>[0,0], :end_at=>[1,1])
+ @ws.add_chart(Axlsx::Pie3DChart, :title=>"bob", :start_at=>[0,0], :end_at=>[1,1])
assert_equal(@ws.drawing.relationships.size, 1, "adding a chart adds a relationship")
- chart = @ws.add_chart(Axlsx::Pie3DChart, :title=>"nancy", :start_at=>[1,5], :end_at=>[5,10])
+ @ws.add_chart(Axlsx::Pie3DChart, :title=>"nancy", :start_at=>[1,5], :end_at=>[5,10])
assert_equal(@ws.drawing.relationships.size, 2, "adding a chart adds a relationship")
end
diff --git a/test/drawing/tc_pic.rb b/test/drawing/tc_pic.rb
index 2c58fcfd..67e6c416 100644
--- a/test/drawing/tc_pic.rb
+++ b/test/drawing/tc_pic.rb
@@ -9,10 +9,7 @@ class TestPic < Test::Unit::TestCase
@test_img_png = File.dirname(__FILE__) + "/../../examples/image1.png"
@test_img_gif = File.dirname(__FILE__) + "/../../examples/image1.gif"
@test_img_fake = File.dirname(__FILE__) + "/../../examples/image1_fake.jpg"
- @image = ws.add_image :image_src => @test_img, :hyperlink => 'https://github.com/randym', :tooltip => "What's up doc?"
- end
-
- def teardown
+ @image = ws.add_image :image_src => @test_img, :hyperlink => 'https://github.com/randym', :tooltip => "What's up doc?", :opacity => 5
end
def test_initialization
@@ -40,6 +37,7 @@ class TestPic < Test::Unit::TestCase
assert_equal(200, @image.width)
end
+
def test_hyperlink
assert_equal(@image.hyperlink.href, "https://github.com/randym")
@image.hyperlink = "http://axlsx.blogspot.com"
@@ -102,5 +100,4 @@ class TestPic < Test::Unit::TestCase
doc = Nokogiri::XML(@image.anchor.drawing.to_xml_string)
assert_equal r_id, doc.xpath("//a:blip").first["r:embed"]
end
-
end
diff --git a/test/drawing/tc_scatter_series.rb b/test/drawing/tc_scatter_series.rb
index 62a338b1..ea3611ab 100644
--- a/test/drawing/tc_scatter_series.rb
+++ b/test/drawing/tc_scatter_series.rb
@@ -18,28 +18,39 @@ class TestScatterSeries < Test::Unit::TestCase
@series = @chart.add_series :xData=>[1,2,4], :yData=>[1,3,9], :title=>"smoothed exponents"
assert(@series.smooth, "series is smooth by default on smooth charts")
end
-
+
def test_unsmoothed_chart_default_smoothing
@chart = @ws.add_chart Axlsx::ScatterChart, :title => "Unsmooth Chart", :scatter_style => :line
@series = @chart.add_series :xData=>[1,2,4], :yData=>[1,3,9], :title=>"unsmoothed exponents"
assert([email protected], "series is not smooth by default on non-smooth charts")
end
-
+
def test_explicit_smoothing
@chart = @ws.add_chart Axlsx::ScatterChart, :title => "Unsmooth Chart, Smooth Series", :scatter_style => :line
@series = @chart.add_series :xData=>[1,2,4], :yData=>[1,3,9], :title=>"smoothed exponents", :smooth => true
assert(@series.smooth, "series is smooth when overriding chart default")
- end
-
+ end
+
def test_explicit_unsmoothing
@chart = @ws.add_chart Axlsx::ScatterChart, :title => "Smooth Chart, Unsmooth Series", :scatter_style => :smoothMarker
@series = @chart.add_series :xData=>[1,2,4], :yData=>[1,3,9], :title=>"unsmoothed exponents", :smooth => false
assert([email protected], "series is not smooth when overriding chart default")
- end
+ end
+
+ def test_ln_width
+ @chart = @ws.add_chart Axlsx::ScatterChart, :title => "ln width", :scatter_style => :line
+ @series = @chart.add_series :xData=>[1,2,4], :yData=>[1,3,9], :title=>"ln_width"
+ @series.ln_width = 12700
+ assert_equal(@series.ln_width, 12700, 'line width assigment is allowed')
+ end
def test_to_xml_string
+ @chart.scatter_style = :line
+ @series.ln_width = 12700
doc = Nokogiri::XML(@chart.to_xml_string)
+ assert_equal(12700, @series.ln_width)
assert_equal(doc.xpath("//a:srgbClr[@val='#{@series.color}']").size,4)
+ assert_equal(doc.xpath("//a:ln[@w='#{@series.ln_width}']").length, 1)
end
end
diff --git a/test/drawing/tc_title.rb b/test/drawing/tc_title.rb
index 84345150..95e44602 100644
--- a/test/drawing/tc_title.rb
+++ b/test/drawing/tc_title.rb
@@ -19,6 +19,11 @@ class TestTitle < Test::Unit::TestCase
assert(@title.cell == nil)
end
+ def test_initialize_title_size
+ title = Axlsx::Title.new 'bob', 90
+ assert_equal "90", title.text_size
+ end
+
def test_text
assert_raise(ArgumentError, "text must be a string") { @title.text = 123 }
@title.cell = @row.cells.first
diff --git a/test/tc_package.rb b/test/tc_package.rb
index 58ff53b0..d89f35b0 100644
--- a/test/tc_package.rb
+++ b/test/tc_package.rb
@@ -7,6 +7,12 @@ class TestPackage < Test::Unit::TestCase
ws = @package.workbook.add_worksheet
ws.add_row ['Can', 'we', 'build it?']
ws.add_row ['Yes!', 'We', 'can!']
+ @rt = Axlsx::RichText.new
+ @rt.add_run "run 1", :b => true, :i => false
+ ws.add_row [@rt]
+
+ ws.rows.last.add_cell('b', :type => :text)
+
ws.outline_level_rows 0, 1
ws.outline_level_columns 0, 1
ws.add_hyperlink :ref => ws.rows.first.cells.last, :location => 'https://github.com/randym'
@@ -193,6 +199,7 @@ class TestPackage < Test::Unit::TestCase
def test_shared_strings_requires_part
@package.use_shared_strings = true
+ @package.to_stream #ensure all cell_serializer paths are hit
p = @package.send(:parts)
assert_equal(p.select{ |part| part[:entry] =~/xl\/sharedStrings.xml/}.size, 1, "shared strings table missing")
end
diff --git a/test/workbook/tc_shared_strings_table.rb b/test/workbook/tc_shared_strings_table.rb
index 25a0a0b2..b9347903 100644
--- a/test/workbook/tc_shared_strings_table.rb
+++ b/test/workbook/tc_shared_strings_table.rb
@@ -4,10 +4,12 @@ class TestSharedStringsTable < Test::Unit::TestCase
def setup
@p = Axlsx::Package.new :use_shared_strings=>true
+
ws = @p.workbook.add_worksheet
ws.add_row ['a', 1, 'b']
ws.add_row ['b', 1, 'c']
ws.add_row ['c', 1, 'd']
+ ws.rows.last.add_cell('b', :type => :text)
end
def test_workbook_has_shared_strings
@@ -16,7 +18,7 @@ class TestSharedStringsTable < Test::Unit::TestCase
def test_count
sst = @p.workbook.shared_strings
- assert_equal(sst.count, 6)
+ assert_equal(sst.count, 7)
end
def test_unique_count
@@ -54,5 +56,4 @@ class TestSharedStringsTable < Test::Unit::TestCase
# assert that the shared string was normalized to remove the control characters
assert_not_nil @p.workbook.shared_strings.to_xml_string.index("helloworld")
end
-
end
diff --git a/test/workbook/tc_workbook.rb b/test/workbook/tc_workbook.rb
index ab400db1..c2f8ebd6 100644
--- a/test/workbook/tc_workbook.rb
+++ b/test/workbook/tc_workbook.rb
@@ -33,6 +33,12 @@ class TestWorkbook < Test::Unit::TestCase
assert_equal(@wb.use_autowidth, false)
end
+ def test_is_reversed
+ assert_equal(@wb.is_reversed, nil)
+ assert_raise(ArgumentError) {@wb.is_reversed = 0.1}
+ assert_nothing_raised {@wb.is_reversed = true }
+ assert_equal(@wb.use_autowidth, true)
+ end
def test_sheet_by_name_retrieval
@wb.add_worksheet(:name=>'foo')
@@ -98,7 +104,16 @@ class TestWorkbook < Test::Unit::TestCase
end
assert(errors.empty?, "error free validation")
end
- def test_range_requires__valid_sheet
+
+ def test_to_xml_reversed
+ @wb.is_reversed = true
+ @wb.add_worksheet(:name => 'first')
+ second = @wb.add_worksheet(:name => 'second')
+ doc = Nokogiri::XML(@wb.to_xml_string)
+ assert_equal second.name, doc.xpath('//xmlns:workbook/xmlns:sheets/*[1]/@name').to_s
+ end
+
+ def test_range_requires_valid_sheet
ws = @wb.add_worksheet :name=>'fish'
ws.add_row [1,2,3]
ws.add_row [4,5,6]
@@ -136,7 +151,7 @@ class TestWorkbook < Test::Unit::TestCase
doc = Nokogiri::XML(@wb.to_xml_string)
assert_equal pivot_table.cache_definition.rId, doc.xpath("//xmlns:pivotCache").first["r:id"]
end
-
+
def test_worksheet_name_is_intact_after_serialized_into_xml
sheet = @wb.add_worksheet(:name => '_Example')
wb_xml = Nokogiri::XML(@wb.to_xml_string)
diff --git a/test/workbook/worksheet/tc_cell.rb b/test/workbook/worksheet/tc_cell.rb
index f61a254f..11b54f44 100644
--- a/test/workbook/worksheet/tc_cell.rb
+++ b/test/workbook/worksheet/tc_cell.rb
@@ -4,6 +4,7 @@ class TestCell < Test::Unit::TestCase
def setup
p = Axlsx::Package.new
+ p.use_shared_strings = true
@ws = p.workbook.add_worksheet :name=>"hmmm"
p.workbook.styles.add_style :sz=>20
@row = @ws.add_row
@@ -56,6 +57,19 @@ class TestCell < Test::Unit::TestCase
assert_equal('foo', @ws.workbook.defined_names.last.name)
end
+ def test_autowidth
+ style = @c.row.worksheet.workbook.styles.add_style({:alignment => {:horizontal => :center, :vertical => :center, :wrap_text => true}} )
+ @c.style = style
+ assert_equal(@c.autowidth, 5.5)
+ end
+
+ def test_time
+ @c.type = :time
+ now = DateTime.now
+ @c.value = now
+ assert_equal(@c.value, now.to_time)
+ end
+
def test_style
assert_raise(ArgumentError, "must reject invalid style indexes") { @[email protected] }
assert_nothing_raised("must allow valid style index changes") {@c.style=1}
diff --git a/test/workbook/worksheet/tc_pivot_table.rb b/test/workbook/worksheet/tc_pivot_table.rb
index ff7f8b92..6d7f4d1c 100644
--- a/test/workbook/worksheet/tc_pivot_table.rb
+++ b/test/workbook/worksheet/tc_pivot_table.rb
@@ -117,12 +117,7 @@ class TestPivotTable < Test::Unit::TestCase
end
def test_to_xml_string
- pivot_table = @ws.add_pivot_table('G5:G6', 'A1:D5')
- shared_test_pivot_table_xml_validity(pivot_table)
- end
-
- def test_to_xml_string_with_configuration
- pivot_table = @ws.add_pivot_table('G5:G6', 'A1:E5') do |pt|
+ pivot_table = @ws.add_pivot_table('G5:G6', 'A1:E5', {:no_subtotals_on_headers=>['Year']}) do |pt|
pt.rows = ['Year', 'Month']
pt.columns = ['Type']
pt.data = ['Sales']
diff --git a/test/workbook/worksheet/tc_rich_text_run.rb b/test/workbook/worksheet/tc_rich_text_run.rb
index f8b11f6c..e4a5ef80 100644
--- a/test/workbook/worksheet/tc_rich_text_run.rb
+++ b/test/workbook/worksheet/tc_rich_text_run.rb
@@ -7,7 +7,7 @@ class RichTextRun < Test::Unit::TestCase
@p.workbook.styles.add_style :sz => 20
@rtr = Axlsx::RichTextRun.new('hihihi', b: true, i: false)
@rtr2 = Axlsx::RichTextRun.new('hihi2hi2', b: false, i: true)
- @rt = Axlsx::RichText.new
+ @rt = Axlsx::RichText.new
@rt.runs << @rtr
@rt.runs << @rtr2
@row = @ws.add_row [@rt]
@@ -19,7 +19,7 @@ class RichTextRun < Test::Unit::TestCase
assert_equal(@rtr.b, true)
assert_equal(@rtr.i, false)
end
-
+
def test_font_size_with_custom_style_and_no_sz
@c.style = @c.row.worksheet.workbook.styles.add_style :bg_color => 'FF00FF'
sz = @rtr.send(:font_size)
@@ -41,12 +41,12 @@ class RichTextRun < Test::Unit::TestCase
sz2 = @rtr2.send(:font_size)
assert_equal(sz2, 52)
end
-
+
def test_rtr_with_sz
@rtr.sz = 25
assert_equal(25, @rtr.send(:font_size))
end
-
+
def test_color
assert_raise(ArgumentError) { @rtr.color = -1.1 }
assert_nothing_raised { @rtr.color = "FF00FF00" }
@@ -129,9 +129,9 @@ class RichTextRun < Test::Unit::TestCase
end
def test_family
- assert_raise(ArgumentError) { @c.family = -1.1 }
- assert_nothing_raised { @c.family = 5 }
- assert_equal(@c.family, 5)
+ assert_raise(ArgumentError) { @rtr.family = 0 }
+ assert_nothing_raised { @rtr.family = 1 }
+ assert_equal(@rtr.family, 1)
end
def test_b
@@ -139,11 +139,11 @@ class RichTextRun < Test::Unit::TestCase
assert_nothing_raised { @c.b = false }
assert_equal(@c.b, false)
end
-
+
def test_multiline_autowidth
wrap = @p.workbook.styles.add_style({:alignment => {:wrap_text => true}})
awtr = Axlsx::RichTextRun.new('I\'m bold' + "\n", :b => true)
- rt = Axlsx::RichText.new
+ rt = Axlsx::RichText.new
rt.runs << awtr
@ws.add_row [rt], :style => wrap
ar = [0]
@@ -151,7 +151,7 @@ class RichTextRun < Test::Unit::TestCase
assert_equal(ar.length, 2)
assert_equal(ar.last, 0)
end
-
+
def test_to_xml
schema = Nokogiri::XML::Schema(File.open(Axlsx::SML_XSD))
doc = Nokogiri::XML(@ws.to_xml_string)
@@ -161,7 +161,7 @@ class RichTextRun < Test::Unit::TestCase
errors.push error
end
assert(errors.empty?, "error free validation")
-
+
assert(doc.xpath('//rPr/b[@val=1]'))
assert(doc.xpath('//rPr/i[@val=0]'))
assert(doc.xpath('//rPr/b[@val=0]'))
diff --git a/test/workbook/worksheet/tc_table.rb b/test/workbook/worksheet/tc_table.rb
index 6f39bb13..8edfc099 100644
--- a/test/workbook/worksheet/tc_table.rb
+++ b/test/workbook/worksheet/tc_table.rb
@@ -47,9 +47,9 @@ class TestTable < Test::Unit::TestCase
def test_relationships
assert(@ws.relationships.empty?)
- table = @ws.add_table("A1:D5")
+ @ws.add_table("A1:D5")
assert_equal(@ws.relationships.size, 1, "adding a table adds a relationship")
- table = @ws.add_table("F1:J5")
+ @ws.add_table("F1:J5")
assert_equal(@ws.relationships.size, 2, "adding a table adds a relationship")
end
@@ -64,5 +64,4 @@ class TestTable < Test::Unit::TestCase
end
assert(errors.empty?, "error free validation")
end
-
end
diff --git a/test/workbook/worksheet/tc_worksheet.rb b/test/workbook/worksheet/tc_worksheet.rb
index 166850e5..fa8832d8 100644
--- a/test/workbook/worksheet/tc_worksheet.rb
+++ b/test/workbook/worksheet/tc_worksheet.rb
@@ -93,7 +93,7 @@ class TestWorksheet < Test::Unit::TestCase
page_setup = {:fit_to_height => 1, :fit_to_width => 1, :orientation => :landscape, :paper_width => "210mm", :paper_height => "297mm", :scale => 80}
print_options = {:grid_lines => true, :headings => true, :horizontal_centered => true, :vertical_centered => true}
header_footer = {:different_first => false, :different_odd_even => false, :odd_header => 'Header'}
- optioned = @ws.workbook.add_worksheet(:name => 'bob', :page_margins => page_margins, :page_setup => page_setup, :print_options => print_options, :header_footer => header_footer, :selected => true, :show_gridlines => false)
+ optioned = @ws.workbook.add_worksheet(:name => 'bob', :page_margins => page_margins, :page_setup => page_setup, :print_options => print_options, :header_footer => header_footer)
page_margins.keys.each do |key|
assert_equal(page_margins[key], optioned.page_margins.send(key))
end
@@ -107,23 +107,21 @@ class TestWorksheet < Test::Unit::TestCase
assert_equal(header_footer[key], optioned.header_footer.send(key))
end
assert_equal(optioned.name, 'bob')
- assert_equal(optioned.selected, true)
- assert_equal(optioned.show_gridlines, false)
end
- def test_use_gridlines
- assert_raise(ArgumentError) { @ws.show_gridlines = -1.1 }
- assert_nothing_raised { @ws.show_gridlines = false }
- assert_equal(@ws.show_gridlines, false)
- end
+ # def test_use_gridlines
+ # assert_raise(ArgumentError) { @ws.show_gridlines = -1.1 }
+ # assert_nothing_raised { @ws.show_gridlines = false }
+ # assert_equal(@ws.show_gridlines, false)
+ # end
- def test_selected
- assert_raise(ArgumentError) { @ws.selected = -1.1 }
- assert_nothing_raised { @ws.selected = true }
- assert_equal(@ws.selected, true)
- end
+ # def test_selected
+ # assert_raise(ArgumentError) { @ws.selected = -1.1 }
+ # assert_nothing_raised { @ws.selected = true }
+ # assert_equal(@ws.selected, true)
+ # end
def test_rels_pn
assert_equal(@ws.rels_pn, "worksheets/_rels/sheet1.xml.rels")
@@ -266,11 +264,11 @@ class TestWorksheet < Test::Unit::TestCase
end
end
- def test_to_xml_string_fit_to_page
- @ws.page_setup.fit_to_width = 1
- doc = Nokogiri::XML(@ws.to_xml_string)
- assert_equal(doc.xpath('//xmlns:worksheet/xmlns:sheetPr/xmlns:pageSetUpPr[@fitToPage=1]').size, 1)
- end
+ # def test_to_xml_string_fit_to_page
+ # @ws.page_setup.fit_to_width = 1
+ # doc = Nokogiri::XML(@ws.to_xml_string)
+ # assert_equal(doc.xpath('//xmlns:worksheet/xmlns:sheetPr/xmlns:pageSetUpPr[@fitToPage=1]').size, 1)
+ # end
def test_to_xml_string_dimensions
@ws.add_row [1,2,3]
@@ -278,22 +276,22 @@ class TestWorksheet < Test::Unit::TestCase
assert_equal(doc.xpath('//xmlns:worksheet/xmlns:dimension[@ref="A1:C1"]').size, 1)
end
- def test_fit_to_page_assignation_does_nothing
- @ws.fit_to_page = true
- assert_equal(@ws.fit_to_page?, false)
- end
+ # def test_fit_to_page_assignation_does_nothing
+ # @ws.fit_to_page = true
+ # assert_equal(@ws.fit_to_page?, false)
+ # end
- def test_to_xml_string_selected
- @ws.selected = true
- doc = Nokogiri::XML(@ws.to_xml_string)
- assert_equal(doc.xpath('//xmlns:worksheet/xmlns:sheetViews/xmlns:sheetView[@tabSelected=1]').size, 1)
- end
+ # def test_to_xml_string_selected
+ # @ws.selected = true
+ # doc = Nokogiri::XML(@ws.to_xml_string)
+ # assert_equal(doc.xpath('//xmlns:worksheet/xmlns:sheetViews/xmlns:sheetView[@tabSelected=1]').size, 1)
+ # end
- def test_to_xml_string_show_gridlines
- @ws.show_gridlines = false
- doc = Nokogiri::XML(@ws.to_xml_string)
- assert_equal(doc.xpath('//xmlns:worksheet/xmlns:sheetViews/xmlns:sheetView[@showGridLines=0]').size, 1)
- end
+ # def test_to_xml_string_show_gridlines
+ # @ws.show_gridlines = false
+ # doc = Nokogiri::XML(@ws.to_xml_string)
+ # assert_equal(doc.xpath('//xmlns:worksheet/xmlns:sheetViews/xmlns:sheetView[@showGridLines=0]').size, 1)
+ # end
def test_to_xml_string_auto_fit_data
@ws.add_row [1, "two"]
@@ -439,15 +437,15 @@ class TestWorksheet < Test::Unit::TestCase
def test_relationships
@ws.add_row [1,2,3]
assert(@ws.relationships.empty?, "No Drawing relationship until you add a chart")
- c = @ws.add_chart Axlsx::Pie3DChart
+ @ws.add_chart Axlsx::Pie3DChart
assert_equal(@ws.relationships.size, 1, "adding a chart creates the relationship")
- c = @ws.add_chart Axlsx::Pie3DChart
+ @ws.add_chart Axlsx::Pie3DChart
assert_equal(@ws.relationships.size, 1, "multiple charts still only result in one relationship")
- c = @ws.add_comment :text => 'builder', :author => 'bob', :ref => @ws.rows.last.cells.last
+ @ws.add_comment :text => 'builder', :author => 'bob', :ref => @ws.rows.last.cells.last
assert_equal(@ws.relationships.size, 3, "adding a comment adds 2 relationships")
- c = @ws.add_comment :text => 'not that is a comment!', :author => 'travis', :ref => "A1"
+ @ws.add_comment :text => 'not that is a comment!', :author => 'travis', :ref => "A1"
assert_equal(@ws.relationships.size, 3, "adding multiple comments in the same worksheet should not add any additional comment relationships")
- c = @ws.add_pivot_table 'G5:G6', 'A1:D10'
+ @ws.add_pivot_table 'G5:G6', 'A1:D10'
assert_equal(@ws.relationships.size, 4, "adding a pivot table adds 1 relationship")
end
@@ -580,7 +578,7 @@ 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)