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
@@ -1,496 +0,0 @@
1
- require 'date'
2
- require 'nokogiri'
3
- require 'cgi'
4
-
5
- class Roo::OpenOffice < Roo::Base
6
- class << self
7
- def extract_content(tmpdir, filename)
8
- Roo::ZipFile.open(filename) do |zip|
9
- process_zipfile(tmpdir, zip)
10
- end
11
- end
12
-
13
- def process_zipfile(tmpdir, zip, path='')
14
- if zip.file.file? path
15
- if path == "content.xml"
16
- open(File.join(tmpdir, 'roo_content.xml'),'wb') {|f|
17
- f << zip.read(path)
18
- }
19
- end
20
- else
21
- unless path.empty?
22
- path += '/'
23
- end
24
- zip.dir.foreach(path) do |filename|
25
- process_zipfile(tmpdir, zip, path+filename)
26
- end
27
- end
28
- end
29
- end
30
-
31
- # initialization and opening of a spreadsheet file
32
- # values for packed: :zip
33
- def initialize(filename, options={}, deprecated_file_warning=:error, deprecated_tmpdir_root=nil)
34
- if Hash === options
35
- packed = options[:packed]
36
- file_warning = options[:file_warning] || :error
37
- tmpdir_root = options[:tmpdir_root]
38
- else
39
- warn 'Supplying `packed`, `file_warning`, or `tmpdir_root` as separate arguments to `Roo::OpenOffice.new` is deprecated. Use an options hash instead.'
40
- packed = options
41
- file_warning = deprecated_file_warning
42
- tmpdir_root = deprecated_tmpdir_root
43
- end
44
-
45
- file_type_check(filename,'.ods','an Roo::OpenOffice', file_warning, packed)
46
- make_tmpdir(tmpdir_root) do |tmpdir|
47
- filename = download_uri(filename, tmpdir) if uri?(filename)
48
- filename = unzip(filename, tmpdir) if packed == :zip
49
- #TODO: @cells_read[:default] = false
50
- @filename = filename
51
- unless File.file?(@filename)
52
- raise IOError, "file #{@filename} does not exist"
53
- end
54
- self.class.extract_content(tmpdir, @filename)
55
- @doc = load_xml(File.join(tmpdir, "roo_content.xml"))
56
- end
57
- super(filename, options)
58
- @formula = Hash.new
59
- @style = Hash.new
60
- @style_defaults = Hash.new { |h,k| h[k] = [] }
61
- @style_definitions = Hash.new
62
- @comment = Hash.new
63
- @comments_read = Hash.new
64
- end
65
-
66
- def method_missing(m,*args)
67
- read_labels
68
- # is method name a label name
69
- if @label.has_key?(m.to_s)
70
- row,col = label(m.to_s)
71
- cell(row,col)
72
- else
73
- # call super for methods like #a1
74
- super
75
- end
76
- end
77
-
78
- # Returns the content of a spreadsheet-cell.
79
- # (1,1) is the upper left corner.
80
- # (1,1), (1,'A'), ('A',1), ('a',1) all refers to the
81
- # cell at the first line and first row.
82
- def cell(row, col, sheet=nil)
83
- sheet ||= @default_sheet
84
- read_cells(sheet)
85
- row,col = normalize(row,col)
86
- if celltype(row,col,sheet) == :date
87
- yyyy,mm,dd = @cell[sheet][[row,col]].to_s.split('-')
88
- return Date.new(yyyy.to_i,mm.to_i,dd.to_i)
89
- end
90
- @cell[sheet][[row,col]]
91
- end
92
-
93
- # Returns the formula at (row,col).
94
- # Returns nil if there is no formula.
95
- # The method #formula? checks if there is a formula.
96
- def formula(row,col,sheet=nil)
97
- sheet ||= @default_sheet
98
- read_cells(sheet)
99
- row,col = normalize(row,col)
100
- @formula[sheet][[row,col]]
101
- end
102
- alias_method :formula?, :formula
103
-
104
- # returns each formula in the selected sheet as an array of elements
105
- # [row, col, formula]
106
- def formulas(sheet=nil)
107
- sheet ||= @default_sheet
108
- read_cells(sheet)
109
- if @formula[sheet]
110
- @formula[sheet].each.collect do |elem|
111
- [elem[0][0], elem[0][1], elem[1]]
112
- end
113
- else
114
- []
115
- end
116
- end
117
-
118
- class Font
119
- attr_accessor :bold, :italic, :underline
120
-
121
- def bold?
122
- @bold == 'bold'
123
- end
124
-
125
- def italic?
126
- @italic == 'italic'
127
- end
128
-
129
- def underline?
130
- @underline != nil
131
- end
132
- end
133
-
134
- # Given a cell, return the cell's style
135
- def font(row, col, sheet=nil)
136
- sheet ||= @default_sheet
137
- read_cells(sheet)
138
- row,col = normalize(row,col)
139
- style_name = @style[sheet][[row,col]] || @style_defaults[sheet][col - 1] || 'Default'
140
- @style_definitions[style_name]
141
- end
142
-
143
- # returns the type of a cell:
144
- # * :float
145
- # * :string
146
- # * :date
147
- # * :percentage
148
- # * :formula
149
- # * :time
150
- # * :datetime
151
- def celltype(row,col,sheet=nil)
152
- sheet ||= @default_sheet
153
- read_cells(sheet)
154
- row,col = normalize(row,col)
155
- if @formula[sheet][[row,col]]
156
- return :formula
157
- else
158
- @cell_type[sheet][[row,col]]
159
- end
160
- end
161
-
162
- def sheets
163
- @doc.xpath("//*[local-name()='table']").map do |sheet|
164
- sheet.attributes["name"].value
165
- end
166
- end
167
-
168
- # version of the Roo::OpenOffice document
169
- # at 2007 this is always "1.0"
170
- def officeversion
171
- oo_version
172
- @officeversion
173
- end
174
-
175
- # shows the internal representation of all cells
176
- # mainly for debugging purposes
177
- def to_s(sheet=nil)
178
- sheet ||= @default_sheet
179
- read_cells(sheet)
180
- @cell[sheet].inspect
181
- end
182
-
183
- # returns the row,col values of the labelled cell
184
- # (nil,nil) if label is not defined
185
- def label(labelname)
186
- read_labels
187
- unless @label.size > 0
188
- return nil,nil,nil
189
- end
190
- if @label.has_key? labelname
191
- return @label[labelname][1].to_i,
192
- Roo::Base.letter_to_number(@label[labelname][2]),
193
- @label[labelname][0]
194
- else
195
- return nil,nil,nil
196
- end
197
- end
198
-
199
- # Returns an array which all labels. Each element is an array with
200
- # [labelname, [row,col,sheetname]]
201
- def labels(sheet=nil)
202
- read_labels
203
- @label.map do |label|
204
- [ label[0], # name
205
- [ label[1][1].to_i, # row
206
- Roo::Base.letter_to_number(label[1][2]), # column
207
- label[1][0], # sheet
208
- ] ]
209
- end
210
- end
211
-
212
- # returns the comment at (row/col)
213
- # nil if there is no comment
214
- def comment(row,col,sheet=nil)
215
- sheet ||= @default_sheet
216
- read_cells(sheet)
217
- row,col = normalize(row,col)
218
- return nil unless @comment[sheet]
219
- @comment[sheet][[row,col]]
220
- end
221
-
222
- # true, if there is a comment
223
- def comment?(row,col,sheet=nil)
224
- sheet ||= @default_sheet
225
- read_cells(sheet)
226
- row,col = normalize(row,col)
227
- comment(row,col) != nil
228
- end
229
-
230
-
231
- # returns each comment in the selected sheet as an array of elements
232
- # [row, col, comment]
233
- def comments(sheet=nil)
234
- sheet ||= @default_sheet
235
- read_comments(sheet) unless @comments_read[sheet]
236
- if @comment[sheet]
237
- @comment[sheet].each.collect do |elem|
238
- [elem[0][0],elem[0][1],elem[1]]
239
- end
240
- else
241
- []
242
- end
243
- end
244
-
245
- private
246
-
247
- # read the version of the OO-Version
248
- def oo_version
249
- @doc.xpath("//*[local-name()='document-content']").each do |office|
250
- @officeversion = attr(office,'version')
251
- end
252
- end
253
-
254
- # helper function to set the internal representation of cells
255
- def set_cell_values(sheet,x,y,i,v,value_type,formula,table_cell,str_v,style_name)
256
- key = [y,x+i]
257
- @cell_type[sheet] = {} unless @cell_type[sheet]
258
- @cell_type[sheet][key] = Roo::OpenOffice.oo_type_2_roo_type(value_type)
259
- @formula[sheet] = {} unless @formula[sheet]
260
- if formula
261
- ['of:', 'oooc:'].each do |prefix|
262
- if formula[0,prefix.length] == prefix
263
- formula = formula[prefix.length..-1]
264
- end
265
- end
266
- @formula[sheet][key] = formula
267
- end
268
- @cell[sheet] = {} unless @cell[sheet]
269
- @style[sheet] = {} unless @style[sheet]
270
- @style[sheet][key] = style_name
271
- case @cell_type[sheet][key]
272
- when :float
273
- @cell[sheet][key] = v.to_f
274
- when :string
275
- @cell[sheet][key] = str_v
276
- when :date
277
- #TODO: if table_cell.attributes['date-value'].size != "XXXX-XX-XX".size
278
- if attr(table_cell,'date-value').size != "XXXX-XX-XX".size
279
- #-- dann ist noch eine Uhrzeit vorhanden
280
- #-- "1961-11-21T12:17:18"
281
- @cell[sheet][key] = DateTime.parse(attr(table_cell,'date-value').to_s)
282
- @cell_type[sheet][key] = :datetime
283
- else
284
- @cell[sheet][key] = table_cell.attributes['date-value']
285
- end
286
- when :percentage
287
- @cell[sheet][key] = v.to_f
288
- when :time
289
- hms = v.split(':')
290
- @cell[sheet][key] = hms[0].to_i*3600 + hms[1].to_i*60 + hms[2].to_i
291
- else
292
- @cell[sheet][key] = v
293
- end
294
- end
295
-
296
- # read all cells in the selected sheet
297
- #--
298
- # the following construct means '4 blanks'
299
- # some content <text:s text:c="3"/>
300
- #++
301
- def read_cells(sheet=nil)
302
- sheet ||= @default_sheet
303
- validate_sheet!(sheet)
304
- return if @cells_read[sheet]
305
-
306
- sheet_found = false
307
- @doc.xpath("//*[local-name()='table']").each do |ws|
308
- if sheet == attr(ws,'name')
309
- sheet_found = true
310
- col = 1
311
- row = 1
312
- ws.children.each do |table_element|
313
- case table_element.name
314
- when 'table-column'
315
- @style_defaults[sheet] << table_element.attributes['default-cell-style-name']
316
- when 'table-row'
317
- if table_element.attributes['number-rows-repeated']
318
- skip_row = attr(table_element,'number-rows-repeated').to_s.to_i
319
- row = row + skip_row - 1
320
- end
321
- table_element.children.each do |cell|
322
- skip_col = attr(cell, 'number-columns-repeated')
323
- formula = attr(cell,'formula')
324
- value_type = attr(cell,'value-type')
325
- v = attr(cell,'value')
326
- style_name = attr(cell,'style-name')
327
- case value_type
328
- when 'string'
329
- str_v = ''
330
- # insert \n if there is more than one paragraph
331
- para_count = 0
332
- cell.children.each do |str|
333
- # begin comments
334
- =begin
335
- - <table:table-cell office:value-type="string">
336
- - <office:annotation office:display="true" draw:style-name="gr1" draw:text-style-name="P1" svg:width="1.1413in" svg:height="0.3902in" svg:x="2.0142in" svg:y="0in" draw:caption-point-x="-0.2402in" draw:caption-point-y="0.5661in">
337
- <dc:date>2011-09-20T00:00:00</dc:date>
338
- <text:p text:style-name="P1">Kommentar fuer B4</text:p>
339
- </office:annotation>
340
- <text:p>B4 (mit Kommentar)</text:p>
341
- </table:table-cell>
342
- =end
343
- if str.name == 'annotation'
344
- str.children.each do |annotation|
345
- if annotation.name == 'p'
346
- # @comment ist ein Hash mit Sheet als Key (wie bei @cell)
347
- # innerhalb eines Elements besteht ein Eintrag aus einem
348
- # weiteren Hash mit Key [row,col] und dem eigentlichen
349
- # Kommentartext als Inhalt
350
- @comment[sheet] = Hash.new unless @comment[sheet]
351
- key = [row,col]
352
- @comment[sheet][key] = annotation.text
353
- end
354
- end
355
- end
356
- # end comments
357
- if str.name == 'p'
358
- v = str.content
359
- str_v += "\n" if para_count > 0
360
- para_count += 1
361
- if str.children.size > 1
362
- str_v += children_to_string(str.children)
363
- else
364
- str.children.each do |child|
365
- str_v += child.content #.text
366
- end
367
- end
368
- str_v.gsub!(/&apos;/,"'") # special case not supported by unescapeHTML
369
- str_v = CGI.unescapeHTML(str_v)
370
- end # == 'p'
371
- end
372
- when 'time'
373
- cell.children.each do |str|
374
- if str.name == 'p'
375
- v = str.content
376
- end
377
- end
378
- when '', nil
379
- #
380
- when 'date'
381
- #
382
- when 'percentage'
383
- #
384
- when 'float'
385
- #
386
- when 'boolean'
387
- v = attr(cell,'boolean-value').to_s
388
- else
389
- # raise "unknown type #{value_type}"
390
- end
391
- if skip_col
392
- if v != nil or cell.attributes['date-value']
393
- 0.upto(skip_col.to_i-1) do |i|
394
- set_cell_values(sheet,col,row,i,v,value_type,formula,cell,str_v,style_name)
395
- end
396
- end
397
- col += (skip_col.to_i - 1)
398
- end # if skip
399
- set_cell_values(sheet,col,row,0,v,value_type,formula,cell,str_v,style_name)
400
- col += 1
401
- end
402
- row += 1
403
- col = 1
404
- end
405
- end
406
- end
407
- end
408
- @doc.xpath("//*[local-name()='automatic-styles']").each do |style|
409
- read_styles(style)
410
- end
411
- if !sheet_found
412
- raise RangeError
413
- end
414
- @cells_read[sheet] = true
415
- @comments_read[sheet] = true
416
- end
417
-
418
- # Only calls read_cells because Roo::Base calls read_comments
419
- # whereas the reading of comments is done in read_cells for Roo::OpenOffice-objects
420
- def read_comments(sheet=nil)
421
- read_cells(sheet)
422
- end
423
-
424
- def read_labels
425
- @label ||= Hash[@doc.xpath("//table:named-range").map do |ne|
426
- #-
427
- # $Sheet1.$C$5
428
- #+
429
- name = attr(ne,'name').to_s
430
- sheetname,coords = attr(ne,'cell-range-address').to_s.split('.$')
431
- col, row = coords.split('$')
432
- sheetname = sheetname[1..-1] if sheetname[0,1] == '$'
433
- [name, [sheetname,row,col]]
434
- end]
435
- end
436
-
437
- def read_styles(style_elements)
438
- @style_definitions['Default'] = Roo::OpenOffice::Font.new
439
- style_elements.each do |style|
440
- next unless style.name == 'style'
441
- style_name = attr(style,'name')
442
- style.each do |properties|
443
- font = Roo::OpenOffice::Font.new
444
- font.bold = attr(properties,'font-weight')
445
- font.italic = attr(properties,'font-style')
446
- font.underline = attr(properties,'text-underline-style')
447
- @style_definitions[style_name] = font
448
- end
449
- end
450
- end
451
-
452
- A_ROO_TYPE = {
453
- "float" => :float,
454
- "string" => :string,
455
- "date" => :date,
456
- "percentage" => :percentage,
457
- "time" => :time,
458
- }
459
-
460
- def self.oo_type_2_roo_type(ootype)
461
- return A_ROO_TYPE[ootype]
462
- end
463
-
464
- # helper method to convert compressed spaces and other elements within
465
- # an text into a string
466
- def children_to_string(children)
467
- result = ''
468
- children.each {|child|
469
- if child.text?
470
- result = result + child.content
471
- else
472
- if child.name == 's'
473
- compressed_spaces = child.attributes['c'].to_s.to_i
474
- # no explicit number means a count of 1:
475
- if compressed_spaces == 0
476
- compressed_spaces = 1
477
- end
478
- result = result + " "*compressed_spaces
479
- else
480
- result = result + child.content
481
- end
482
- end
483
- }
484
- result
485
- end
486
-
487
- def attr(node, attr_name)
488
- if node.attributes[attr_name]
489
- node.attributes[attr_name].value
490
- end
491
- end
492
- end # class
493
-
494
- # LibreOffice is just an alias for Roo::OpenOffice class
495
- class Roo::LibreOffice < Roo::OpenOffice
496
- end
@@ -1,83 +0,0 @@
1
- warn "Roo's roo_rails_helper, aka the spreadsheet view method is currently deprecated with no replacement. If you find it helpful, tell http://github.com/Empact or extract it yourself."
2
- def spreadsheet(spreadsheet, sheets, options={})
3
- @rspreadsheet = spreadsheet
4
- coordinates = true # default
5
- o=""
6
- if options[:coordinates] != nil
7
- o << ":coordinates uebergeben: #{options[:coordinates]}"
8
- coordinates = options[:coordinates]
9
- end
10
- if options[:bgcolor]
11
- bgcolor = options[:bgcolor]
12
- else
13
- bgcolor = false
14
- end
15
-
16
- sheets.each { |sheet|
17
- @rspreadsheet.default_sheet = sheet
18
- linenumber = @rspreadsheet.first_row(sheet)
19
- if options[:first_row]
20
- linenumber += (options[:first_row]-1)
21
- end
22
- o << '<table border="0" cellspacing="1" cellpadding="1">'
23
- if options[:first_row]
24
- first_row = options[:first_row]
25
- end
26
- if options[:last_row]
27
- last_row = options[:last_row]
28
- end
29
- if options[:first_column]
30
- first_column = options[:first_column]
31
- end
32
- if options[:last_column]
33
- last_column = options[:last_column]
34
- end
35
- first_row = @rspreadsheet.first_row(sheet) unless first_row
36
- last_row = @rspreadsheet.last_row(sheet) unless last_row
37
- first_column = @rspreadsheet.first_column(sheet) unless first_column
38
- last_column = @rspreadsheet.last_column(sheet) unless last_column
39
- if coordinates
40
- o << " <tr>"
41
- o << " <td>&nbsp;</td>"
42
- @rspreadsheet.first_column(sheet).upto(@rspreadsheet.last_column(sheet)) {|c|
43
- if c < first_column or c > last_column
44
- next
45
- end
46
- o << " <td>"
47
- o << " <b>#{Roo::Base.number_to_letter(c)}</b>"
48
- o << " </td>"
49
- }
50
- o << "</tr>"
51
- end
52
- @rspreadsheet.first_row.upto(@rspreadsheet.last_row) do |y|
53
- if first_row and (y < first_row or y > last_row)
54
- next
55
- end
56
- o << "<tr>"
57
- if coordinates
58
- o << "<td><b>#{linenumber.to_s}</b></td>"
59
- end
60
- linenumber += 1
61
- @rspreadsheet.first_column(sheet).upto(@rspreadsheet.last_column(sheet)) do |x|
62
- if x < first_column or x > last_column
63
- next
64
- end
65
- if bgcolor
66
- o << "<td bgcolor=\"#{bgcolor}\">"
67
- else
68
- o << '<td bgcolor="lightgreen">'
69
- end
70
- if @rspreadsheet.cell(y,x).to_s.empty?
71
- o << "&nbsp;"
72
- else
73
- o << "#{@rspreadsheet.cell(y,x)}"
74
- end
75
- o << "</td>"
76
- end
77
- o << "</tr>"
78
- end
79
- o << "</table>"
80
- } # each sheet
81
- return o
82
- end
83
-
data/lib/roo/worksheet.rb DELETED
@@ -1,18 +0,0 @@
1
- # patch for skipping blank rows in the case of
2
- # having a spreadsheet with 30,000 nil rows appended
3
- # to the actual data. (it happens and your RAM will love me)
4
- class Spreadsheet::Worksheet
5
-
6
- def each skip=dimensions[0]
7
- blanks = 0
8
- skip.upto(dimensions[1] - 1) do |i|
9
- if row(i).any?
10
- Proc.new.call(row(i))
11
- else
12
- blanks += 1
13
- blanks < 20 ? next : return
14
- end
15
- end
16
- end
17
-
18
- end
data/scripts/txt2html DELETED
@@ -1,67 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'rubygems'
4
- require 'redcloth'
5
- require 'syntax/convertors/html'
6
- require 'erb'
7
- require File.dirname(__FILE__) + '/../lib/roo/version.rb'
8
-
9
- version = Roo::VERSION::STRING
10
- download = 'http://rubyforge.org/projects/roo'
11
-
12
- class Fixnum
13
- def ordinal
14
- # teens
15
- return 'th' if (10..19).include?(self % 100)
16
- # others
17
- case self % 10
18
- when 1: return 'st'
19
- when 2: return 'nd'
20
- when 3: return 'rd'
21
- else return 'th'
22
- end
23
- end
24
- end
25
-
26
- class Time
27
- def pretty
28
- return "#{mday}#{mday.ordinal} #{strftime('%B')} #{year}"
29
- end
30
- end
31
-
32
- def convert_syntax(syntax, source)
33
- return Syntax::Convertors::HTML.for_syntax(syntax).convert(source).gsub(%r!^<pre>|</pre>$!,'')
34
- end
35
-
36
- if ARGV.length >= 1
37
- src, template = ARGV
38
- template ||= File.dirname(__FILE__) + '/../website/template.rhtml'
39
-
40
- else
41
- puts("Usage: #{File.split($0).last} source.txt [template.rhtml] > output.html")
42
- exit!
43
- end
44
-
45
- template = ERB.new(File.open(template).read)
46
-
47
- title = nil
48
- body = nil
49
- File.open(src) do |fsrc|
50
- title_text = fsrc.readline
51
- body_text = fsrc.read
52
- syntax_items = []
53
- body_text.gsub!(%r!<(pre|code)[^>]*?syntax=['"]([^'"]+)[^>]*>(.*?)</>!m){
54
- ident = syntax_items.length
55
- element, syntax, source = $1, $2, $3
56
- syntax_items << "<#{element} class='syntax'>#{convert_syntax(syntax, source)}</#{element}>"
57
- "syntax-temp-#{ident}"
58
- }
59
- title = RedCloth.new(title_text).to_html.gsub(%r!<.*?>!,'').strip
60
- body = RedCloth.new(body_text).to_html
61
- body.gsub!(%r!(?:<pre><code>)?syntax-temp-(d+)(?:</code></pre>)?!){ syntax_items[$1.to_i] }
62
- end
63
- stat = File.stat(src)
64
- created = stat.ctime
65
- modified = stat.mtime
66
-
67
- $stdout << template.result(binding)
@@ -1,15 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Roo::Excel2003XML do
4
- describe '.new' do
5
- context 'with an xml file' do
6
- let(:path) { 'test/files/datetime.xml' }
7
-
8
- it 'loads the file' do
9
- expect {
10
- Roo::Excel2003XML.new(path)
11
- }.to_not raise_error
12
- end
13
- end
14
- end
15
- end
@@ -1,17 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Roo::Excel do
4
- let(:excel) { Roo::Excel.new('test/files/boolean.xls') }
5
-
6
- describe '.new' do
7
- it 'creates an instance' do
8
- expect(excel).to be_a(Roo::Excel)
9
- end
10
- end
11
-
12
- describe '#sheets' do
13
- it 'returns the sheet names of the file' do
14
- expect(excel.sheets).to eq(["Sheet1", "Sheet2", "Sheet3"])
15
- end
16
- end
17
- end