summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--README.md8
-rw-r--r--cd1
-rw-r--r--examples/underline.rb13
-rw-r--r--exclusive.rb32
-rw-r--r--lib/axlsx/drawing/axes.rb10
-rw-r--r--lib/axlsx/drawing/bar_3D_chart.rb4
-rw-r--r--lib/axlsx/package.rb12
-rw-r--r--lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb2
-rw-r--r--lib/axlsx/workbook/worksheet/worksheet.rb9
-rw-r--r--test/drawing/tc_axes.rb8
-rw-r--r--test/drawing/tc_bar_3D_chart.rb6
-rw-r--r--test/workbook/worksheet/tc_conditional_formatting.rb6
-rw-r--r--test/workbook/worksheet/tc_worksheet.rb7
13 files changed, 99 insertions, 19 deletions
diff --git a/README.md b/README.md
index 20f67088..ff3fe557 100644
--- a/README.md
+++ b/README.md
@@ -21,7 +21,7 @@ appreciation for the gem, please don't hesitate to make a donation.
**License**: MIT License
-**Latest Version**: 1.3.6
+**Latest Version**: 1.3.7
**Ruby Version**: 1.8.7 (soon to be depreciated!!!), 1.9.2, 1.9.3, 2.0.0
@@ -29,7 +29,7 @@ appreciation for the gem, please don't hesitate to make a donation.
**Rubinius Version**: rubinius 2.0.0dev * lower versions may run, this gem always tests against head.
-**Release Date**: April 24th 2013
+**Release Date**: June ? 2013
If you are working in rails, or with active record see:
[acts_as_xlsx](http://github.com/randym/acts_as_xlsx)
@@ -160,7 +160,9 @@ This gem has 100% test coverage using test/unit. To execute tests for this gem,
#Change log
---------
-- **April.??.13**:1.37
+- **June.?.13**:1.3.7
+ - Bugfix: transposition of cells for Worksheet#cols now supports
+ incongruent column counts.counts
- Added space preservation for cell text. This will allow whitespace
in cell text both when using shared strings and when serializing
directly to the cell.
diff --git a/cd b/cd
new file mode 100644
index 00000000..8588caed
--- /dev/null
+++ b/cd
@@ -0,0 +1 @@
+/opt/boxen/rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/axlsx-1.3.6/lib/axlsx.rb
diff --git a/examples/underline.rb b/examples/underline.rb
new file mode 100644
index 00000000..ccd1b394
--- /dev/null
+++ b/examples/underline.rb
@@ -0,0 +1,13 @@
+$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
+require 'axlsx'
+p = Axlsx::Package.new
+p.workbook do |wb|
+ wb.styles do |s|
+ no_underline = s.add_style :sz => 10, :b => true, :u => false, :alignment => { :horizontal=> :right }
+ wb.add_worksheet(:name => 'wunderlinen') do |sheet|
+ sheet.add_row %w{a b c really?}, :style => no_underline
+ end
+ end
+end
+p.serialize 'no_underline.xlsx'
+
diff --git a/exclusive.rb b/exclusive.rb
new file mode 100644
index 00000000..71339146
--- /dev/null
+++ b/exclusive.rb
@@ -0,0 +1,32 @@
+
+def exclusively_true(hash, key)
+ #clone = hash.clone
+ return false unless hash.delete(key) == true
+ !hash.has_value? true
+end
+
+require 'test/unit'
+class TestExclusive < Test::Unit::TestCase
+ def setup
+ @test_hash = {foo: true, bar: false, hoge: false}
+ end
+ def test_exclusive
+ assert_equal(true, exclusively_true(@test_hash, :foo))
+ end
+ def test_inexclusive
+ @test_hash[:bar] = true
+ assert_equal(false, exclusively_true(@test_hash, :foo))
+ end
+end
+
+require 'benchmark'
+
+h = {foo: true}
+999.times {|i| h["a#{i}"] = false}
+Benchmark.bmbm(30) do |x|
+ x.report('exclusively_true') do
+ 1000.times do
+ exclusively_true(h, :foo)
+ end
+ end
+end
diff --git a/lib/axlsx/drawing/axes.rb b/lib/axlsx/drawing/axes.rb
index c3a8dd85..bc40e532 100644
--- a/lib/axlsx/drawing/axes.rb
+++ b/lib/axlsx/drawing/axes.rb
@@ -5,9 +5,11 @@ module Axlsx
class Axes
# @param [Hash] options options used to generate axis each key
- # should be an axis name like :val_axix and its value should be the
- # class of the axis type to construct.
+ # should be an axis name like :val_axis and its value should be the
+ # class of the axis type to construct. The :cat_axis, if there is one,
+ # must come first (we assume a Ruby 1.9+ Hash or an OrderedHash).
def initialize(options={})
+ raise(ArgumentError, "CatAxis must come first") if options.keys.include?(:cat_axis) && options.keys.first != :cat_axis
options.each do |name, axis_class|
add_axis(name, axis_class)
end
@@ -28,7 +30,9 @@ module Axlsx
# serialized. Otherwise, each axis is serialized in full.
def to_xml_string(str = '', options = {})
if options[:ids]
- axes.inject(str) { |string, axis| string << '<c:axId val="' << axis[1].id.to_s << '"/>' }
+ # CatAxis must come first in the XML (for Microsoft Excel at least)
+ sorted = axes.sort_by { |name, axis| axis.kind_of?(CatAxis) ? 0 : 1 }
+ sorted.inject(str) { |string, axis| string << '<c:axId val="' << axis[1].id.to_s << '"/>' }
else
axes.each { |axis| axis[1].to_xml_string(str) }
end
diff --git a/lib/axlsx/drawing/bar_3D_chart.rb b/lib/axlsx/drawing/bar_3D_chart.rb
index 3315ad80..755f334c 100644
--- a/lib/axlsx/drawing/bar_3D_chart.rb
+++ b/lib/axlsx/drawing/bar_3D_chart.rb
@@ -142,10 +142,10 @@ module Axlsx
end
# A hash of axes used by this chart. Bar charts have a value and
- # category axes specified via axex[:val_axes] and axes[:cat_axis]
+ # category axes specified via axes[:val_axes] and axes[:cat_axis]
# @return [Axes]
def axes
- @axes ||= Axes.new(:val_axis => ValAxis, :cat_axis => CatAxis)
+ @axes ||= Axes.new(:cat_axis => CatAxis, :val_axis => ValAxis)
end
end
end
diff --git a/lib/axlsx/package.rb b/lib/axlsx/package.rb
index 5a5a2169..37620b48 100644
--- a/lib/axlsx/package.rb
+++ b/lib/axlsx/package.rb
@@ -37,12 +37,6 @@ module Axlsx
end
- # Shortcut to specify that the workbook should use shared strings
- # @see Workbook#use_shared_strings
- def use_shared_strings=(v)
- Axlsx::validate_boolean(v);
- workbook.use_shared_strings = v
- end
# Shortcut to determine if the workbook is configured to use shared strings
# @see Workbook#use_shared_strings
@@ -50,6 +44,12 @@ module Axlsx
workbook.use_shared_strings
end
+ # Shortcut to specify that the workbook should use shared strings
+ # @see Workbook#use_shared_strings
+ def use_shared_strings=(v)
+ Axlsx::validate_boolean(v);
+ workbook.use_shared_strings = v
+ end
# The workbook this package will serialize or validate.
# @return [Workbook] If no workbook instance has been assigned with this package a new Workbook instance is returned.
# @raise ArgumentError if workbook parameter is not a Workbook instance.
diff --git a/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb b/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb
index 9db091be..916b31c2 100644
--- a/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb
+++ b/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb
@@ -182,7 +182,7 @@ module Axlsx
# @see timePeriod
def timePeriod=(v); Axlsx::validate_time_period_type(v); @timePeriod = v end
# @see formula
- def formula=(v); [*v].each {|x| Axlsx::validate_string(x) }; @formula = v end
+ def formula=(v); [*v].each {|x| Axlsx::validate_string(x) }; @formula = [*v].map { |form| ::CGI.escapeHTML(form) } end
# @see color_scale
def color_scale=(v)
diff --git a/lib/axlsx/workbook/worksheet/worksheet.rb b/lib/axlsx/workbook/worksheet/worksheet.rb
index 1187bf83..7324181a 100644
--- a/lib/axlsx/workbook/worksheet/worksheet.rb
+++ b/lib/axlsx/workbook/worksheet/worksheet.rb
@@ -115,8 +115,13 @@ module Axlsx
end
# returns the sheet data as columns
- def cols
- @rows.transpose
+ # If you pass a block, it will be evaluated whenever a row does not have a
+ # cell at a specific index. The block will be called with the row and column
+ # index in the missing cell was found.
+ # @example
+ # cols { |row_index, column_index| p "warn - row #{row_index} is does not have a cell at #{column_index}
+ def cols(&block)
+ @rows.transpose(&block)
end
# An range that excel will apply an auto-filter to "A1:B3"
diff --git a/test/drawing/tc_axes.rb b/test/drawing/tc_axes.rb
new file mode 100644
index 00000000..e3c26936
--- /dev/null
+++ b/test/drawing/tc_axes.rb
@@ -0,0 +1,8 @@
+require 'tc_helper.rb'
+
+class TestAxes < Test::Unit::TestCase
+ def test_constructor_requires_cat_axis_first
+ assert_raise(ArgumentError) { Axlsx::Axes.new(:val_axis => Axlsx::ValAxis, :cat_axis => Axlsx::CatAxis) }
+ assert_nothing_raised { Axlsx::Axes.new(:cat_axis => Axlsx::CatAxis, :val_axis => Axlsx::ValAxis) }
+ end
+end \ No newline at end of file
diff --git a/test/drawing/tc_bar_3D_chart.rb b/test/drawing/tc_bar_3D_chart.rb
index 3e1ff342..0cae7af6 100644
--- a/test/drawing/tc_bar_3D_chart.rb
+++ b/test/drawing/tc_bar_3D_chart.rb
@@ -62,4 +62,10 @@ class TestBar3DChart < Test::Unit::TestCase
assert(errors.empty?, "error free validation")
end
+ def test_to_xml_string_has_axes_in_correct_order
+ str = @chart.to_xml_string
+ cat_axis_position = str.index(@chart.axes[:cat_axis].id.to_s)
+ val_axis_position = str.index(@chart.axes[:val_axis].id.to_s)
+ assert(cat_axis_position < val_axis_position, "cat_axis must occur earlier than val_axis in the XML")
+ end
end
diff --git a/test/workbook/worksheet/tc_conditional_formatting.rb b/test/workbook/worksheet/tc_conditional_formatting.rb
index 42e29fa6..9e5e01cf 100644
--- a/test/workbook/worksheet/tc_conditional_formatting.rb
+++ b/test/workbook/worksheet/tc_conditional_formatting.rb
@@ -131,9 +131,11 @@ class TestConditionalFormatting < Test::Unit::TestCase
end
def test_multiple_formulas
- @ws.add_conditional_formatting "B3:B3", { :type => :cellIs, :dxfId => 0, :priority => 1, :operator => :between, :formula => ["1","5"] }
+ @ws.add_conditional_formatting "B3:B3", { :type => :cellIs, :dxfId => 0, :priority => 1, :operator => :between, :formula => ["1 <> 2","5"] }
doc = Nokogiri::XML.parse(@ws.to_xml_string)
- assert doc.xpath("//xmlns:worksheet/xmlns:conditionalFormatting//xmlns:cfRule[@type='cellIs'][@dxfId=0][@priority=1][@operator='between']//xmlns:formula='1'")
+ p doc.xpath("//xmlns:worksheet/xmlns:conditionalFormatting//xmlns:cfRule[@type='cellIs'][@dxfId=0][@priority=1][@operator='between']")
+
+ assert doc.xpath("//xmlns:worksheet/xmlns:conditionalFormatting//xmlns:cfRule[@type='cellIs'][@dxfId=0][@priority=1][@operator='between']//xmlns:formula='1 <> 2'")
assert doc.xpath("//xmlns:worksheet/xmlns:conditionalFormatting//xmlns:cfRule[@type='cellIs'][@dxfId=0][@priority=1][@operator='between']//xmlns:formula='5'")
end
diff --git a/test/workbook/worksheet/tc_worksheet.rb b/test/workbook/worksheet/tc_worksheet.rb
index b05a1c56..980c9e01 100644
--- a/test/workbook/worksheet/tc_worksheet.rb
+++ b/test/workbook/worksheet/tc_worksheet.rb
@@ -212,6 +212,13 @@ class TestWorksheet < Test::Unit::TestCase
assert_equal(c[0].value, 2)
end
+ def test_cols_with_block
+ @ws.add_row [1,2,3]
+ @ws.add_row [1]
+ cols = @ws.cols {|row, column| :foo }
+ assert_equal(:foo, cols[1][1])
+ end
+
def test_row_style
@ws.add_row [1,2,3,4]
@ws.add_row [1,2,3,4]