roo 1.13.2 → 2.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (216) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +17 -0
  3. data/.github/ISSUE_TEMPLATE +10 -0
  4. data/.gitignore +11 -0
  5. data/.simplecov +4 -0
  6. data/.travis.yml +17 -0
  7. data/CHANGELOG.md +626 -0
  8. data/Gemfile +17 -12
  9. data/Gemfile_ruby2 +30 -0
  10. data/Guardfile +23 -0
  11. data/LICENSE +3 -1
  12. data/README.md +285 -0
  13. data/Rakefile +23 -23
  14. data/examples/roo_soap_client.rb +28 -31
  15. data/examples/roo_soap_server.rb +4 -6
  16. data/examples/write_me.rb +9 -10
  17. data/lib/roo/base.rb +298 -495
  18. data/lib/roo/constants.rb +5 -0
  19. data/lib/roo/csv.rb +127 -113
  20. data/lib/roo/errors.rb +11 -0
  21. data/lib/roo/excelx/cell/base.rb +94 -0
  22. data/lib/roo/excelx/cell/boolean.rb +27 -0
  23. data/lib/roo/excelx/cell/date.rb +28 -0
  24. data/lib/roo/excelx/cell/datetime.rb +111 -0
  25. data/lib/roo/excelx/cell/empty.rb +19 -0
  26. data/lib/roo/excelx/cell/number.rb +87 -0
  27. data/lib/roo/excelx/cell/string.rb +19 -0
  28. data/lib/roo/excelx/cell/time.rb +43 -0
  29. data/lib/roo/excelx/cell.rb +106 -0
  30. data/lib/roo/excelx/comments.rb +55 -0
  31. data/lib/roo/excelx/coordinate.rb +12 -0
  32. data/lib/roo/excelx/extractor.rb +21 -0
  33. data/lib/roo/excelx/format.rb +64 -0
  34. data/lib/roo/excelx/relationships.rb +25 -0
  35. data/lib/roo/excelx/shared.rb +32 -0
  36. data/lib/roo/excelx/shared_strings.rb +157 -0
  37. data/lib/roo/excelx/sheet.rb +112 -0
  38. data/lib/roo/excelx/sheet_doc.rb +211 -0
  39. data/lib/roo/excelx/styles.rb +64 -0
  40. data/lib/roo/excelx/workbook.rb +59 -0
  41. data/lib/roo/excelx.rb +376 -602
  42. data/lib/roo/font.rb +17 -0
  43. data/lib/roo/formatters/base.rb +15 -0
  44. data/lib/roo/formatters/csv.rb +84 -0
  45. data/lib/roo/formatters/matrix.rb +23 -0
  46. data/lib/roo/formatters/xml.rb +31 -0
  47. data/lib/roo/formatters/yaml.rb +40 -0
  48. data/lib/roo/libre_office.rb +4 -0
  49. data/lib/roo/link.rb +34 -0
  50. data/lib/roo/open_office.rb +626 -0
  51. data/lib/roo/spreadsheet.rb +22 -23
  52. data/lib/roo/tempdir.rb +21 -0
  53. data/lib/roo/utils.rb +78 -0
  54. data/lib/roo/version.rb +3 -0
  55. data/lib/roo.rb +23 -24
  56. data/roo.gemspec +21 -204
  57. data/spec/helpers.rb +5 -0
  58. data/spec/lib/roo/base_spec.rb +229 -3
  59. data/spec/lib/roo/csv_spec.rb +38 -11
  60. data/spec/lib/roo/excelx/format_spec.rb +7 -6
  61. data/spec/lib/roo/excelx_spec.rb +510 -11
  62. data/spec/lib/roo/libreoffice_spec.rb +16 -6
  63. data/spec/lib/roo/openoffice_spec.rb +30 -8
  64. data/spec/lib/roo/spreadsheet_spec.rb +60 -12
  65. data/spec/lib/roo/utils_spec.rb +106 -0
  66. data/spec/spec_helper.rb +7 -6
  67. data/test/all_ss.rb +12 -11
  68. data/test/excelx/cell/test_base.rb +63 -0
  69. data/test/excelx/cell/test_boolean.rb +36 -0
  70. data/test/excelx/cell/test_date.rb +38 -0
  71. data/test/excelx/cell/test_datetime.rb +45 -0
  72. data/test/excelx/cell/test_empty.rb +7 -0
  73. data/test/excelx/cell/test_number.rb +74 -0
  74. data/test/excelx/cell/test_string.rb +28 -0
  75. data/test/excelx/cell/test_time.rb +30 -0
  76. data/test/formatters/test_csv.rb +119 -0
  77. data/test/formatters/test_matrix.rb +76 -0
  78. data/test/formatters/test_xml.rb +74 -0
  79. data/test/formatters/test_yaml.rb +20 -0
  80. data/test/roo/test_csv.rb +52 -0
  81. data/test/roo/test_excelx.rb +186 -0
  82. data/test/roo/test_libre_office.rb +9 -0
  83. data/test/roo/test_open_office.rb +126 -0
  84. data/test/test_helper.rb +73 -53
  85. data/test/test_roo.rb +1211 -2292
  86. metadata +119 -298
  87. data/CHANGELOG +0 -417
  88. data/Gemfile.lock +0 -78
  89. data/README.markdown +0 -126
  90. data/VERSION +0 -1
  91. data/lib/roo/excel.rb +0 -355
  92. data/lib/roo/excel2003xml.rb +0 -300
  93. data/lib/roo/google.rb +0 -292
  94. data/lib/roo/openoffice.rb +0 -496
  95. data/lib/roo/roo_rails_helper.rb +0 -83
  96. data/lib/roo/worksheet.rb +0 -18
  97. data/scripts/txt2html +0 -67
  98. data/spec/lib/roo/excel2003xml_spec.rb +0 -15
  99. data/spec/lib/roo/excel_spec.rb +0 -17
  100. data/spec/lib/roo/google_spec.rb +0 -64
  101. data/test/files/1900_base.xls +0 -0
  102. data/test/files/1900_base.xlsx +0 -0
  103. data/test/files/1904_base.xls +0 -0
  104. data/test/files/1904_base.xlsx +0 -0
  105. data/test/files/Bibelbund.csv +0 -3741
  106. data/test/files/Bibelbund.ods +0 -0
  107. data/test/files/Bibelbund.xls +0 -0
  108. data/test/files/Bibelbund.xlsx +0 -0
  109. data/test/files/Bibelbund.xml +0 -62518
  110. data/test/files/Bibelbund1.ods +0 -0
  111. data/test/files/Pfand_from_windows_phone.xlsx +0 -0
  112. data/test/files/bad_excel_date.xls +0 -0
  113. data/test/files/bbu.ods +0 -0
  114. data/test/files/bbu.xls +0 -0
  115. data/test/files/bbu.xlsx +0 -0
  116. data/test/files/bbu.xml +0 -152
  117. data/test/files/bode-v1.ods.zip +0 -0
  118. data/test/files/bode-v1.xls.zip +0 -0
  119. data/test/files/boolean.csv +0 -2
  120. data/test/files/boolean.ods +0 -0
  121. data/test/files/boolean.xls +0 -0
  122. data/test/files/boolean.xlsx +0 -0
  123. data/test/files/boolean.xml +0 -112
  124. data/test/files/borders.ods +0 -0
  125. data/test/files/borders.xls +0 -0
  126. data/test/files/borders.xlsx +0 -0
  127. data/test/files/borders.xml +0 -144
  128. data/test/files/bug-numbered-sheet-names.xlsx +0 -0
  129. data/test/files/bug-row-column-fixnum-float.xls +0 -0
  130. data/test/files/bug-row-column-fixnum-float.xml +0 -127
  131. data/test/files/comments.ods +0 -0
  132. data/test/files/comments.xls +0 -0
  133. data/test/files/comments.xlsx +0 -0
  134. data/test/files/csvtypes.csv +0 -1
  135. data/test/files/datetime.ods +0 -0
  136. data/test/files/datetime.xls +0 -0
  137. data/test/files/datetime.xlsx +0 -0
  138. data/test/files/datetime.xml +0 -142
  139. data/test/files/datetime_floatconv.xls +0 -0
  140. data/test/files/datetime_floatconv.xml +0 -148
  141. data/test/files/dreimalvier.ods +0 -0
  142. data/test/files/emptysheets.ods +0 -0
  143. data/test/files/emptysheets.xls +0 -0
  144. data/test/files/emptysheets.xlsx +0 -0
  145. data/test/files/emptysheets.xml +0 -105
  146. data/test/files/excel2003.xml +0 -21140
  147. data/test/files/false_encoding.xls +0 -0
  148. data/test/files/false_encoding.xml +0 -132
  149. data/test/files/file_item_error.xlsx +0 -0
  150. data/test/files/formula.ods +0 -0
  151. data/test/files/formula.xls +0 -0
  152. data/test/files/formula.xlsx +0 -0
  153. data/test/files/formula.xml +0 -134
  154. data/test/files/formula_parse_error.xls +0 -0
  155. data/test/files/formula_parse_error.xml +0 -1833
  156. data/test/files/formula_string_error.xlsx +0 -0
  157. data/test/files/html-escape.ods +0 -0
  158. data/test/files/link.xls +0 -0
  159. data/test/files/link.xlsx +0 -0
  160. data/test/files/matrix.ods +0 -0
  161. data/test/files/matrix.xls +0 -0
  162. data/test/files/named_cells.ods +0 -0
  163. data/test/files/named_cells.xls +0 -0
  164. data/test/files/named_cells.xlsx +0 -0
  165. data/test/files/no_spreadsheet_file.txt +0 -1
  166. data/test/files/numbers1.csv +0 -18
  167. data/test/files/numbers1.ods +0 -0
  168. data/test/files/numbers1.xls +0 -0
  169. data/test/files/numbers1.xlsx +0 -0
  170. data/test/files/numbers1.xml +0 -312
  171. data/test/files/numeric-link.xlsx +0 -0
  172. data/test/files/only_one_sheet.ods +0 -0
  173. data/test/files/only_one_sheet.xls +0 -0
  174. data/test/files/only_one_sheet.xlsx +0 -0
  175. data/test/files/only_one_sheet.xml +0 -67
  176. data/test/files/paragraph.ods +0 -0
  177. data/test/files/paragraph.xls +0 -0
  178. data/test/files/paragraph.xlsx +0 -0
  179. data/test/files/paragraph.xml +0 -127
  180. data/test/files/prova.xls +0 -0
  181. data/test/files/ric.ods +0 -0
  182. data/test/files/simple_spreadsheet.ods +0 -0
  183. data/test/files/simple_spreadsheet.xls +0 -0
  184. data/test/files/simple_spreadsheet.xlsx +0 -0
  185. data/test/files/simple_spreadsheet.xml +0 -225
  186. data/test/files/simple_spreadsheet_from_italo.ods +0 -0
  187. data/test/files/simple_spreadsheet_from_italo.xls +0 -0
  188. data/test/files/simple_spreadsheet_from_italo.xml +0 -242
  189. data/test/files/so_datetime.csv +0 -7
  190. data/test/files/style.ods +0 -0
  191. data/test/files/style.xls +0 -0
  192. data/test/files/style.xlsx +0 -0
  193. data/test/files/style.xml +0 -154
  194. data/test/files/time-test.csv +0 -2
  195. data/test/files/time-test.ods +0 -0
  196. data/test/files/time-test.xls +0 -0
  197. data/test/files/time-test.xlsx +0 -0
  198. data/test/files/time-test.xml +0 -131
  199. data/test/files/type_excel.ods +0 -0
  200. data/test/files/type_excel.xlsx +0 -0
  201. data/test/files/type_excelx.ods +0 -0
  202. data/test/files/type_excelx.xls +0 -0
  203. data/test/files/type_openoffice.xls +0 -0
  204. data/test/files/type_openoffice.xlsx +0 -0
  205. data/test/files/whitespace.ods +0 -0
  206. data/test/files/whitespace.xls +0 -0
  207. data/test/files/whitespace.xlsx +0 -0
  208. data/test/files/whitespace.xml +0 -184
  209. data/test/rm_sub_test.rb +0 -12
  210. data/test/rm_test.rb +0 -7
  211. data/test/test_generic_spreadsheet.rb +0 -259
  212. data/website/index.html +0 -385
  213. data/website/index.txt +0 -423
  214. data/website/javascripts/rounded_corners_lite.inc.js +0 -285
  215. data/website/stylesheets/screen.css +0 -130
  216. data/website/template.rhtml +0 -48
