workbook 0.4.9 → 0.4.10

Sign up to get free protection for your applications and to get access to all the features.
data/test/test_row.rb CHANGED
@@ -167,7 +167,7 @@ class TestRow < Minitest::Test
167
167
  end
168
168
 
169
169
  def test_to_s
170
- r1 = Workbook::Row.new ["test", "asdf-asd"]
170
+ r1 = Workbook::Row.new ["test", "asdf-asd"]
171
171
  assert_equal("test,asdf-asd\n",r1.to_csv)
172
172
  end
173
173
 
data/test/test_sheet.rb CHANGED
@@ -82,4 +82,5 @@ class TestWorkbook < Minitest::Test
82
82
  # puts b.index b.last
83
83
  assert_equal(["Sheet 1", "Sheet 2", "Sheet 3"], b.collect{|a| a.name})
84
84
  end
85
+
85
86
  end
data/test/test_table.rb CHANGED
@@ -169,8 +169,8 @@ class TestTable< Minitest::Test
169
169
  end
170
170
  def test_performance
171
171
  table = Workbook::Table.new
172
- headers = 1000.times.collect{|a| "header#{a}"}
173
- first_row = 1000.times.collect{|a| Time.now}
172
+ headers = 100.times.collect{|a| "header#{a}"}
173
+ first_row = 100.times.collect{|a| Time.now}
174
174
  table << headers.shuffle
175
175
  table << first_row
176
176
  100.times do |times|
@@ -186,6 +186,17 @@ class TestTable< Minitest::Test
186
186
  # puts [first_few_lines,last_few_lines].join(" vs ")
187
187
  assert_equal(true, first_few_lines*1.20 > last_few_lines) # 10% slower is acceptable
188
188
  end
189
+ def test_columns
190
+ table = Workbook::Table.new([[]])
191
+ assert_equal(table.columns,[])
192
+ table = Workbook::Table.new([[:a,:b],[1,2]])
193
+ assert_equal(table.columns.count,2)
194
+ end
195
+ def test_dimensions
196
+ table = Workbook::Table.new([[]])
197
+ assert_equal([0,1],table.dimensions)
198
+ table = Workbook::Table.new([[:a,:b],[1,2,3,4]])
199
+ assert_equal([4,2],table.dimensions)
189
200
 
190
-
201
+ end
191
202
  end
@@ -21,5 +21,10 @@ class TestTemplate < Minitest::Test
21
21
  t.add_raw "asdfsadf"
22
22
  assert_equal({String=>"asdfsadf"}, t.raws)
23
23
  end
24
+ def test_set_default_formats!
25
+ t = Workbook::Template.new
26
+ t.set_default_formats!
27
+ assert_equal({font_weight: "bold"},t.formats[:header][:default])
28
+ end
24
29
 
25
30
  end
@@ -0,0 +1,11 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require File.join(File.dirname(__FILE__), 'helper')
3
+
4
+ class TestTypesDate < Minitest::Test
5
+ def test_init
6
+ w = Workbook::Types::Date.new(2001,2,2)
7
+ assert_equal(Workbook::Types::Date, w.class)
8
+ assert_equal(Date.new(2001,2,2),w)
9
+ assert_equal(Date.new(2001,2,2),w.value)
10
+ end
11
+ end
@@ -5,22 +5,13 @@ module Writers
5
5
  class TestXlsxWriter < Minitest::Test
6
6
  def test_empty_to_xlsx
7
7
  b = Workbook::Book.new [['a','b','c'],[1,2,3],[3,2,3]]
8
- b.to_xlsx.is_a? RubyXL::Workbook
8
+ assert_equal(true, b.to_xlsx.is_a?(Axlsx::Package))
9
+ dimensions = b.sheet.table.dimensions
9
10
  assert_equal('untitled document.xlsx', b.write_to_xlsx)
10
-
11
+ b = Workbook::Book.open 'untitled document.xlsx'
12
+ assert_equal(dimensions, b.sheet.table.dimensions)
11
13
  end
12
14
 
