roo 1.13.2 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +7 -0
- data/.simplecov +4 -0
- data/.travis.yml +13 -0
- data/CHANGELOG.md +515 -0
- data/Gemfile +16 -10
- data/Guardfile +24 -0
- data/LICENSE +3 -1
- data/README.md +254 -0
- data/Rakefile +23 -23
- data/examples/roo_soap_client.rb +28 -31
- data/examples/roo_soap_server.rb +4 -6
- data/examples/write_me.rb +9 -10
- data/lib/roo/base.rb +334 -395
- data/lib/roo/csv.rb +120 -113
- data/lib/roo/excelx/cell.rb +77 -0
- data/lib/roo/excelx/comments.rb +22 -0
- data/lib/roo/excelx/extractor.rb +22 -0
- data/lib/roo/excelx/relationships.rb +25 -0
- data/lib/roo/excelx/shared_strings.rb +37 -0
- data/lib/roo/excelx/sheet.rb +107 -0
- data/lib/roo/excelx/sheet_doc.rb +200 -0
- data/lib/roo/excelx/styles.rb +64 -0
- data/lib/roo/excelx/workbook.rb +59 -0
- data/lib/roo/excelx.rb +413 -597
- data/lib/roo/font.rb +17 -0
- data/lib/roo/libre_office.rb +5 -0
- data/lib/roo/link.rb +15 -0
- data/lib/roo/{openoffice.rb → open_office.rb} +681 -496
- data/lib/roo/spreadsheet.rb +20 -23
- data/lib/roo/utils.rb +78 -0
- data/lib/roo/version.rb +3 -0
- data/lib/roo.rb +18 -24
- data/roo.gemspec +20 -204
- data/spec/lib/roo/base_spec.rb +1 -4
- data/spec/lib/roo/csv_spec.rb +21 -13
- data/spec/lib/roo/excelx/format_spec.rb +7 -6
- data/spec/lib/roo/excelx_spec.rb +424 -11
- data/spec/lib/roo/libreoffice_spec.rb +16 -6
- data/spec/lib/roo/openoffice_spec.rb +13 -8
- data/spec/lib/roo/spreadsheet_spec.rb +40 -12
- data/spec/lib/roo/utils_spec.rb +106 -0
- data/spec/spec_helper.rb +2 -1
- data/test/test_generic_spreadsheet.rb +117 -139
- data/test/test_helper.rb +9 -56
- data/test/test_roo.rb +274 -478
- metadata +65 -303
- data/CHANGELOG +0 -417
- data/Gemfile.lock +0 -78
- data/README.markdown +0 -126
- data/VERSION +0 -1
- data/lib/roo/excel.rb +0 -355
- data/lib/roo/excel2003xml.rb +0 -300
- data/lib/roo/google.rb +0 -292
- data/lib/roo/roo_rails_helper.rb +0 -83
- data/lib/roo/worksheet.rb +0 -18
- data/scripts/txt2html +0 -67
- data/spec/lib/roo/excel2003xml_spec.rb +0 -15
- data/spec/lib/roo/excel_spec.rb +0 -17
- data/spec/lib/roo/google_spec.rb +0 -64
- data/test/files/1900_base.xls +0 -0
- data/test/files/1900_base.xlsx +0 -0
- data/test/files/1904_base.xls +0 -0
- data/test/files/1904_base.xlsx +0 -0
- data/test/files/Bibelbund.csv +0 -3741
- data/test/files/Bibelbund.ods +0 -0
- data/test/files/Bibelbund.xls +0 -0
- data/test/files/Bibelbund.xlsx +0 -0
- data/test/files/Bibelbund.xml +0 -62518
- data/test/files/Bibelbund1.ods +0 -0
- data/test/files/Pfand_from_windows_phone.xlsx +0 -0
- data/test/files/bad_excel_date.xls +0 -0
- data/test/files/bbu.ods +0 -0
- data/test/files/bbu.xls +0 -0
- data/test/files/bbu.xlsx +0 -0
- data/test/files/bbu.xml +0 -152
- data/test/files/bode-v1.ods.zip +0 -0
- data/test/files/bode-v1.xls.zip +0 -0
- data/test/files/boolean.csv +0 -2
- data/test/files/boolean.ods +0 -0
- data/test/files/boolean.xls +0 -0
- data/test/files/boolean.xlsx +0 -0
- data/test/files/boolean.xml +0 -112
- data/test/files/borders.ods +0 -0
- data/test/files/borders.xls +0 -0
- data/test/files/borders.xlsx +0 -0
- data/test/files/borders.xml +0 -144
- data/test/files/bug-numbered-sheet-names.xlsx +0 -0
- data/test/files/bug-row-column-fixnum-float.xls +0 -0
- data/test/files/bug-row-column-fixnum-float.xml +0 -127
- data/test/files/comments.ods +0 -0
- data/test/files/comments.xls +0 -0
- data/test/files/comments.xlsx +0 -0
- data/test/files/csvtypes.csv +0 -1
- data/test/files/datetime.ods +0 -0
- data/test/files/datetime.xls +0 -0
- data/test/files/datetime.xlsx +0 -0
- data/test/files/datetime.xml +0 -142
- data/test/files/datetime_floatconv.xls +0 -0
- data/test/files/datetime_floatconv.xml +0 -148
- data/test/files/dreimalvier.ods +0 -0
- data/test/files/emptysheets.ods +0 -0
- data/test/files/emptysheets.xls +0 -0
- data/test/files/emptysheets.xlsx +0 -0
- data/test/files/emptysheets.xml +0 -105
- data/test/files/excel2003.xml +0 -21140
- data/test/files/false_encoding.xls +0 -0
- data/test/files/false_encoding.xml +0 -132
- data/test/files/file_item_error.xlsx +0 -0
- data/test/files/formula.ods +0 -0
- data/test/files/formula.xls +0 -0
- data/test/files/formula.xlsx +0 -0
- data/test/files/formula.xml +0 -134
- data/test/files/formula_parse_error.xls +0 -0
- data/test/files/formula_parse_error.xml +0 -1833
- data/test/files/formula_string_error.xlsx +0 -0
- data/test/files/html-escape.ods +0 -0
- data/test/files/link.xls +0 -0
- data/test/files/link.xlsx +0 -0
- data/test/files/matrix.ods +0 -0
- data/test/files/matrix.xls +0 -0
- data/test/files/named_cells.ods +0 -0
- data/test/files/named_cells.xls +0 -0
- data/test/files/named_cells.xlsx +0 -0
- data/test/files/no_spreadsheet_file.txt +0 -1
- data/test/files/numbers1.csv +0 -18
- data/test/files/numbers1.ods +0 -0
- data/test/files/numbers1.xls +0 -0
- data/test/files/numbers1.xlsx +0 -0
- data/test/files/numbers1.xml +0 -312
- data/test/files/numeric-link.xlsx +0 -0
- data/test/files/only_one_sheet.ods +0 -0
- data/test/files/only_one_sheet.xls +0 -0
- data/test/files/only_one_sheet.xlsx +0 -0
- data/test/files/only_one_sheet.xml +0 -67
- data/test/files/paragraph.ods +0 -0
- data/test/files/paragraph.xls +0 -0
- data/test/files/paragraph.xlsx +0 -0
- data/test/files/paragraph.xml +0 -127
- data/test/files/prova.xls +0 -0
- data/test/files/ric.ods +0 -0
- data/test/files/simple_spreadsheet.ods +0 -0
- data/test/files/simple_spreadsheet.xls +0 -0
- data/test/files/simple_spreadsheet.xlsx +0 -0
- data/test/files/simple_spreadsheet.xml +0 -225
- data/test/files/simple_spreadsheet_from_italo.ods +0 -0
- data/test/files/simple_spreadsheet_from_italo.xls +0 -0
- data/test/files/simple_spreadsheet_from_italo.xml +0 -242
- data/test/files/so_datetime.csv +0 -7
- data/test/files/style.ods +0 -0
- data/test/files/style.xls +0 -0
- data/test/files/style.xlsx +0 -0
- data/test/files/style.xml +0 -154
- data/test/files/time-test.csv +0 -2
- data/test/files/time-test.ods +0 -0
- data/test/files/time-test.xls +0 -0
- data/test/files/time-test.xlsx +0 -0
- data/test/files/time-test.xml +0 -131
- data/test/files/type_excel.ods +0 -0
- data/test/files/type_excel.xlsx +0 -0
- data/test/files/type_excelx.ods +0 -0
- data/test/files/type_excelx.xls +0 -0
- data/test/files/type_openoffice.xls +0 -0
- data/test/files/type_openoffice.xlsx +0 -0
- data/test/files/whitespace.ods +0 -0
- data/test/files/whitespace.xls +0 -0
- data/test/files/whitespace.xlsx +0 -0
- data/test/files/whitespace.xml +0 -184
- data/test/rm_sub_test.rb +0 -12
- data/test/rm_test.rb +0 -7
- data/website/index.html +0 -385
- data/website/index.txt +0 -423
- data/website/javascripts/rounded_corners_lite.inc.js +0 -285
- data/website/stylesheets/screen.css +0 -130
- data/website/template.rhtml +0 -48
data/lib/roo/google.rb
DELETED
@@ -1,292 +0,0 @@
|
|
1
|
-
begin
|
2
|
-
require "google_drive"
|
3
|
-
rescue LoadError => e
|
4
|
-
raise e, "Using Roo::Google requires the google_drive gem"
|
5
|
-
end
|
6
|
-
|
7
|
-
class Roo::Google < Roo::Base
|
8
|
-
attr_accessor :date_format, :datetime_format
|
9
|
-
|
10
|
-
# Creates a new Google Drive object.
|
11
|
-
def initialize(spreadsheet_key, options = {})
|
12
|
-
@filename = spreadsheet_key
|
13
|
-
@user = options[:user] || ENV['GOOGLE_MAIL']
|
14
|
-
@password = options[:password] || ENV['GOOGLE_PASSWORD']
|
15
|
-
@access_token = options[:access_token] || ENV['GOOGLE_TOKEN']
|
16
|
-
|
17
|
-
@worksheets = session.spreadsheet_by_key(@filename).worksheets
|
18
|
-
@sheets = @worksheets.map {|sheet| sheet.title }
|
19
|
-
super
|
20
|
-
@cell = Hash.new {|h,k| h[k]=Hash.new}
|
21
|
-
@cell_type = Hash.new {|h,k| h[k]=Hash.new}
|
22
|
-
@formula = Hash.new
|
23
|
-
@date_format = '%d/%m/%Y'
|
24
|
-
@datetime_format = '%d/%m/%Y %H:%M:%S'
|
25
|
-
@time_format = '%H:%M:%S'
|
26
|
-
end
|
27
|
-
|
28
|
-
# returns an array of sheet names in the spreadsheet
|
29
|
-
attr_reader :sheets
|
30
|
-
|
31
|
-
def date?(string)
|
32
|
-
Date.strptime(string, @date_format)
|
33
|
-
true
|
34
|
-
rescue
|
35
|
-
false
|
36
|
-
end
|
37
|
-
|
38
|
-
# is String a time with format HH:MM:SS?
|
39
|
-
def time?(string)
|
40
|
-
DateTime.strptime(string, @time_format)
|
41
|
-
true
|
42
|
-
rescue
|
43
|
-
false
|
44
|
-
end
|
45
|
-
|
46
|
-
def datetime?(string)
|
47
|
-
DateTime.strptime(string, @datetime_format)
|
48
|
-
true
|
49
|
-
rescue
|
50
|
-
false
|
51
|
-
end
|
52
|
-
|
53
|
-
def numeric?(string)
|
54
|
-
string =~ /^[0-9]+[\.]*[0-9]*$/
|
55
|
-
end
|
56
|
-
|
57
|
-
def timestring_to_seconds(value)
|
58
|
-
hms = value.split(':')
|
59
|
-
hms[0].to_i*3600 + hms[1].to_i*60 + hms[2].to_i
|
60
|
-
end
|
61
|
-
|
62
|
-
# Returns the content of a spreadsheet-cell.
|
63
|
-
# (1,1) is the upper left corner.
|
64
|
-
# (1,1), (1,'A'), ('A',1), ('a',1) all refers to the
|
65
|
-
# cell at the first line and first row.
|
66
|
-
def cell(row, col, sheet=nil)
|
67
|
-
sheet ||= @default_sheet
|
68
|
-
validate_sheet!(sheet) #TODO: 2007-12-16
|
69
|
-
read_cells(sheet)
|
70
|
-
row,col = normalize(row,col)
|
71
|
-
value = @cell[sheet]["#{row},#{col}"]
|
72
|
-
if celltype(row,col,sheet) == :date
|
73
|
-
begin
|
74
|
-
return Date.strptime(value, @date_format)
|
75
|
-
rescue ArgumentError
|
76
|
-
raise "Invalid Date #{sheet}[#{row},#{col}] #{value} using format '{@date_format}'"
|
77
|
-
end
|
78
|
-
elsif celltype(row,col,sheet) == :datetime
|
79
|
-
begin
|
80
|
-
return DateTime.strptime(value, @datetime_format)
|
81
|
-
rescue ArgumentError
|
82
|
-
raise "Invalid DateTime #{sheet}[#{row},#{col}] #{value} using format '{@datetime_format}'"
|
83
|
-
end
|
84
|
-
end
|
85
|
-
return value
|
86
|
-
end
|
87
|
-
|
88
|
-
# returns the type of a cell:
|
89
|
-
# * :float
|
90
|
-
# * :string
|
91
|
-
# * :date
|
92
|
-
# * :percentage
|
93
|
-
# * :formula
|
94
|
-
# * :time
|
95
|
-
# * :datetime
|
96
|
-
def celltype(row, col, sheet=nil)
|
97
|
-
sheet ||= @default_sheet
|
98
|
-
read_cells(sheet)
|
99
|
-
row,col = normalize(row,col)
|
100
|
-
if @formula.size > 0 && @formula[sheet]["#{row},#{col}"]
|
101
|
-
:formula
|
102
|
-
else
|
103
|
-
@cell_type[sheet]["#{row},#{col}"]
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
# Returns the formula at (row,col).
|
108
|
-
# Returns nil if there is no formula.
|
109
|
-
# The method #formula? checks if there is a formula.
|
110
|
-
def formula(row,col,sheet=nil)
|
111
|
-
sheet ||= @default_sheet
|
112
|
-
read_cells(sheet)
|
113
|
-
row,col = normalize(row,col)
|
114
|
-
@formula[sheet]["#{row},#{col}"] && @formula[sheet]["#{row},#{col}"]
|
115
|
-
end
|
116
|
-
alias_method :formula?, :formula
|
117
|
-
|
118
|
-
# true, if the cell is empty
|
119
|
-
def empty?(row, col, sheet=nil)
|
120
|
-
value = cell(row, col, sheet)
|
121
|
-
return true unless value
|
122
|
-
return false if value.class == Date # a date is never empty
|
123
|
-
return false if value.class == Float
|
124
|
-
return false if celltype(row,col,sheet) == :time
|
125
|
-
value.empty?
|
126
|
-
end
|
127
|
-
|
128
|
-
# sets the cell to the content of 'value'
|
129
|
-
# a formula can be set in the form of '=SUM(...)'
|
130
|
-
def set(row,col,value,sheet=nil)
|
131
|
-
sheet ||= @default_sheet
|
132
|
-
validate_sheet!(sheet)
|
133
|
-
|
134
|
-
sheet_no = sheets.index(sheet)+1
|
135
|
-
row,col = normalize(row,col)
|
136
|
-
add_to_cell_roo(row,col,value,sheet_no)
|
137
|
-
# re-read the portion of the document that has changed
|
138
|
-
if @cells_read[sheet]
|
139
|
-
value, value_type = determine_datatype(value.to_s)
|
140
|
-
|
141
|
-
_set_value(row,col,value,sheet)
|
142
|
-
set_type(row,col,value_type,sheet)
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
# *DEPRECATED*: Use Roo::Google#set instead
|
147
|
-
def set_value(row,col,value,sheet=nil)
|
148
|
-
warn "[DEPRECATION] `set_value` is deprecated. Please use `set` instead."
|
149
|
-
set(row,col,value,sheet)
|
150
|
-
end
|
151
|
-
|
152
|
-
# returns the first non-empty row in a sheet
|
153
|
-
def first_row(sheet=nil)
|
154
|
-
sheet ||= @default_sheet
|
155
|
-
unless @first_row[sheet]
|
156
|
-
sheet_no = sheets.index(sheet) + 1
|
157
|
-
@first_row[sheet], @last_row[sheet], @first_column[sheet], @last_column[sheet] =
|
158
|
-
oben_unten_links_rechts(sheet_no)
|
159
|
-
end
|
160
|
-
return @first_row[sheet]
|
161
|
-
end
|
162
|
-
|
163
|
-
# returns the last non-empty row in a sheet
|
164
|
-
def last_row(sheet=nil)
|
165
|
-
sheet ||= @default_sheet
|
166
|
-
unless @last_row[sheet]
|
167
|
-
sheet_no = sheets.index(sheet) + 1
|
168
|
-
@first_row[sheet], @last_row[sheet], @first_column[sheet], @last_column[sheet] =
|
169
|
-
oben_unten_links_rechts(sheet_no)
|
170
|
-
end
|
171
|
-
return @last_row[sheet]
|
172
|
-
end
|
173
|
-
|
174
|
-
# returns the first non-empty column in a sheet
|
175
|
-
def first_column(sheet=nil)
|
176
|
-
sheet ||= @default_sheet
|
177
|
-
unless @first_column[sheet]
|
178
|
-
sheet_no = sheets.index(sheet) + 1
|
179
|
-
@first_row[sheet], @last_row[sheet], @first_column[sheet], @last_column[sheet] =
|
180
|
-
oben_unten_links_rechts(sheet_no)
|
181
|
-
end
|
182
|
-
return @first_column[sheet]
|
183
|
-
end
|
184
|
-
|
185
|
-
# returns the last non-empty column in a sheet
|
186
|
-
def last_column(sheet=nil)
|
187
|
-
sheet ||= @default_sheet
|
188
|
-
unless @last_column[sheet]
|
189
|
-
sheet_no = sheets.index(sheet) + 1
|
190
|
-
@first_row[sheet], @last_row[sheet], @first_column[sheet], @last_column[sheet] =
|
191
|
-
oben_unten_links_rechts(sheet_no)
|
192
|
-
end
|
193
|
-
return @last_column[sheet]
|
194
|
-
end
|
195
|
-
|
196
|
-
private
|
197
|
-
|
198
|
-
def _set_value(row,col,value,sheet=nil)
|
199
|
-
sheet ||= @default_sheet
|
200
|
-
@cell[sheet][ "#{row},#{col}"] = value
|
201
|
-
end
|
202
|
-
|
203
|
-
def set_type(row,col,type,sheet=nil)
|
204
|
-
sheet ||= @default_sheet
|
205
|
-
@cell_type[sheet]["#{row},#{col}"] = type
|
206
|
-
end
|
207
|
-
|
208
|
-
# read all cells in a sheet.
|
209
|
-
def read_cells(sheet=nil)
|
210
|
-
sheet ||= @default_sheet
|
211
|
-
validate_sheet!(sheet)
|
212
|
-
return if @cells_read[sheet]
|
213
|
-
|
214
|
-
sheet_no = sheets.index(sheet)
|
215
|
-
ws = @worksheets[sheet_no]
|
216
|
-
for row in 1..ws.num_rows
|
217
|
-
for col in 1..ws.num_cols
|
218
|
-
key = "#{row},#{col}"
|
219
|
-
string_value = ws.input_value(row,col) # item['inputvalue'] || item['inputValue']
|
220
|
-
numeric_value = ws[row,col] #item['numericvalue'] || item['numericValue']
|
221
|
-
(value, value_type) = determine_datatype(string_value, numeric_value)
|
222
|
-
@cell[sheet][key] = value unless value == "" or value == nil
|
223
|
-
@cell_type[sheet][key] = value_type
|
224
|
-
@formula[sheet] = {} unless @formula[sheet]
|
225
|
-
@formula[sheet][key] = string_value if value_type == :formula
|
226
|
-
end
|
227
|
-
end
|
228
|
-
@cells_read[sheet] = true
|
229
|
-
end
|
230
|
-
|
231
|
-
def determine_datatype(val, numval=nil)
|
232
|
-
if val.nil? || val[0,1] == '='
|
233
|
-
ty = :formula
|
234
|
-
if numeric?(numval)
|
235
|
-
val = numval.to_f
|
236
|
-
else
|
237
|
-
val = numval
|
238
|
-
end
|
239
|
-
else
|
240
|
-
if datetime?(val)
|
241
|
-
ty = :datetime
|
242
|
-
elsif date?(val)
|
243
|
-
ty = :date
|
244
|
-
elsif numeric?(val)
|
245
|
-
ty = :float
|
246
|
-
val = val.to_f
|
247
|
-
elsif time?(val)
|
248
|
-
ty = :time
|
249
|
-
val = timestring_to_seconds(val)
|
250
|
-
else
|
251
|
-
ty = :string
|
252
|
-
end
|
253
|
-
end
|
254
|
-
return val, ty
|
255
|
-
end
|
256
|
-
|
257
|
-
def add_to_cell_roo(row,col,value, sheet_no=1)
|
258
|
-
sheet_no -= 1
|
259
|
-
@worksheets[sheet_no][row,col] = value
|
260
|
-
@worksheets[sheet_no].save
|
261
|
-
end
|
262
|
-
def entry_roo(value,row,col)
|
263
|
-
return value,row,col
|
264
|
-
end
|
265
|
-
|
266
|
-
def oben_unten_links_rechts(sheet_no)
|
267
|
-
ws = @worksheets[sheet_no-1]
|
268
|
-
rows = []
|
269
|
-
cols = []
|
270
|
-
for row in 1..ws.num_rows
|
271
|
-
for col in 1..ws.num_cols
|
272
|
-
rows << row if ws[row,col] and ws[row,col] != '' #TODO: besser?
|
273
|
-
cols << col if ws[row,col] and ws[row,col] != '' #TODO: besser?
|
274
|
-
end
|
275
|
-
end
|
276
|
-
return rows.min, rows.max, cols.min, cols.max
|
277
|
-
end
|
278
|
-
|
279
|
-
def reinitialize
|
280
|
-
initialize(@filename, user: @user, password: @password, access_token: @access_token)
|
281
|
-
end
|
282
|
-
|
283
|
-
def session
|
284
|
-
@session ||= if @user && @password
|
285
|
-
GoogleDrive.login(@user, @password)
|
286
|
-
elsif @access_token
|
287
|
-
GoogleDrive.login_with_oauth(@access_token)
|
288
|
-
else
|
289
|
-
warn 'set user and password or access token'
|
290
|
-
end
|
291
|
-
end
|
292
|
-
end
|
data/lib/roo/roo_rails_helper.rb
DELETED
@@ -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> </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 << " "
|
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
|
data/spec/lib/roo/excel_spec.rb
DELETED
@@ -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
|
data/spec/lib/roo/google_spec.rb
DELETED
@@ -1,64 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Roo::Google do
|
4
|
-
let(:key) { '0AiokXJytm-hjdDhYbTNvZ3pDWm9oZm9yWURLX3ZoR2c' }
|
5
|
-
|
6
|
-
describe '.new' do
|
7
|
-
context 'given a username and password' do
|
8
|
-
let(:user) { 'user' }
|
9
|
-
let(:password) { 'password' }
|
10
|
-
|
11
|
-
subject {
|
12
|
-
Roo::Google.new(key, user: user, password: password)
|
13
|
-
}
|
14
|
-
|
15
|
-
it 'creates an instance' do
|
16
|
-
VCR.use_cassette('google_drive') do
|
17
|
-
expect(subject).to be_a(Roo::Google)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
context 'given an access token' do
|
23
|
-
let(:access_token) { 'ya29.AHES6ZR1kGjlmlLJG9skjpO0IjzQ6qDohXwFJclzD7mHI9xa-cFzlg' }
|
24
|
-
|
25
|
-
subject {
|
26
|
-
Roo::Google.new(key, access_token: access_token)
|
27
|
-
}
|
28
|
-
|
29
|
-
it 'creates an instance' do
|
30
|
-
VCR.use_cassette('google_drive_access_token') do
|
31
|
-
expect(subject).to be_a(Roo::Google)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
describe '.set' do
|
38
|
-
let(:key) { '0AiVSev9-0p-PdEVrQldEY1I4dDJjVlpEQUkwblprcnc' }
|
39
|
-
let(:user) { 'user' }
|
40
|
-
let(:password) { "password" }
|
41
|
-
|
42
|
-
subject {
|
43
|
-
Roo::Google.new(key, user: user, password: password)
|
44
|
-
}
|
45
|
-
|
46
|
-
it 'records the value' do
|
47
|
-
VCR.use_cassette('google_drive_set') do
|
48
|
-
subject.cell(1, 1).should == '1x1'
|
49
|
-
subject.cell(1, 2).should == '1x2'
|
50
|
-
subject.cell(2, 1).should == '2x1'
|
51
|
-
subject.cell(2, 2).should == '2x2'
|
52
|
-
subject.set(1, 1, '1x1')
|
53
|
-
subject.set(1, 2, '1x2')
|
54
|
-
subject.set(2, 1, '2x1')
|
55
|
-
subject.set(2, 2, '2x2')
|
56
|
-
subject.cell(1, 1).should == '1x1'
|
57
|
-
subject.cell(1, 2).should == '1x2'
|
58
|
-
subject.cell(2, 1).should == '2x1'
|
59
|
-
subject.cell(2, 2).should == '2x2'
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
end
|
data/test/files/1900_base.xls
DELETED
Binary file
|
data/test/files/1900_base.xlsx
DELETED
Binary file
|
data/test/files/1904_base.xls
DELETED
Binary file
|
data/test/files/1904_base.xlsx
DELETED
Binary file
|