data/Gemfile_ruby2 ADDED
@@ -0,0 +1,30 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'nokogiri', "< 1.7.0"
6
+
7
+ group :test do
8
+ # additional testing libs
9
+ gem 'shoulda'
10
+ gem 'rspec', '>= 3.0.0'
11
+ gem 'simplecov', '>= 0.9.0', require: false
12
+ gem 'coveralls', require: false
13
+ gem "activesupport", "~> 4.2.0"
14
+ gem "tins", '~> 1.6.0'
15
+ gem "term-ansicolor", "~> 1.3.2"
16
+ gem "minitest-reporters"
17
+ end
18
+
19
+ group :local_development do
20
+ gem "listen", "~> 3.0.6"
21
+ gem 'terminal-notifier-guard', require: false if RUBY_PLATFORM.downcase.include?('darwin')
22
+ gem 'guard-rspec', '>= 4.3.1', require: false
23
+ gem 'guard-minitest', require: false
24
+ gem 'guard-bundler', require: false
25
+ gem 'guard-preek', require: false
26
+ gem 'guard-rubocop', require: false
27
+ gem 'guard-reek', github: 'pericles/guard-reek', require: false
28
+ gem 'rb-readline'
29
+ gem 'pry'
30
+ end
data/Guardfile ADDED
@@ -0,0 +1,23 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard :minitest, test_folders: ['test'] do
5
+ watch(%r{^test/(.*)\/?test_(.*)\.rb$})
6
+ watch(%r{^lib/(.*/)?([^/]+)\.rb$}) { |m| "test/#{m[1].to_s.sub('roo/', '')}test_#{m[2]}.rb" }
7
+ watch(%r{^test/test_helper\.rb$}) { 'test' }
8
+ end
9
+
10
+ # Note: The cmd option is now required due to the increasing number of ways
11
+ # rspec may be run, below are examples of the most common uses.
12
+ # * bundler: 'bundle exec rspec'
13
+ # * bundler binstubs: 'bin/rspec'
14
+ # * spring: 'bin/rsspec' (This will use spring if running and you have
15
+ # installed the spring binstubs per the docs)
16
+ # * zeus: 'zeus rspec' (requires the server to be started separetly)
17
+ # * 'just' rspec: 'rspec'
18
+ guard :rspec, cmd: 'bundle exec rspec' do
19
+ watch(%r{^spec/.+_spec\.rb$})
20
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
21
+ watch('spec/spec_helper.rb') { "spec" }
22
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
23
+ end
data/LICENSE CHANGED
@@ -1,4 +1,6 @@
1
- Copyright (c) 2008-2013 Thomas Preymesser, Ben Woosley
1
+ Copyright (c) 2008-2014 Thomas Preymesser, Ben Woosley
2
+
3
+ MIT License
2
4
 
