workbook 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -1
- data/.travis.yml +6 -0
- data/Gemfile.lock +8 -4
- data/LICENSE.txt +22 -0
- data/README.md +4 -0
- data/Rakefile +3 -1
- data/doc/file.README.html +1 -1
- data/lib/workbook.rb +4 -2
- data/lib/workbook/book.rb +25 -3
- data/lib/workbook/cell.rb +9 -3
- data/lib/workbook/format.rb +1 -0
- data/lib/workbook/modules/raw_objects_storage.rb +2 -1
- data/lib/workbook/modules/table_diff_sort.rb +1 -0
- data/lib/workbook/modules/type_parser.rb +7 -3
- data/lib/workbook/readers/csv_reader.rb +16 -6
- data/lib/workbook/readers/txt_reader.rb +3 -3
- data/lib/workbook/readers/xls_reader.rb +2 -1
- data/lib/workbook/readers/xls_shared.rb +1 -0
- data/lib/workbook/readers/xlsx_reader.rb +4 -1
- data/lib/workbook/row.rb +1 -0
- data/lib/workbook/sheet.rb +21 -1
- data/lib/workbook/table.rb +28 -0
- data/lib/workbook/template.rb +2 -1
- data/lib/workbook/version.rb +4 -0
- data/lib/workbook/writers/csv_table_writer.rb +2 -1
- data/lib/workbook/writers/xls_writer.rb +2 -1
- data/test/artifacts/sheetduplication.xls +0 -0
- data/test/artifacts/simple_csv.csv +1 -1
- data/test/artifacts/simple_excel_csv.csv +1 -1
- data/test/helper.rb +1 -0
- data/test/test_book.rb +9 -1
- data/test/test_cell.rb +1 -0
- data/test/test_format.rb +1 -0
- data/test/test_functional.rb +1 -0
- data/test/test_modules_table_diff_sort.rb +1 -0
- data/test/test_modules_type_parser.rb +4 -2
- data/test/test_readers_csv_reader.rb +3 -1
- data/test/test_readers_txt_reader.rb +1 -0
- data/test/test_readers_xls_reader.rb +2 -1
- data/test/test_readers_xlsx_reader.rb +3 -2
- data/test/test_row.rb +1 -0
- data/test/test_sheet.rb +11 -0
- data/test/test_table.rb +30 -0
- data/test/test_template.rb +1 -0
- data/test/test_writers_xls_writer.rb +2 -1
- data/workbook.gemspec +12 -7
- metadata +66 -6
data/.gitignore
CHANGED
data/.travis.yml
ADDED
data/Gemfile.lock
CHANGED
@@ -1,20 +1,24 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
workbook (0.2.
|
5
|
-
|
4
|
+
workbook (0.2.2)
|
5
|
+
nokogiri
|
6
|
+
rake
|
6
7
|
rchardet (~> 1.3)
|
7
8
|
rubyXL
|
9
|
+
rubyzip
|
8
10
|
spreadsheet (>= 0.7.5)
|
9
11
|
|
10
12
|
GEM
|
11
13
|
remote: http://rubygems.org/
|
12
14
|
specs:
|
13
|
-
|
15
|
+
nokogiri (1.5.6)
|
16
|
+
rake (10.0.3)
|
14
17
|
rchardet (1.3.1)
|
15
18
|
ruby-ole (1.2.11.6)
|
16
19
|
rubyXL (1.2.10)
|
17
|
-
|
20
|
+
rubyzip (0.9.9)
|
21
|
+
spreadsheet (0.8.1)
|
18
22
|
ruby-ole (>= 1.0)
|
19
23
|
|
20
24
|
PLATFORMS
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Maarten Brouwers
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -116,6 +116,10 @@ Currently writing is limited to the following formats. Templating support is sti
|
|
116
116
|
|
117
117
|
In case you want to display the table in HTML, some conversion is offered to convert text/background properties to css-entities. Internally the hash storing style elements tries to map to CSS where possible.
|
118
118
|
|
119
|
+
## Compatibility
|
120
|
+
|
121
|
+
Workbook should be compatible with ruby 1.8.7 and 1.9.3. Check [Travis for Workbook's current build status](https://travis-ci.org/murb/workbook) [![Build Status](https://travis-ci.org/murb/workbook.png?branch=master)](https://travis-ci.org/murb/workbook).
|
122
|
+
|
119
123
|
## Alternatives
|
120
124
|
|
121
125
|
The [ruby toolbox lists plenty of alternatives](https://www.ruby-toolbox.com/search?utf8=%E2%9C%93&q=spreadsheet), that just didn't suit my needs.
|
data/Rakefile
CHANGED
data/doc/file.README.html
CHANGED
@@ -220,7 +220,7 @@ On my wishlist: In the future I hope to return the cell value directly, without
|
|
220
220
|
<ul>
|
221
221
|
<li><a href="https://github.com/zdavatz/spreadsheet">Spreadsheet</a> Used for reading and writing old style .xls files (Copyright (c) 2010 ywesee GmbH (mhatakeyama@ywesee.com, zdavatz@ywesee.com); GPL3 (License required for closed implementations))</li>
|
222
222
|
<li><a href="http://code.google.com/p/ruby-ole/">ruby-ole</a> Used in the Spreadsheet Gem (Copyright (c) 2007-2010 Charles Lowe; MIT)</li>
|
223
|
-
<li><a href="http://fastercsv.rubyforge.org/">FasterCSV</a> Used for reading CSV (comma separated text) and TXT (tab separated text) files (Copyright (c) James Edward Gray II; GPL2 & Ruby License)</li>
|
223
|
+
<li><a href="http://fastercsv.rubyforge.org/">FasterCSV</a> Used for reading CSV (comma separated text) and TXT (tab separated text) files (Copyright (c) James Edward Gray II; GPL2 & Ruby License) (not actively included for ruby 1.9 installs)</li>
|
224
224
|
<li><a href="http://rubyforge.org/projects/rchardet">rchardet</a> Used for detecting encoding in CSV and TXT importers (Copyright (c) JMHodges; LGPL)</li>
|
225
225
|
<li><a href="https://github.com/gilt/rubyXL">RubyXL</a> Used for reading the newer .xlsx files (Copyright (c) 2011 Vivek Bhagwat; MIT-Licensed)</li>
|
226
226
|
</ul>
|
data/lib/workbook.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
$KCODE="u" if RUBY_VERSION < "1.9"
|
2
3
|
require 'workbook/book'
|
3
4
|
require 'workbook/sheet'
|
4
5
|
require 'workbook/table'
|
@@ -6,9 +7,10 @@ require 'workbook/row'
|
|
6
7
|
require 'workbook/cell'
|
7
8
|
require 'workbook/format'
|
8
9
|
require 'workbook/template'
|
10
|
+
require 'workbook/version'
|
9
11
|
|
10
12
|
module Workbook
|
11
13
|
class << self
|
12
14
|
|
13
15
|
end
|
14
|
-
end
|
16
|
+
end
|
data/lib/workbook/book.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
1
2
|
require 'workbook/writers/xls_writer'
|
2
3
|
require 'workbook/readers/xls_reader'
|
3
4
|
require 'workbook/readers/xls_shared'
|
4
5
|
require 'workbook/readers/xlsx_reader'
|
5
6
|
require 'workbook/readers/csv_reader'
|
6
7
|
require 'workbook/readers/txt_reader'
|
7
|
-
require 'rchardet'
|
8
8
|
|
9
9
|
module Workbook
|
10
10
|
# The Book class is the container of sheets. It can be inialized by either the standard initalizer or the open method. The
|
@@ -104,11 +104,33 @@ module Workbook
|
|
104
104
|
extension = file_extension(filename) unless extension
|
105
105
|
f = File.open(filename,'r')
|
106
106
|
t = f.read
|
107
|
-
|
108
|
-
t = Iconv.conv("UTF-8//TRANSLIT//IGNORE",detected_encoding,t)
|
107
|
+
t = text_to_utf8(t)
|
109
108
|
send("load_#{extension}".to_sym,t)
|
110
109
|
end
|
111
110
|
|
111
|
+
|
112
|
+
# Helper method to convert text in a file to UTF-8
|
113
|
+
#
|
114
|
+
# @param [String] text a string to convert
|
115
|
+
def text_to_utf8 text
|
116
|
+
if RUBY_VERSION < '1.9'
|
117
|
+
require 'rchardet'
|
118
|
+
require 'iconv'
|
119
|
+
detected_encoding = CharDet.detect(text)
|
120
|
+
detected_encoding = detected_encoding['encoding']
|
121
|
+
text = Iconv.conv("UTF-8//TRANSLIT//IGNORE",detected_encoding,text)
|
122
|
+
text = text.gsub("\xEF\xBB\xBF", '') # removing the BOM...
|
123
|
+
else
|
124
|
+
unless text.valid_encoding? and text.encoding == "UTF-8"
|
125
|
+
# TODO: had some ruby 1.9 problems with rchardet ... but ideally it or a similar functionality will be reintroduced
|
126
|
+
source_encoding = text.valid_encoding? ? text.encoding : "US-ASCII"
|
127
|
+
text = text.encode('UTF-8', source_encoding, {:invalid=>:replace, :undef=>:replace, :replace=>""})
|
128
|
+
text = text.gsub("\u0000","") # TODO: this cleanup of nil values isn't supposed to be needed...
|
129
|
+
end
|
130
|
+
end
|
131
|
+
return text
|
132
|
+
end
|
133
|
+
|
112
134
|
# @param [String] filename The full filename, or path
|
113
135
|
#
|
114
136
|
# @return [String] The file extension
|
data/lib/workbook/cell.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# encoding: utf-8
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
2
|
|
3
3
|
require 'workbook/modules/type_parser'
|
4
4
|
|
@@ -108,8 +108,14 @@ module Workbook
|
|
108
108
|
v = v.gsub(s, rep)
|
109
109
|
end
|
110
110
|
end
|
111
|
-
|
112
|
-
|
111
|
+
if RUBY_VERSION < '1.9'
|
112
|
+
v = v.gsub(/[^\x00-\x7F]/n,'')
|
113
|
+
else
|
114
|
+
# See String#encode
|
115
|
+
encoding_options = {:invalid => :replace, :undef => :replace, :replace => ''}
|
116
|
+
v = v.encode(Encoding.find('ASCII'), encoding_options)
|
117
|
+
end
|
118
|
+
v = v.downcase.to_sym
|
113
119
|
end
|
114
120
|
v
|
115
121
|
end
|
data/lib/workbook/format.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
1
2
|
module Workbook
|
2
3
|
module Modules
|
3
4
|
# Adds type parsing capabilities to e.g. a Cell.
|
@@ -59,14 +60,14 @@ module Workbook
|
|
59
60
|
|
60
61
|
def string_nil_converter
|
61
62
|
proc do |v|
|
62
|
-
|
63
|
+
(v == "" ? nil : v)
|
63
64
|
end
|
64
65
|
end
|
65
66
|
|
66
67
|
def string_integer_converter
|
67
68
|
proc do |v|
|
68
69
|
if v.to_i.to_s == v
|
69
|
-
|
70
|
+
v.to_i
|
70
71
|
else
|
71
72
|
v
|
72
73
|
end
|
@@ -78,8 +79,11 @@ module Workbook
|
|
78
79
|
rv = v
|
79
80
|
starts_with_nr = v.chars.first.to_i.to_s == v.chars.first #it should at least start with a number...
|
80
81
|
no_spaced_dash = v.to_s.match(" - ") ? false : true
|
82
|
+
min_two_dashes = v.to_s.scan("-").count > 1 ? true : false
|
83
|
+
min_two_dashes = v.to_s.scan("/").count > 1 ? true : false if min_two_dashes == false
|
84
|
+
|
81
85
|
normal_date_length = v.to_s.length <= 25
|
82
|
-
if no_spaced_dash and starts_with_nr and normal_date_length
|
86
|
+
if no_spaced_dash and starts_with_nr and normal_date_length and min_two_dashes
|
83
87
|
begin
|
84
88
|
rv = (v.length > 10) ? DateTime.parse(v) : Date.parse(v)
|
85
89
|
rescue ArgumentError
|
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
2
|
|
3
3
|
module Workbook
|
4
4
|
module Readers
|
@@ -8,18 +8,28 @@ module Workbook
|
|
8
8
|
parse_csv csv
|
9
9
|
end
|
10
10
|
|
11
|
+
def csv_lib
|
12
|
+
if RUBY_VERSION < '1.9'
|
13
|
+
require 'faster_csv'
|
14
|
+
return FasterCSV
|
15
|
+
else
|
16
|
+
return CSV
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
11
20
|
def parse_csv csv_raw
|
12
21
|
custom_date_converter = Workbook::Cell.new.string_optimistic_date_converter
|
13
22
|
converters = [:float,:integer,:date,:date_time,custom_date_converter]
|
14
23
|
csv=nil
|
15
|
-
begin
|
16
|
-
|
17
|
-
|
24
|
+
#begin
|
25
|
+
csv = csv_lib.parse(csv_raw,{:converters=>converters})
|
26
|
+
|
27
|
+
#rescue
|
18
28
|
# we're going to have another shot at it...
|
19
|
-
|
29
|
+
#end
|
20
30
|
|
21
31
|
if csv==nil or csv[0].count == 1
|
22
|
-
csv_excel =
|
32
|
+
csv_excel = csv_lib.parse(csv_raw,{:converters=>converters,:col_sep=>';'})
|
23
33
|
csv = csv_excel if csv_excel[0].count > 1
|
24
34
|
end
|
25
35
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
2
|
module Workbook
|
3
3
|
module Readers
|
4
4
|
module TxtReader
|
@@ -9,9 +9,9 @@ module Workbook
|
|
9
9
|
|
10
10
|
def parse_txt csv_raw
|
11
11
|
csv = []
|
12
|
-
csv_raw.split("\n").each {|l| csv <<
|
12
|
+
csv_raw.split("\n").each {|l| csv << csv_lib.parse_line(l,{:col_sep=>"\t"});nil}
|
13
13
|
self[0]=Workbook::Sheet.new(csv,self,{:parse_cells_on_batch_creation=>true, :cell_parse_options=>{:detect_date=>true}}) unless sheet.has_contents?
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
17
|
-
end
|
17
|
+
end
|
@@ -1,8 +1,11 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
1
2
|
require 'rubyXL'
|
2
3
|
|
3
|
-
#
|
4
|
+
# Monkeypatching rubyXL, pull request submitted: https://github.com/gilt/rubyXL/pull/47
|
4
5
|
module RubyXL
|
5
6
|
class Workbook
|
7
|
+
|
8
|
+
# Improves upon date format detection
|
6
9
|
def is_date_format?(num_fmt)
|
7
10
|
num_fmt.downcase!
|
8
11
|
skip_chars = ['$', '-', '+', '/', '(', ')', ':', ' ']
|
data/lib/workbook/row.rb
CHANGED
data/lib/workbook/sheet.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
1
2
|
module Workbook
|
2
3
|
class Sheet < Array
|
3
4
|
# A Sheet is a container of tables
|
4
5
|
attr_accessor :book
|
6
|
+
attr_accessor :name
|
5
7
|
|
6
8
|
# Initialize a new sheet
|
7
9
|
#
|
@@ -44,5 +46,23 @@ module Workbook
|
|
44
46
|
return @book
|
45
47
|
end
|
46
48
|
end
|
49
|
+
|
50
|
+
# Removes all lines from this table
|
51
|
+
#
|
52
|
+
# @return [Workbook::Table] (self)
|
53
|
+
def delete_all
|
54
|
+
self.delete_if{|b| true}
|
55
|
+
end
|
56
|
+
|
57
|
+
# clones itself *and* the tables it contains
|
58
|
+
#
|
59
|
+
# @return [Workbook::Sheet] The cloned sheet
|
60
|
+
def clone
|
61
|
+
s = self
|
62
|
+
c = super
|
63
|
+
c.delete_all
|
64
|
+
s.each{|t| c << t.clone}
|
65
|
+
return c
|
66
|
+
end
|
47
67
|
end
|
48
|
-
end
|
68
|
+
end
|
data/lib/workbook/table.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
1
2
|
require 'workbook/modules/table_diff_sort'
|
2
3
|
require 'workbook/writers/csv_table_writer'
|
3
4
|
|
@@ -71,11 +72,18 @@ module Workbook
|
|
71
72
|
self.clone.remove_empty_lines!.count != 0
|
72
73
|
end
|
73
74
|
|
75
|
+
# Returns true if the row exists in this table
|
76
|
+
#
|
77
|
+
# @param [Workbook::Row] row to test for
|
78
|
+
# @return [Boolean] whether the row exist in this table
|
74
79
|
def contains_row? row
|
75
80
|
raise ArgumentError, "table should be a Workbook::Row (you passed a #{t.class})" unless row.is_a?(Workbook::Row)
|
76
81
|
self.collect{|r| r.object_id}.include? row.object_id
|
77
82
|
end
|
78
83
|
|
84
|
+
# Returns the sheet this table belongs to, creates a new sheet if none exists
|
85
|
+
#
|
86
|
+
# @return [Workbook::Sheet] The sheet this table belongs to
|
79
87
|
def sheet
|
80
88
|
if @sheet
|
81
89
|
return @sheet
|
@@ -85,5 +93,25 @@ module Workbook
|
|
85
93
|
end
|
86
94
|
end
|
87
95
|
|
96
|
+
# Removes all lines from this table
|
97
|
+
#
|
98
|
+
# @return [Workbook::Table] (self)
|
99
|
+
def delete_all
|
100
|
+
self.delete_if{|b| true}
|
101
|
+
end
|
102
|
+
|
103
|
+
# clones itself *and* the rows it contains
|
104
|
+
#
|
105
|
+
# @return [Workbook::Table] The cloned table
|
106
|
+
def clone
|
107
|
+
t = self
|
108
|
+
c = super
|
109
|
+
header_row_index = t.index(t.header)
|
110
|
+
c.delete_all
|
111
|
+
t.each{|r| c << r.clone}
|
112
|
+
c.header = c[header_row_index] if header_row_index
|
113
|
+
return c
|
114
|
+
end
|
115
|
+
|
88
116
|
end
|
89
117
|
end
|
data/lib/workbook/template.rb
CHANGED
Binary file
|
@@ -3,4 +3,4 @@ a;b;c
|
|
3
3
|
asdf;23;asd
|
4
4
|
23;asdf;sadf
|
5
5
|
12;23;12-02-2011 12:23
|
6
|
-
12 asdf;
|
6
|
+
12 asdf;6/12 ovk getekend terugontv.+>acq ter tekening. 13/12 ovk getekend terugontv.+>Fred ter tekening.;6/12
|
data/test/helper.rb
CHANGED
data/test/test_book.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
1
2
|
require File.join(File.dirname(__FILE__), 'helper')
|
2
3
|
|
3
4
|
class TestWorkbook < Test::Unit::TestCase
|
@@ -51,6 +52,13 @@ class TestWorkbook < Test::Unit::TestCase
|
|
51
52
|
assert_equal(b,b.first.table.sheet.book)
|
52
53
|
assert_equal(Workbook::Row, b.first.table.header.class)
|
53
54
|
assert_equal(b,b.first.table.header.table.sheet.book)
|
54
|
-
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_text_to_utf8
|
58
|
+
f = File.open("test/artifacts/excel_different_types.txt",'r')
|
59
|
+
t = f.read
|
60
|
+
w = Workbook::Book.new
|
61
|
+
t = w.text_to_utf8(t)
|
62
|
+
assert_equal("a\tb\tc\td", t.split(/(\n|\r)/).first)
|
55
63
|
end
|
56
64
|
end
|
data/test/test_cell.rb
CHANGED
data/test/test_format.rb
CHANGED
data/test/test_functional.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
1
2
|
require File.join(File.dirname(__FILE__), 'helper')
|
2
3
|
module Modules
|
3
4
|
class TestTypeParser < Test::Unit::TestCase
|
4
5
|
def examples
|
5
6
|
{"2312"=>2312,
|
6
|
-
|
7
|
+
"12-12-2012"=>Date.new(2012,12,12),
|
7
8
|
"12-12-2012 12:24"=>DateTime.new(2012,12,12,12,24),
|
8
9
|
"2012-12-12 12:24"=>DateTime.new(2012,12,12,12,24),
|
9
10
|
"2011-05-19T15_37_49 - 52349.xml"=>"2011-05-19T15_37_49 - 52349.xml",
|
@@ -15,7 +16,8 @@ module Modules
|
|
15
16
|
"12 bomenasdfasdfsadf"=>"12 bomenasdfasdfsadf",
|
16
17
|
""=>nil,
|
17
18
|
" "=>nil,
|
18
|
-
"mailto:sadf@asdf.as"=>"sadf@asdf.as"
|
19
|
+
"mailto:sadf@asdf.as"=>"sadf@asdf.as",
|
20
|
+
"012-3456789"=>"012-3456789"
|
19
21
|
}
|
20
22
|
end
|
21
23
|
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
1
2
|
require File.join(File.dirname(__FILE__), 'helper')
|
2
3
|
module Readers
|
3
4
|
class TestCsvWriter < Test::Unit::TestCase
|
@@ -24,6 +25,7 @@ module Readers
|
|
24
25
|
# asdf;23;asd
|
25
26
|
# 23;asdf;sadf
|
26
27
|
# 12;23;12-02-2011 12:23
|
28
|
+
# 12 asadf; 6/12 ovk getekend teru...; 6/12
|
27
29
|
#y w.sheet.table
|
28
30
|
assert_equal([:a,:b,:c],w.sheet.table.header.to_symbols)
|
29
31
|
assert_equal(23,w.sheet.table[2][:b].value)
|
@@ -31,7 +33,7 @@ module Readers
|
|
31
33
|
assert_equal(Date.new(2001,1,1),w.sheet.table[1][:a].value)
|
32
34
|
assert_equal(DateTime.new(2011,2,12,12,23),w.sheet.table[4][:c].value)
|
33
35
|
assert_equal("6/12 ovk getekend terugontv.+>acq ter tekening. 13/12 ovk getekend terugontv.+>Fred ter tekening.", w.sheet.table[5][:b].value)
|
34
|
-
assert_equal(
|
36
|
+
assert_equal("6/12",w.sheet.table[5][:c].value)
|
35
37
|
end
|
36
38
|
def test_excel_standardized_open
|
37
39
|
w = Workbook::Book.new
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
1
2
|
require File.join(File.dirname(__FILE__), 'helper')
|
2
3
|
module Readers
|
3
4
|
class TestXlsxWriter < Test::Unit::TestCase
|
@@ -21,8 +22,8 @@ module Readers
|
|
21
22
|
assert_equal("Callnr.",w.sheet.table[0][:callnr].value)
|
22
23
|
assert_equal("2475617.00",w.sheet.table[3][:callnr].value)
|
23
24
|
assert_equal("2012-12-03T12:30:00+00:00",w.sheet.table[7][:datum_gemeld].value.to_s)
|
24
|
-
assert_equal("2012-12-03T09:
|
25
|
+
assert_equal("2012-12-03T09:4",w.sheet.table[6][:datum_gemeld].value.to_s[0..14])
|
25
26
|
end
|
26
27
|
|
27
28
|
end
|
28
|
-
end
|
29
|
+
end
|
data/test/test_row.rb
CHANGED
data/test/test_sheet.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
1
2
|
require File.join(File.dirname(__FILE__), 'helper')
|
2
3
|
|
3
4
|
class TestWorkbook < Test::Unit::TestCase
|
@@ -30,5 +31,15 @@ class TestWorkbook < Test::Unit::TestCase
|
|
30
31
|
assert_equal(s, b.sheet)
|
31
32
|
assert_equal(s.book.sheet, b.sheet.table.sheet)
|
32
33
|
end
|
34
|
+
|
35
|
+
def test_clone
|
36
|
+
w = Workbook::Book.new [["a","b"],[1,2],[3,4]]
|
37
|
+
s = w.sheet
|
38
|
+
assert_equal(3,s.table[2][:a])
|
39
|
+
s2 = s.clone
|
40
|
+
s2.table[2][:a] = 5
|
41
|
+
assert_equal(3,s.table[2][:a])
|
42
|
+
assert_equal(5,s2.table[2][:a])
|
43
|
+
end
|
33
44
|
|
34
45
|
end
|
data/test/test_table.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
1
2
|
require File.join(File.dirname(__FILE__), 'helper')
|
2
3
|
|
3
4
|
class TestTable< Test::Unit::TestCase
|
@@ -58,5 +59,34 @@ class TestTable< Test::Unit::TestCase
|
|
58
59
|
assert_equal(t, s.table)
|
59
60
|
assert_equal(t.sheet, s)
|
60
61
|
end
|
62
|
+
|
63
|
+
def test_delete_all
|
64
|
+
w = Workbook::Book.new [["a","b"],[1,2],[3,4]]
|
65
|
+
t = w.sheet.table
|
66
|
+
t.delete_all
|
67
|
+
assert_equal(Workbook::Table,t.class)
|
68
|
+
assert_equal(0,t.count)
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_clone
|
72
|
+
w = Workbook::Book.new [["a","b"],[1,2],[3,4]]
|
73
|
+
t = w.sheet.table
|
74
|
+
assert_equal(3,t[2][:a])
|
75
|
+
t2 = t.clone
|
76
|
+
t2[2][:a] = 5
|
77
|
+
assert_equal(3,t[2][:a])
|
78
|
+
assert_equal(5,t2[2][:a])
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_clone_custom_header
|
82
|
+
w = Workbook::Book.new [[nil, nil],["a","b"],[1,2],[3,4]]
|
83
|
+
t = w.sheet.table
|
84
|
+
t.header=t[1]
|
85
|
+
assert_equal(3,t[3][:a])
|
86
|
+
t2 = t.clone
|
87
|
+
t2[3][:a] = 5
|
88
|
+
assert_equal(3,t[3][:a])
|
89
|
+
assert_equal(5,t2[3][:a])
|
90
|
+
end
|
61
91
|
|
62
92
|
end
|
data/test/test_template.rb
CHANGED
data/workbook.gemspec
CHANGED
@@ -1,23 +1,28 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
|
3
|
-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
require "workbook/version"
|
4
6
|
|
5
7
|
Gem::Specification.new do |s|
|
6
8
|
s.name = 'workbook'
|
7
9
|
s.rubyforge_project = 'workbook'
|
8
|
-
s.version =
|
10
|
+
s.version = Workbook::VERSION
|
9
11
|
s.date = '2013-01-10'
|
10
12
|
s.summary = "Workbook is a datastructure to contain books of tables (an anlogy used in e.g. Excel)"
|
11
13
|
s.description = "Workbook contains workbooks, as in a table, contains rows, contains cells, reads/writes excels and csv's and tab separated, and offers basic diffing and sorting capabilities."
|
12
14
|
s.authors = ["Maarten Brouwers"]
|
13
15
|
s.add_dependency('spreadsheet', '>= 0.7.5')
|
14
|
-
s.add_dependency('fastercsv')
|
16
|
+
s.add_dependency('fastercsv') if RUBY_VERSION < "1.9"
|
15
17
|
s.add_dependency("rchardet", "~> 1.3")
|
18
|
+
s.add_dependency("rake")
|
16
19
|
s.add_dependency('rubyXL')
|
20
|
+
s.add_dependency('nokogiri')
|
21
|
+
s.add_dependency('rubyzip')
|
17
22
|
s.platform = Gem::Platform::RUBY
|
18
|
-
s.files = `git ls-files`.split(
|
19
|
-
s.test_files =
|
20
|
-
s.executables =
|
23
|
+
s.files = `git ls-files`.split($/)
|
24
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
25
|
+
s.executables = s.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
21
26
|
s.require_paths = ["lib"]
|
22
27
|
s.email = ['gem@murb.nl']
|
23
28
|
s.homepage =
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: workbook
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 19
|
5
|
+
prerelease:
|
5
6
|
segments:
|
6
7
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
8
|
+
- 3
|
9
|
+
- 0
|
10
|
+
version: 0.3.0
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Maarten Brouwers
|
@@ -21,9 +22,11 @@ dependencies:
|
|
21
22
|
name: spreadsheet
|
22
23
|
prerelease: false
|
23
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
24
26
|
requirements:
|
25
27
|
- - ">="
|
26
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 9
|
27
30
|
segments:
|
28
31
|
- 0
|
29
32
|
- 7
|
@@ -35,9 +38,11 @@ dependencies:
|
|
35
38
|
name: fastercsv
|
36
39
|
prerelease: false
|
37
40
|
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
38
42
|
requirements:
|
39
43
|
- - ">="
|
40
44
|
- !ruby/object:Gem::Version
|
45
|
+
hash: 3
|
41
46
|
segments:
|
42
47
|
- 0
|
43
48
|
version: "0"
|
@@ -47,9 +52,11 @@ dependencies:
|
|
47
52
|
name: rchardet
|
48
53
|
prerelease: false
|
49
54
|
requirement: &id003 !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
50
56
|
requirements:
|
51
57
|
- - ~>
|
52
58
|
- !ruby/object:Gem::Version
|
59
|
+
hash: 9
|
53
60
|
segments:
|
54
61
|
- 1
|
55
62
|
- 3
|
@@ -57,17 +64,61 @@ dependencies:
|
|
57
64
|
type: :runtime
|
58
65
|
version_requirements: *id003
|
59
66
|
- !ruby/object:Gem::Dependency
|
60
|
-
name:
|
67
|
+
name: rake
|
61
68
|
prerelease: false
|
62
69
|
requirement: &id004 !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
63
71
|
requirements:
|
64
72
|
- - ">="
|
65
73
|
- !ruby/object:Gem::Version
|
74
|
+
hash: 3
|
66
75
|
segments:
|
67
76
|
- 0
|
68
77
|
version: "0"
|
69
78
|
type: :runtime
|
70
79
|
version_requirements: *id004
|
80
|
+
- !ruby/object:Gem::Dependency
|
81
|
+
name: rubyXL
|
82
|
+
prerelease: false
|
83
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
hash: 3
|
89
|
+
segments:
|
90
|
+
- 0
|
91
|
+
version: "0"
|
92
|
+
type: :runtime
|
93
|
+
version_requirements: *id005
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: nokogiri
|
96
|
+
prerelease: false
|
97
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
98
|
+
none: false
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
hash: 3
|
103
|
+
segments:
|
104
|
+
- 0
|
105
|
+
version: "0"
|
106
|
+
type: :runtime
|
107
|
+
version_requirements: *id006
|
108
|
+
- !ruby/object:Gem::Dependency
|
109
|
+
name: rubyzip
|
110
|
+
prerelease: false
|
111
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
112
|
+
none: false
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
hash: 3
|
117
|
+
segments:
|
118
|
+
- 0
|
119
|
+
version: "0"
|
120
|
+
type: :runtime
|
121
|
+
version_requirements: *id007
|
71
122
|
description: Workbook contains workbooks, as in a table, contains rows, contains cells, reads/writes excels and csv's and tab separated, and offers basic diffing and sorting capabilities.
|
72
123
|
email:
|
73
124
|
- gem@murb.nl
|
@@ -79,12 +130,14 @@ extra_rdoc_files: []
|
|
79
130
|
|
80
131
|
files:
|
81
132
|
- .gitignore
|
133
|
+
- .travis.yml
|
82
134
|
- .yardoc/checksums
|
83
135
|
- .yardoc/object_types
|
84
136
|
- .yardoc/objects/root.dat
|
85
137
|
- .yardoc/proxy_types
|
86
138
|
- Gemfile
|
87
139
|
- Gemfile.lock
|
140
|
+
- LICENSE.txt
|
88
141
|
- README.md
|
89
142
|
- Rakefile
|
90
143
|
- doc/RubyXL.html
|
@@ -141,6 +194,7 @@ files:
|
|
141
194
|
- lib/workbook/sheet.rb
|
142
195
|
- lib/workbook/table.rb
|
143
196
|
- lib/workbook/template.rb
|
197
|
+
- lib/workbook/version.rb
|
144
198
|
- lib/workbook/writers/csv_table_writer.rb
|
145
199
|
- lib/workbook/writers/xls_writer.rb
|
146
200
|
- test/artifacts/book_with_tabs_and_colours.xls
|
@@ -151,6 +205,7 @@ files:
|
|
151
205
|
- test/artifacts/excel_different_types.xls
|
152
206
|
- test/artifacts/excel_different_types.xlsx
|
153
207
|
- test/artifacts/native_xlsx.xlsx
|
208
|
+
- test/artifacts/sheetduplication.xls
|
154
209
|
- test/artifacts/simple_csv.csv
|
155
210
|
- test/artifacts/simple_excel_csv.csv
|
156
211
|
- test/artifacts/simple_sheet.xls
|
@@ -184,23 +239,27 @@ rdoc_options: []
|
|
184
239
|
require_paths:
|
185
240
|
- lib
|
186
241
|
required_ruby_version: !ruby/object:Gem::Requirement
|
242
|
+
none: false
|
187
243
|
requirements:
|
188
244
|
- - ">="
|
189
245
|
- !ruby/object:Gem::Version
|
246
|
+
hash: 3
|
190
247
|
segments:
|
191
248
|
- 0
|
192
249
|
version: "0"
|
193
250
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
251
|
+
none: false
|
194
252
|
requirements:
|
195
253
|
- - ">="
|
196
254
|
- !ruby/object:Gem::Version
|
255
|
+
hash: 3
|
197
256
|
segments:
|
198
257
|
- 0
|
199
258
|
version: "0"
|
200
259
|
requirements: []
|
201
260
|
|
202
261
|
rubyforge_project: workbook
|
203
|
-
rubygems_version: 1.
|
262
|
+
rubygems_version: 1.6.2
|
204
263
|
signing_key:
|
205
264
|
specification_version: 3
|
206
265
|
summary: Workbook is a datastructure to contain books of tables (an anlogy used in e.g. Excel)
|
@@ -213,6 +272,7 @@ test_files:
|
|
213
272
|
- test/artifacts/excel_different_types.xls
|
214
273
|
- test/artifacts/excel_different_types.xlsx
|
215
274
|
- test/artifacts/native_xlsx.xlsx
|
275
|
+
- test/artifacts/sheetduplication.xls
|
216
276
|
- test/artifacts/simple_csv.csv
|
217
277
|
- test/artifacts/simple_excel_csv.csv
|
218
278
|
- test/artifacts/simple_sheet.xls
|