Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

spreadsheet-0.6.8.gem released

  • Loading branch information...
commit 3748121dcb2f4873499d1c3bcac4906af7424e92 2 parents 9d486bd + e318958
Zeno R.R. Davatz authored January 20, 2012
2  .gitignore
... ...
@@ -0,0 +1,2 @@
  1
+tags
  2
+*.swp
12  lib/spreadsheet/excel/writer/worksheet.rb
@@ -756,14 +756,18 @@ def write_row row
756 756
              else
757 757
                height * TWIPS
758 758
              end
759  
-    # TODO: Row spacing
760  
-    data = [
  759
+
  760
+    attrs = [
761 761
       row.idx,
762 762
       row.first_used,
763 763
       row.first_unused,
764 764
       height,
765  
-      opts,
766  
-    ].pack binfmt(:row)
  765
+      opts]
  766
+
  767
+    return if attrs.any?(&:nil?)
  768
+
  769
+    # TODO: Row spacing
  770
+    data = attrs.pack binfmt(:row)
767 771
     write_op opcode(:row), data
768 772
   end
769 773
   def write_rowblock block
71  test/excel/writer/worksheet.rb
@@ -7,34 +7,49 @@
7 7
 module Spreadsheet
8 8
   module Excel
9 9
     module Writer
10  
-class TestWorksheet < Test::Unit::TestCase
11  
-  def test_need_number
12  
-    sheet = Worksheet.new nil, nil
13  
-    assert_equal false, sheet.need_number?(10)
14  
-    assert_equal false, sheet.need_number?(114.55)
15  
-    assert_equal false, sheet.need_number?(0.1)
16  
-    assert_equal false, sheet.need_number?(0.01)
17  
-    assert_equal false, sheet.need_number?(0 / 0.0) # NaN
18  
-    assert_equal true, sheet.need_number?(0.001)
19  
-    assert_equal true, sheet.need_number?(10000000.0)
20  
-  end
21  
-  def test_write_merged_cells
22  
-    # top/bottom/left/right cell of test range 1/2
23  
-    r1t, r1b, r1l, r1r = 0, 0, 0, 1
24  
-    r2t, r2b, r2l, r2r = 1, 2, 0, 0
25  
-    book = Spreadsheet::Workbook.new
26  
-    sheet = book.create_worksheet
27  
-    sheet.merge_cells(r1t, r1l, r1b, r1r)
28  
-    sheet.merge_cells(r2t, r2l, r2b, r2r)
29  
-    assert_equal [[r1t, r1b, r1l, r1r], [r2t, r2b, r2l, r2r]], sheet.merged_cells
30  
-    io = StringIO.new
31  
-    book.write(io)
32  
-    book2 = Spreadsheet.open(io)
33  
-    sheet2 = book2.worksheet(0)
34  
-    sheet2[0,0] # trigger read_worksheet
35  
-    assert_equal [[r1t, r1b, r1l, r1r], [r2t, r2b, r2l, r2r]], sheet2.merged_cells
36  
-  end
37  
-end
  10
+     class TestWorksheet < Test::Unit::TestCase
  11
+        def test_need_number
  12
+          sheet = Worksheet.new nil, nil
  13
+          assert_equal false, sheet.need_number?(10)
  14
+          assert_equal false, sheet.need_number?(114.55)
  15
+          assert_equal false, sheet.need_number?(0.1)
  16
+          assert_equal false, sheet.need_number?(0.01)
  17
+          assert_equal false, sheet.need_number?(0 / 0.0) # NaN
  18
+          assert_equal true, sheet.need_number?(0.001)
  19
+          assert_equal true, sheet.need_number?(10000000.0)
  20
+        end
  21
+
  22
+        class RowMock
  23
+          attr_accessor :idx, :first_used, :first_unused, :height, :outline_level
  24
+
  25
+          def initialize
  26
+            @idx, @first_used, @first_unused, @height, @outline_level = 0,0,0,0,1
  27
+          end
  28
+
  29
+          def method_missing name, *args
  30
+            nil
  31
+          end
  32
+        end
  33
+
  34
+        def test_write_row_should_not_write_if_the_row_has_no_used_columns
  35
+          sheet = Worksheet.new nil, nil
  36
+          row = RowMock.new
  37
+          row.first_used = nil
  38
+
  39
+          sheet.write_row row
  40
+
  41
+          assert_equal '', sheet.data
  42
+        end
  43
+
  44
+        def test_write_row_should_write_if_any_column_is_used
  45
+          sheet = Worksheet.new nil, nil
  46
+          row = RowMock.new
  47
+
  48
+          sheet.write_row row
  49
+
  50
+          assert_equal false, sheet.data.empty?
  51
+        end
  52
+      end
38 53
     end
39 54
   end
40 55
 end

0 notes on commit 3748121

Please sign in to comment.
Something went wrong with that request. Please try again.