3
5
  Permission is hereby granted, free of charge, to any person obtaining
4
6
  a copy of this software and associated documentation files (the
data/README.md ADDED
@@ -0,0 +1,285 @@
1
+ # Roo
2
+
3
+ [![Build Status](https://img.shields.io/travis/roo-rb/roo.svg?style=flat-square)](https://travis-ci.org/roo-rb/roo) [![Code Climate](https://img.shields.io/codeclimate/github/roo-rb/roo.svg?style=flat-square)](https://codeclimate.com/github/roo-rb/roo) [![Coverage Status](https://img.shields.io/coveralls/roo-rb/roo.svg?style=flat-square)](https://coveralls.io/r/roo-rb/roo) [![Gem Version](https://img.shields.io/gem/v/roo.svg?style=flat-square)](https://rubygems.org/gems/roo)
4
+
5
+ Roo implements read access for all common spreadsheet types. It can handle:
6
+ * Excel 2007 - 2013 formats (xlsx, xlsm)
7
+ * LibreOffice / OpenOffice.org formats (ods)
8
+ * CSV
9
+ * Excel 97, Excel 2002 XML, and Excel 2003 XML formats when using the [roo-xls](https://github.com/roo-rb/roo-xls) gem (xls, xml)
10
+ * Google spreadsheets with read/write access when using [roo-google](https://github.com/roo-rb/roo-google)
11
+
12
+ ## Installation
13
+
14
+ Install as a gem
15
+
16
+ $ gem install roo
17
+
18
+ Or add it to your Gemfile
19
+
20
+ ```ruby
21
+ gem "roo", "~> 2.6.0"
22
+ ```
23
+ ## Usage
24
+
25
+ Opening a spreadsheet
26
+
27
+ ```ruby
28
+ require 'roo'
29
+
30
+ xlsx = Roo::Spreadsheet.open('./new_prices.xlsx')
31
+ xlsx = Roo::Excelx.new("./new_prices.xlsx")
32
+
33
+ # Use the extension option if the extension is ambiguous.
34
+ xlsx = Roo::Spreadsheet.open('./rails_temp_upload', extension: :xlsx)
35
+
36
+ xlsx.info
37
+ # => Returns basic info about the spreadsheet file
38
+ ```
39
+
40
+ ``Roo::Spreadsheet.open`` can accept both paths and ``File`` instances.
41
+
42
+ ### Working with sheets
43
+
44
+ ```ruby
45
+ ods.sheets
46
+ # => ['Info', 'Sheet 2', 'Sheet 3'] # an Array of sheet names in the workbook
47
+
48
+ ods.sheet('Info').row(1)
49
+ ods.sheet(0).row(1)
50
+
51
+ # Set the last sheet as the default sheet.
52
+ ods.default_sheet = ods.sheets.last
53
+ ods.default_sheet = ods.sheets[2]
54
+ ods.default_sheet = 'Sheet 3'
55
+
56
+ # Iterate through each sheet
57
+ ods.each_with_pagename do |name, sheet|
58
+ p sheet.row(1)
59
+ end
60
+ ```
61
+
62
+ ### Accessing rows and columns
63
+
64
+ Roo uses Excel's numbering for rows, columns and cells, so `1` is the first index, not `0` as it is in an ``Array``
65
+
66
+ ```ruby
67
+ sheet.row(1)
68
+ # returns the first row of the spreadsheet.
69
+
70
+ sheet.column(1)
71
+ # returns the first column of the spreadsheet.
72
+ ```
73
+
74
+ Almost all methods have an optional argument `sheet`. If this parameter is omitted, the default_sheet will be used.
75
+
76
+ ```ruby
77
+ sheet.first_row(sheet.sheets[0])
78
+ # => 1 # the number of the first row
79
+ sheet.last_row
80
+ # => 42 # the number of the last row
81
+ sheet.first_column
82
+ # => 1 # the number of the first column
83
+ sheet.last_column
84
+ # => 10 # the number of the last column
85
+ ```
86
+
87
+ #### Accessing cells
88
+
89
+ You can access the top-left cell in the following ways
90
+
91
+ ```ruby
92
+ s.cell(1,1)
93
+ s.cell('A',1)
94
+ s.cell(1,'A')
95
+ s.a1
96
+
97
+ # Access the second sheet's top-left cell.
98
+ s.cell(1,'A',s.sheets[1])
99
+ ```
100
+
101
+ #### Querying a spreadsheet
102
+ Use ``each`` to iterate over each row.
103
+
104
+ If each is given a hash with the names of some columns, then each will generate a hash with the columns supplied for each row.
105
+
106
+ ```ruby
107
+ sheet.each(id: 'ID', name: 'FULL_NAME') do |hash|
108
+ puts hash.inspect
109
+ # => { id: 1, name: 'John Smith' }
110
+ end
111
+ ```
112
+
113
+ Use ``sheet.parse`` to return an array of rows. Column names can be a ``String`` or a ``Regexp``.
114
+
115
+ ```ruby
116
+ sheet.parse(id: /UPC|SKU/, qty: /ATS*\sATP\s*QTY\z/)
117
+ # => [{:id => 727880013358, :qty => 12}, ...]
118
+ ```
119
+
120
+ Use the ``:header_search`` option to locate the header row and assign the header names.
121
+
122
+ ```ruby
123
+ sheet.parse(header_search: [/UPC*SKU/,/ATS*\sATP\s*QTY\z/])
124
+ ```
125
+
126
+ Use the ``:clean`` option to strip out control characters and surrounding white space.
127
+
128
+ ```ruby
129
+ sheet.parse(clean: true)
130
+ ```
131
+
132
+ ### Exporting spreadsheets
133
+ Roo has the ability to export sheets using the following formats. It
134
+ will only export the ``default_sheet``.
135
+
136
+ ```ruby
137
+ sheet.to_csv
138
+ sheet.to_matrix
139
+ sheet.to_xml
140
+ sheet.to_yaml
141
+ ```
142
+
143
+ ### Excel (xlsx and xlsm) Support
144
+
145
+ Stream rows from an Excelx spreadsheet.
146
+
147
+ ```ruby
148
+ xlsx = Roo::Excelx.new("./test_data/test_small.xlsx")
149
+ xlsx.each_row_streaming do |row|
150
+ puts row.inspect # Array of Excelx::Cell objects
151
+ end
152
+ ```
153
+
154
+ By default blank cells will be excluded from the array. To keep them, use the option pad_cells = true. (They will be set to nil in the array)
155
+ ```ruby
156
+ xlsx.each_row_streaming(pad_cells: true) do |row|
157
+ puts row.inspect # Array of Excelx::Cell objects
158
+ end
159
+ ```
160
+
161
+ To stream only some of the rows, you can use the ```max_rows``` and ```offset```options.
162
+ ```ruby
163
+ xlsx.each_row_streaming(offset: 1) do |row| # Will exclude first (inevitably header) row
164
+ puts row.inspect # Array of Excelx::Cell objects
165
+ end
166
+ ```
167
+
168
+ ```ruby
169
+ xlsx.each_row_streaming(max_rows: 3) do |row| # Will yield 4 rows (it's automatically incremented by 1) after the supplied offset.
170
+ puts row.inspect # Array of Excelx::Cell objects
171
+ end
172
+ ```
173
+
174
+ Iterate over each row
175
+
176
+ ```ruby
177
+ xlsx.each_row do |row|
178
+ ...
179
+ end
180
+ ```
181
+
182
+ ``Roo::Excelx`` also provides these helpful methods.
183
+
184
+ ```ruby
185
+ xlsx.excelx_type(3, 'C')
186
+ # => :numeric_or_formula
187
+
188
+ xlsx.cell(3, 'C')
189
+ # => 600000383.0
190
+
191
+ xlsx.excelx_value(row,col)
192
+ # => '600000383'
193
+
194
+ xlsx.formatted_value(row,col)
195
+ # => '0600000383'
196
+ ```
197
+
198
+ ``Roo::Excelx`` can access celltype, comments, font information, formulas, hyperlinks and labels.
199
+
200
+ ```ruby
201
+ xlsx.comment(1,1, ods.sheets[-1])
202
+ xlsx.font(1,1).bold?
203
+ xlsx.formula('A', 2)
204
+ ```
205
+
206
+ ### OpenOffice / LibreOffice Support
207
+
208
+ Roo::OpenOffice has support for encrypted OpenOffice spreadsheets.
209
+
210
+ ```ruby
211
+ # Load an encrypted OpenOffice Spreadsheet
212
+ ods = Roo::OpenOffice.new("myspreadsheet.ods", password: "password")
213
+ ```
214
+
215
+ ``Roo::OpenOffice`` can access celltype, comments, font information, formulas and labels.
216
+
217
+ ```ruby
218
+ ods.celltype
219
+ # => :percentage
220
+
221
+ ods.comment(1,1, ods.sheets[-1])
222
+
223
+ ods.font(1,1).italic?
224
+ # => false
225
+
226
+ ods.formula('A', 2)
227
+ ```
228
+
229
+ ### CSV Support
230
+
231
+ ```ruby
232
+ # Load a CSV file
233
+ s = Roo::CSV.new("mycsv.csv")
234
+ ```
235
+
236
+ Because Roo uses the [standard CSV library](), you can use options available to that library to parse csv files. You can pass options using the ``csv_options`` key.
237
+
238
+ For instance, you can load tab-delimited files (``.tsv``), and you can use a particular encoding when opening the file.
239
+
240
+
241
+ ```ruby
242
+ # Load a tab-delimited csv
243
+ s = Roo::CSV.new("mytsv.tsv", csv_options: {col_sep: "\t"})
244
+
245
+ # Load a csv with an explicit encoding
246
+ s = Roo::CSV.new("mycsv.csv", csv_options: {encoding: Encoding::ISO_8859_1})
247
+ ```
248
+
249
+ ## Upgrading from Roo 1.13.x
250
+ If you use ``.xls`` or Google spreadsheets, you will need to install ``roo-xls`` or ``roo-google`` to continue using that functionality.
251
+
252
+ Roo's public methods have stayed relatively consistent between 1.13.x and 2.0.0, but please check the [Changelog](https://github.com/roo-rb/roo/blob/master/CHANGELOG.md) to better understand the changes made since 1.13.x.
253
+
254
+
255
+
256
+ ## Contributing
257
+ ### Features
258
+ 1. Fork it ( https://github.com/[my-github-username]/roo/fork )
259
+ 2. Install it (`bundle install --with local_development`)
260
+ 3. Create your feature branch (`git checkout -b my-new-feature`)
261
+ 4. Commit your changes (`git commit -am 'My new feature'`)
262
+ 5. Push to the branch (`git push origin my-new-feature`)
263
+ 6. Create a new Pull Request
264
+
265
+ ### Testing
266
+ Roo uses Minitest and RSpec. The best of both worlds! Run `bundle exec rake` to
267
+ run the tests/examples.
268
+
269
+ Roo also has a few tests that take a long time (5+ seconds). To run these, use
270
+ `LONG_RUN=true bundle exec rake`
271
+
272
+ When testing using Ruby 2.0 or 2.1, use this command:
273
+ `BUNDLE_GEMFILE=Gemfile_ruby2 bundle exec rake`
274
+
275
+ ### Issues
276
+
277
+ If you find an issue, please create a gist and refer to it in an issue ([sample gist](https://gist.github.com/stevendaniels/98a05849036e99bb8b3c)). Here are some instructions for creating such a gist.
278
+
279
+ 1. [Create a gist](https://gist.github.com) with code that creates the error.
280
+ 2. Clone the gist repo locally, add a stripped down version of the offending spreadsheet to the gist repo, and push the gist's changes master.
281
+ 3. Paste the gist url here.
282
+
283
+
284
+ ## License
285
+ [Roo uses an MIT License](https://github.com/roo-rb/roo/blob/master/LICENSE)
data/Rakefile CHANGED
@@ -1,23 +1,23 @@
1
- require 'jeweler'
2
-
3
- Jeweler::Tasks.new do |gem|
4
- # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
5
- gem.name = "roo"
6
- gem.summary = "Roo can access the contents of various spreadsheet files."
7
- gem.description = "Roo can access the contents of various spreadsheet files. It can handle\n* OpenOffice\n* Excel\n* Google spreadsheets\n* Excelx\n* LibreOffice\n* CSV"
8
- gem.email = "ruby.ruby.ruby.roo@gmail.com"
9
- gem.homepage = "http://github.com/Empact/roo"
10
- gem.authors = ['Thomas Preymesser', 'Hugh McGowan', 'Ben Woosley']
11
-
12
- gem.license = 'MIT'
13
- gem.required_ruby_version = '>= 1.9.0'
14
-
15
- gem.test_files = FileList["{spec,test}/**/*.*"]
16
- end
17
-
18
- require 'rake/testtask'
19
- Rake::TestTask.new do |t|
20
- t.libs << "test"
21
- t.test_files = FileList['test/test*.rb']
22
- t.verbose = true
23
- end
1
+ require 'bundler/gem_tasks'
2
+
3
+ require 'rake/testtask'
4
+ require 'rspec/core/rake_task'
5
+ require 'coveralls/rake/task'
6
+
7
+ # Test unit
8
+ Rake::TestTask.new do |t|
9
+ t.libs << 'test'
10
+ t.test_files = FileList['test/**/test*.rb']
11
+ t.verbose = true
12
+ end
13
+
14
+ # RSpec
15
+ RSpec::Core::RakeTask.new(:spec)
16
+
17
+ # Coveralls
18
+ Coveralls::RakeTask.new
19
+
20
+ default_task = [:test, :spec]
21
+ default_task << 'coveralls:push' if ENV['TRAVIS']
22
+
23
+ task default: default_task
@@ -1,38 +1,38 @@
1
1
  require 'soap/rpc/driver'
2
2
 
3
- def ferien_fuer_region(proxy, region, year=nil)
4
- proxy.first_row.upto(proxy.last_row) { |row|
5
- if proxy.cell(row, 2) == region
6
- jahr = proxy.cell(row,1).to_i
7
- if year == nil || jahr == year
8
- bis_datum = proxy.cell(row,5)
9
- if DateTime.now > bis_datum
10
- print '('
11
- end
12
- print jahr.to_s+" "
13
- print proxy.cell(row,2)+" "
14
- print proxy.cell(row,3)+" "
15
- print proxy.cell(row,4).to_s+" "
16
- print bis_datum.to_s+" "
17
- print (proxy.cell(row,6) || '')+" "
18
- if DateTime.now > bis_datum
19
- print ')'
20
- end
21
- puts
3
+ def ferien_fuer_region(proxy, region, year = nil)
4
+ proxy.first_row.upto(proxy.last_row) do |row|
5
+ if proxy.cell(row, 2) == region
6
+ jahr = proxy.cell(row, 1).to_i
7
+ if year.nil? || jahr == year
8
+ bis_datum = proxy.cell(row, 5)
9
+ if DateTime.now > bis_datum
10
+ print '('
22
11
  end
23
- end
24
- }
12
+ print jahr.to_s + ' '
13
+ print proxy.cell(row, 2) + ' '
14
+ print proxy.cell(row, 3) + ' '
15
+ print proxy.cell(row, 4).to_s + ' '
16
+ print bis_datum.to_s + ' '
17
+ print (proxy.cell(row, 6) || '') + ' '
18
+ if DateTime.now > bis_datum
19
+ print ')'
20
+ end
21
+ puts
22
+ end
23
+ end
25
24
  end
25
+ end
26
26
 
27
- proxy = SOAP::RPC::Driver.new("http://localhost:12321","spreadsheetserver")
28
- proxy.add_method('cell','row','col')
27
+ proxy = SOAP::RPC::Driver.new('http://localhost:12321', 'spreadsheetserver')
28
+ proxy.add_method('cell', 'row', 'col')
29
29
  proxy.add_method('officeversion')
30
30
  proxy.add_method('last_row')
31
31
  proxy.add_method('last_column')
32
32
  proxy.add_method('first_row')
33
33
  proxy.add_method('first_column')
34
34
  proxy.add_method('sheets')
35
- proxy.add_method('set_default_sheet','s')
35
+ proxy.add_method('set_default_sheet', 's')
36
36
  proxy.add_method('ferien_fuer_region', 'region')
37
37
 
38
38
  sheets = proxy.sheets
@@ -42,12 +42,9 @@ puts "first row: #{proxy.first_row}"
42
42
  puts "first column: #{proxy.first_column}"
43
43
  puts "last row: #{proxy.last_row}"
44
44
  puts "last column: #{proxy.last_column}"
45
- puts "cell: #{proxy.cell('C',8)}"
46
- puts "cell: #{proxy.cell('F',12)}"
45
+ puts "cell: #{proxy.cell('C', 8)}"
46
+ puts "cell: #{proxy.cell('F', 12)}"
47
47
  puts "officeversion: #{proxy.officeversion}"
48
- puts "Berlin:"
49
-
50
- ferien_fuer_region(proxy, "Berlin")
51
-
52
-
48
+ puts 'Berlin:'
53
49
 
50
+ ferien_fuer_region(proxy, 'Berlin')
@@ -1,11 +1,10 @@
1
1
  require 'roo'
2
2
  require 'soap/rpc/standaloneServer'
3
3
 
4
- NS = "spreadsheetserver" # name of your service = namespace
4
+ NS = 'spreadsheetserver' # name of your service = namespace
5
5
  class Server2 < SOAP::RPC::StandaloneServer
6
-
7
6
  def on_init
8
- spreadsheet = OpenOffice.new("./Ferien-de.ods")
7
+ spreadsheet = OpenOffice.new('./Ferien-de.ods')
9
8
  add_method(spreadsheet, 'cell', 'row', 'col')
10
9
  add_method(spreadsheet, 'officeversion')
11
10
  add_method(spreadsheet, 'first_row')
@@ -13,14 +12,13 @@ class Server2 < SOAP::RPC::StandaloneServer
13
12
  add_method(spreadsheet, 'first_column')
14
13
  add_method(spreadsheet, 'last_column')
15
14
  add_method(spreadsheet, 'sheets')
16
- #add_method(spreadsheet, 'default_sheet=', 's')
15
+ # add_method(spreadsheet, 'default_sheet=', 's')
17
16
  # method with '...=' did not work? alias method 'set_default_sheet' created
18
17
  add_method(spreadsheet, 'set_default_sheet', 's')
19
18
  end
20
-
21
19
  end
22
20
 
23
- PORT = 12321
21
+ PORT = 12_321
24
22
  puts "serving at port #{PORT}"
25
23
  svr = Server2.new('Roo', NS, '0.0.0.0', PORT)
26
24
 
data/examples/write_me.rb CHANGED
@@ -5,28 +5,27 @@ require 'roo'
5
5
  MAXTRIES = 1000
6
6
  print "what's your name? "
7
7
  my_name = gets.chomp
8
- print "where do you live? "
8
+ print 'where do you live? '
9
9
  my_location = gets.chomp
10
- print "your message? (if left blank, only your name and location will be inserted) "
10
+ print 'your message? (if left blank, only your name and location will be inserted) '
11
11
  my_message = gets.chomp
12
12
  spreadsheet = Google.new('ptu6bbahNZpY0N0RrxQbWdw')
13
13
  spreadsheet.default_sheet = 'Sheet1'
14
14
  success = false
15
15
  MAXTRIES.times do
16
- col = rand(10)+1
17
- row = rand(10)+1
18
- if spreadsheet.empty?(row,col)
16
+ col = rand(10) + 1
17
+ row = rand(10) + 1
18
+ if spreadsheet.empty?(row, col)
19
19
  if my_message.empty?
20
- text = Time.now.to_s+" "+"Greetings from #{my_name} (#{my_location})"
20
+ text = Time.now.to_s + ' ' + "Greetings from #{my_name} (#{my_location})"
21
21
  else
22
- text = Time.now.to_s+" "+"#{my_message} from #{my_name} (#{my_location})"
22
+ text = Time.now.to_s + ' ' + "#{my_message} from #{my_name} (#{my_location})"
23
23
  end
24
- spreadsheet.set_value(row,col,text)
24
+ spreadsheet.set_value(row, col, text)
25
25
  puts "message written to row #{row}, column #{col}"
26
26
  success = true
27
27
  break
28
28
  end
29
29
  puts "Row #{row}, column #{col} already occupied, trying again..."
30
30
  end
31
- puts "no empty cell found within #{MAXTRIES} tries" if !success
32
-
31
+ puts "no empty cell found within #{MAXTRIES} tries" unless success