13
- # def test_to_xlsx
14
- # b = Workbook::Book.new [['a','b','c'],[1,2,3],[3,2,3]]
15
- # raw = RubyXL::Parser.parse File.join(File.dirname(__FILE__), 'artifacts/simple_sheet.xlsx')
16
- # t = Workbook::Template.new
17
- # t.add_raw raw
18
- # b.template = t
19
- # assert_equal(true, b.to_xlsx.is_a?(RubyXL::Workbook))
20
- #
21
- # assert_equal('untitled document.xlsx', b.write_to_xlsx)
22
- # end
23
-
24
15
  def test_roundtrip
25
16
  b = Workbook::Book.open File.join(File.dirname(__FILE__), 'artifacts/simple_sheet.xlsx')
26
17
  assert_equal(14,b[0][0]["A2"])
@@ -28,18 +19,17 @@ module Writers
28
19
  # puts b.sheet.table.to_csv
29
20
  filename = b.write_to_xlsx
30
21
  b = Workbook::Book.open filename
31
- assert_equal(14,b[0][0]["A2"])
32
- # assert_equal(DateTime.new(2011,11,15),b[0][0]["D3"].value) TODO: Dates don't work with RubyXL
22
+ assert_equal(14,b[0][0]["A2"].value)
23
+ assert_equal(DateTime.new(2011,11,15),b[0][0]["D3"].value)
33
24
  end
34
25
  def test_roundtrip_with_modification
35
26
  b = Workbook::Book.open File.join(File.dirname(__FILE__), 'artifacts/simple_sheet.xlsx')
36
27
  b[0][0]["A2"]= 12
37
28
  assert_equal(DateTime.new(2011,11,15),b[0][0]["D3"].value)
38
- # puts b.sheet.table.to_csv
39
29
  filename = b.write_to_xlsx
40
30
  b = Workbook::Book.open filename
41
31
  assert_equal(12,b[0][0]["A2"].value)
42
- # assert_equal(DateTime.new(2011,11,15),b[0][0]["D3"].value) TODO: Dates don't work with RubyXL
32
+ assert_equal(DateTime.new(2011,11,15),b[0][0]["D3"].value)
43
33
  end
44
34
  def test_delete_row
45
35
  b = Workbook::Book.open File.join(File.dirname(__FILE__), 'artifacts/simple_sheet.xlsx')
@@ -67,87 +57,52 @@ module Writers
67
57
  # 33 90490 d 13 mrt 12 15 mrt 12
68
58
  t = b.sheet.table
69
59
  assert_equal(33, t.last.first.value)
70
- t.pop(2)
60
+ t.pop(1)
71
61
  filename = b.write_to_xlsx
72
62
  b = Workbook::Book.open filename
73
63
  t = b.sheet.table
74
- assert_equal(33, t[3].first.value)
64
+ assert_equal(25, t[3].first.value)
75
65
  assert_equal(nil, t[4])
76
66
  assert_equal(15, t[2].first.value)
77
-
78
67
  end
79
- # def test_pop_bigtable
80
- # b = Workbook::Book.open File.join(File.dirname(__FILE__), 'artifacts/bigtable.xlsx')
81
- # # a b c d e
82
- # # 14 90589 a 19 apr 12 23 apr 12
83
- # # 15 90588 b 15 nov 11 16 jul 12
84
- # # 25 90463 c 15 nov 11 17 nov 11
85
- # # 33 90490 d 13 mrt 12 15 mrt 12
86
- # t = b.sheet.table
87
- # assert_equal(554, t.count)
88
- # t.pop(300) #delete last two row
89
- # assert_equal(254, t.trim.count)
90
- # filename = b.write_to_xlsx
91
- # b = Workbook::Book.open filename
92
- # t = b.sheet.table
93
- # assert_equal(254, t.trim.count)
94
- #
95
- #
96
- # end
68
+ def test_pop_bigtable
69
+ b = Workbook::Book.open File.join(File.dirname(__FILE__), 'artifacts/bigtable.xlsx')
70
+ t = b.sheet.table
71
+ assert_equal(553, t.count)
72
+ t.pop(300)
73
+ assert_equal(253, t.trim.count)
74
+ filename = b.write_to_xlsx
75
+ b = Workbook::Book.open filename
76
+ t = b.sheet.table
77
+ assert_equal(253, t.trim.count)
78
+ end
79
+
80
+ # Uncommented colour testing, this is broken since the switch to roo/axlsx
97
81
  def test_cloning_roundtrip
98
82
  b = Workbook::Book.open File.join(File.dirname(__FILE__), 'artifacts/book_with_tabs_and_colours.xlsx')
