diff options
| author | Randy Morgan <[email protected]> | 2013-06-23 10:11:23 +0100 |
|---|---|---|
| committer | Randy Morgan <[email protected]> | 2013-06-23 10:11:23 +0100 |
| commit | 86180711acbb7f9c6a04688fc9e6ffbf27bacf19 (patch) | |
| tree | 336dbcaeb65f9161f2b361c485a8e65976f13357 | |
| parent | 7caf2ea9dfe92fa418f40132ea3c94d3da109f2c (diff) | |
| download | caxlsx-86180711acbb7f9c6a04688fc9e6ffbf27bacf19.tar.gz caxlsx-86180711acbb7f9c6a04688fc9e6ffbf27bacf19.zip | |
added sparse array transposition with blocks for rows/cols switching and some docs updates for release prep
| -rw-r--r-- | README.md | 8 | ||||
| -rw-r--r-- | cd | 1 | ||||
| -rw-r--r-- | examples/underline.rb | 13 | ||||
| -rw-r--r-- | exclusive.rb | 32 | ||||
| -rw-r--r-- | lib/axlsx/package.rb | 12 | ||||
| -rw-r--r-- | lib/axlsx/workbook/worksheet/worksheet.rb | 9 | ||||
| -rw-r--r-- | test/workbook/worksheet/tc_worksheet.rb | 7 |
7 files changed, 71 insertions, 11 deletions
@@ -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. @@ -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] |
