roo 1.13.2 → 2.10.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.codeclimate.yml +17 -0
- data/.github/issue_template.md +16 -0
- data/.github/pull_request_template.md +14 -0
- data/.github/workflows/pull-request.yml +15 -0
- data/.github/workflows/ruby.yml +34 -0
- data/.gitignore +11 -0
- data/.rubocop.yml +186 -0
- data/.simplecov +4 -0
- data/CHANGELOG.md +702 -0
- data/Gemfile +18 -12
- data/Guardfile +23 -0
- data/LICENSE +5 -1
- data/README.md +328 -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 +317 -504
- data/lib/roo/constants.rb +7 -0
- data/lib/roo/csv.rb +141 -113
- data/lib/roo/errors.rb +11 -0
- data/lib/roo/excelx/cell/base.rb +108 -0
- data/lib/roo/excelx/cell/boolean.rb +30 -0
- data/lib/roo/excelx/cell/date.rb +28 -0
- data/lib/roo/excelx/cell/datetime.rb +107 -0
- data/lib/roo/excelx/cell/empty.rb +20 -0
- data/lib/roo/excelx/cell/number.rb +99 -0
- data/lib/roo/excelx/cell/string.rb +19 -0
- data/lib/roo/excelx/cell/time.rb +44 -0
- data/lib/roo/excelx/cell.rb +110 -0
- data/lib/roo/excelx/comments.rb +55 -0
- data/lib/roo/excelx/coordinate.rb +19 -0
- data/lib/roo/excelx/extractor.rb +39 -0
- data/lib/roo/excelx/format.rb +71 -0
- data/lib/roo/excelx/images.rb +26 -0
- data/lib/roo/excelx/relationships.rb +33 -0
- data/lib/roo/excelx/shared.rb +39 -0
- data/lib/roo/excelx/shared_strings.rb +151 -0
- data/lib/roo/excelx/sheet.rb +151 -0
- data/lib/roo/excelx/sheet_doc.rb +257 -0
- data/lib/roo/excelx/styles.rb +64 -0
- data/lib/roo/excelx/workbook.rb +64 -0
- data/lib/roo/excelx.rb +407 -601
- data/lib/roo/font.rb +17 -0
- data/lib/roo/formatters/base.rb +15 -0
- data/lib/roo/formatters/csv.rb +84 -0
- data/lib/roo/formatters/matrix.rb +23 -0
- data/lib/roo/formatters/xml.rb +31 -0
- data/lib/roo/formatters/yaml.rb +40 -0
- data/lib/roo/helpers/default_attr_reader.rb +20 -0
- data/lib/roo/helpers/weak_instance_cache.rb +41 -0
- data/lib/roo/libre_office.rb +4 -0
- data/lib/roo/link.rb +34 -0
- data/lib/roo/open_office.rb +631 -0
- data/lib/roo/spreadsheet.rb +28 -23
- data/lib/roo/tempdir.rb +24 -0
- data/lib/roo/utils.rb +128 -0
- data/lib/roo/version.rb +3 -0
- data/lib/roo.rb +26 -24
- data/roo.gemspec +29 -203
- data/spec/helpers.rb +5 -0
- data/spec/lib/roo/base_spec.rb +291 -3
- data/spec/lib/roo/csv_spec.rb +38 -11
- data/spec/lib/roo/excelx/cell/time_spec.rb +15 -0
- data/spec/lib/roo/excelx/format_spec.rb +7 -6
- data/spec/lib/roo/excelx/relationships_spec.rb +43 -0
- data/spec/lib/roo/excelx/sheet_doc_spec.rb +11 -0
- data/spec/lib/roo/excelx_spec.rb +672 -11
- data/spec/lib/roo/libreoffice_spec.rb +16 -6
- data/spec/lib/roo/openoffice_spec.rb +30 -8
- data/spec/lib/roo/spreadsheet_spec.rb +60 -12
- data/spec/lib/roo/strict_spec.rb +43 -0
- data/spec/lib/roo/utils_spec.rb +119 -0
- data/spec/lib/roo/weak_instance_cache_spec.rb +92 -0
- data/spec/lib/roo_spec.rb +0 -0
- data/spec/spec_helper.rb +7 -6
- data/test/all_ss.rb +12 -11
- data/test/excelx/cell/test_attr_reader_default.rb +72 -0
- data/test/excelx/cell/test_base.rb +68 -0
- data/test/excelx/cell/test_boolean.rb +36 -0
- data/test/excelx/cell/test_date.rb +38 -0
- data/test/excelx/cell/test_datetime.rb +45 -0
- data/test/excelx/cell/test_empty.rb +18 -0
- data/test/excelx/cell/test_number.rb +90 -0
- data/test/excelx/cell/test_string.rb +48 -0
- data/test/excelx/cell/test_time.rb +30 -0
- data/test/excelx/test_coordinate.rb +51 -0
- data/test/formatters/test_csv.rb +136 -0
- data/test/formatters/test_matrix.rb +76 -0
- data/test/formatters/test_xml.rb +78 -0
- data/test/formatters/test_yaml.rb +20 -0
- data/test/helpers/test_accessing_files.rb +81 -0
- data/test/helpers/test_comments.rb +43 -0
- data/test/helpers/test_formulas.rb +9 -0
- data/test/helpers/test_labels.rb +103 -0
- data/test/helpers/test_sheets.rb +55 -0
- data/test/helpers/test_styles.rb +62 -0
- data/test/roo/test_base.rb +182 -0
- data/test/roo/test_csv.rb +88 -0
- data/test/roo/test_excelx.rb +360 -0
- data/test/roo/test_libre_office.rb +9 -0
- data/test/roo/test_open_office.rb +289 -0
- data/test/test_helper.rb +123 -59
- data/test/test_roo.rb +392 -2292
- metadata +153 -298
- 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/openoffice.rb +0 -496
- 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/test/test_generic_spreadsheet.rb +0 -259
- 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/openoffice.rb
DELETED
@@ -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!(/'/,"'") # 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
|
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
|