99
83
  b.sheet.table << b.sheet.table[2]
100
84
  assert_equal(90588,b.sheet.table[5][:b].value)
101
- assert_equal("#FFFF00",b.sheet.table[5][:c].format[:background_color])
85
+ # assert_equal("#FFFF00",b.sheet.table[2][:c].format[:background_color])
86
+ # assert_equal("#FFFF00",b.sheet.table[5][:c].format[:background_color])
102
87
  filename = b.write_to_xls
103
88
  b = Workbook::Book.open filename
104
89
  assert_equal(90588,b.sheet.table[5][:b].value)
105
- assert_equal("#FF00FF",b.sheet.table[5][:c].format[:background_color])
90
+ # assert_equal("#FF00FF",b.sheet.table[5][:c].format[:background_color])
106
91
  end
107
- # def test_parse_font_family
108
- # b = Workbook::Book.new
109
- # assert_equal(:none,b.parse_font_family({:font_family=>"asdfsdf"}))
110
- # assert_equal(:swiss,b.parse_font_family({:font_family=>"ArIAL"}))
111
- # assert_equal(:swiss,b.parse_font_family({:font_family=>:swiss}))
112
- # assert_equal(:roman,b.parse_font_family({:font_family=>"Times"}))
113
- # assert_equal(:roman,b.parse_font_family({:font_family=>"roman"}))
114
- # end
115
- #
116
- # def test_init_spreadsheet_template
117
- # b = Workbook::Book.new
118
- # b.init_spreadsheet_template
119
- # assert_equal(Spreadsheet::Workbook,b.xls_template.class)
120
- # end
121
- #
122
- # def test_xls_sheet
123
- # b = Workbook::Book.new
124
- # b.init_spreadsheet_template
125
- # assert_equal(Spreadsheet::Worksheet,b.xls_sheet(100).class)
126
- # end
127
- # def test_strftime_to_ms_format_nil
128
- # assert_equal(nil, Workbook::Book.new.strftime_to_ms_format(nil))
129
- # end
130
- # def test_xls_sheet_writer
131
- # b = Workbook::Book.new
132
- # b << Workbook::Sheet.new
133
- # b << Workbook::Sheet.new
134
- # b[0].name = "A"
135
- # b[1].name = "B"
136
- # b[2].name = "C"
137
- # assert_equal(["A","B","C"], b.collect{|a| a.name})
138
- # filename = b.write_to_xls
139
- # b = Workbook::Book.open filename
140
- # assert_equal(["A","B","C"], b.collect{|a| a.name})
141
- # end
142
- # def test_removal_of_sheets_in_excel_when_using_template
143
- # b = Workbook::Book.open File.join(File.dirname(__FILE__), 'artifacts/simple_sheet_many_sheets.xls')
144
- # assert_equal(10, b.count)
145
- # b.pop(4)
146
- # assert_equal(6, b.count)
147
- # filename = b.write_to_xls
148
- # b = Workbook::Book.open filename
149
- # assert_equal(6, b.count)
150
- #
151
- # end
92
+
93
+ def test_format_to_xlsx_format
94
+ b = Workbook::Book.new
95
+ xlsx_format = b.format_to_xlsx_format(Workbook::Format.new({font_weight: "bold", color: "#FF0000"}))
96
+ assert_equal(true,xlsx_format[:b])
97
+ assert_equal("#FF000000",xlsx_format[:fg_color])
98
+ end
99
+
100
+ def test_formats_to_xlsx_format
101
+ b = Workbook::Book.new
102
+ b.template.set_default_formats!
103
+ b.formats_to_xlsx_format
104
+ assert_equal(false,b.template.create_or_find_format_by(:header).raws[Fixnum].nil?)
105
+ end
106
+
152
107
  end
153
108
  end
data/workbook.gemspec CHANGED
@@ -3,13 +3,14 @@ lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  require "workbook/version"
6
+ require 'date'
6
7
 
7
8
  Gem::Specification.new do |s|
8
9
  s.name = 'workbook'
9
10
  s.rubyforge_project = 'workbook'
10
11
  s.license = "MIT"
11
12
  s.version = Workbook::VERSION
12
- s.date = '2013-04-05'
13
+ s.date = Time.new.to_date.to_s
13
14
  s.summary = "Workbook is a datastructure to contain books of tables (an anlogy used in e.g. Excel)"
