summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMoses Hohman <[email protected]>2013-06-27 15:37:30 -0500
committerMoses Hohman <[email protected]>2013-06-27 15:37:30 -0500
commit9e2b64a27b2f13694fb1f53d1e50cc5120714521 (patch)
treeaf5cab55de83cf3688283f081bf0b79a7e06196f
parentc560d142d36c211154f03f271747f8756e75fc63 (diff)
parent4954543cc0892008f580f05cfb810fb0986b107f (diff)
downloadcaxlsx-9e2b64a27b2f13694fb1f53d1e50cc5120714521.tar.gz
caxlsx-9e2b64a27b2f13694fb1f53d1e50cc5120714521.zip
Merge remote-tracking branch 'randym/master'
* randym/master: escape formula for conditional formatting fix typo in specs added sparse array transposition with blocks for rows/cols switching and some docs updates for release prep
-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/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/workbook/worksheet/tc_conditional_formatting.rb6
-rw-r--r--test/workbook/worksheet/tc_worksheet.rb7
9 files changed, 76 insertions, 14 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/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/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]