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/package.rb12
-rw-r--r--lib/axlsx/workbook/worksheet/worksheet.rb9
-rw-r--r--test/workbook/worksheet/tc_worksheet.rb7
7 files changed, 71 insertions, 11 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 df87ed12..13a3bd13 100644
--- a/lib/axlsx/package.rb
+++ b/lib/axlsx/package.rb
@@ -35,12 +35,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
@@ -48,6 +42,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/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_worksheet.rb b/test/workbook/worksheet/tc_worksheet.rb
index b05a1c56..20bd0771 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 }
+ asser_equal(:foo, cols[1][1])
+ end
+
def test_row_style
@ws.add_row [1,2,3,4]
@ws.add_row [1,2,3,4]