14
15
  s.description = "Workbook contains workbooks, as in a table, contains rows, contains cells, reads/writes excel, ods and csv and tab separated files, and offers basic diffing and sorting capabilities."
15
16
  s.authors = ["Maarten Brouwers"]
@@ -22,7 +23,9 @@ Gem::Specification.new do |s|
22
23
  s.add_dependency("rake", '~> 10.0')
23
24
  s.add_dependency("json", '~> 1.8')
24
25
  s.add_dependency("zip-zip", '~> 0.2') #actually a hack...
25
- s.add_dependency('rubyXL', '~> 3.3')
26
+ #s.add_dependency('rubyXL', '~> 3.3')
27
+ s.add_dependency('roo', '~> 1.13')
28
+ s.add_dependency('axlsx', '~> 2.0.1')
26
29
  if RUBY_VERSION < "1.9"
27
30
  s.add_dependency('nokogiri', "~> 1.5.10")
28
31
  else
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: workbook
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.9
4
+ version: 0.4.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maarten Brouwers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-04-05 00:00:00.000000000 Z
11
+ date: 2015-07-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-prof
@@ -123,19 +123,33 @@ dependencies:
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0.2'
125
125
  - !ruby/object:Gem::Dependency
126
- name: rubyXL
126
+ name: roo
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
129
  - - "~>"
130
130
  - !ruby/object:Gem::Version
131
- version: '3.3'
131
+ version: '1.13'
132
132
  type: :runtime
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
136
  - - "~>"
137
137
  - !ruby/object:Gem::Version
138
- version: '3.3'
138
+ version: '1.13'
139
+ - !ruby/object:Gem::Dependency
140
+ name: axlsx
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: 2.0.1
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: 2.0.1
139
153
  - !ruby/object:Gem::Dependency
140
154
  name: nokogiri
141
155
  requirement: !ruby/object:Gem::Requirement
@@ -219,6 +233,7 @@ files:
219
233
  - lib/workbook/format.rb
220
234
  - lib/workbook/generatetypes.rb
221
235
  - lib/workbook/modules/cache.rb
236
+ - lib/workbook/modules/cell.rb
222
237
  - lib/workbook/modules/diff_sort.rb
223
238
  - lib/workbook/modules/raw_objects_storage.rb
224
239
  - lib/workbook/modules/type_parser.rb
@@ -279,11 +294,11 @@ files:
279
294
  - test/artifacts/zip_in_xls.xls
280
295
  - test/helper.rb
281
296
  - test/test_book.rb
282
- - test/test_cell.rb
283
297
  - test/test_column.rb
284
298
  - test/test_format.rb
285
299
  - test/test_functional.rb
286
300
  - test/test_modules_cache.rb
301
+ - test/test_modules_cell.rb
287
302
  - test/test_modules_table_diff_sort.rb
288
303
  - test/test_modules_type_parser.rb
289
304
  - test/test_readers_csv_reader.rb
@@ -295,6 +310,7 @@ files:
295
310
  - test/test_sheet.rb
296
311
  - test/test_table.rb
297
312
  - test/test_template.rb
313
+ - test/test_types_date.rb
298
314
  - test/test_writers_html_writer.rb
299
315
  - test/test_writers_json_writer.rb
300
316
  - test/test_writers_xls_writer.rb
@@ -355,11 +371,11 @@ test_files:
355
371
  - test/artifacts/zip_in_xls.xls
356
372
  - test/helper.rb
357
373
  - test/test_book.rb
358
- - test/test_cell.rb
359
374
  - test/test_column.rb
360
375
  - test/test_format.rb
361
376
  - test/test_functional.rb
362
377
  - test/test_modules_cache.rb
378
+ - test/test_modules_cell.rb
363
379
  - test/test_modules_table_diff_sort.rb
364
380
  - test/test_modules_type_parser.rb
365
381
  - test/test_readers_csv_reader.rb
@@ -371,6 +387,7 @@ test_files:
371
387
  - test/test_sheet.rb
372
388
  - test/test_table.rb
373
389
  - test/test_template.rb
390
+ - test/test_types_date.rb
374
391
  - test/test_writers_html_writer.rb
375
392
  - test/test_writers_json_writer.rb
376
393
  - test/test_writers_xls_writer.rb