Skip to content

Commit 5633f7f

Browse files
committedFeb 26, 2017
added initial examples and Gemfile
0 parents  commit 5633f7f

6 files changed

+113
-0
lines changed
 

‎Gemfile

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
source 'https://rubygems.org'
2+
3+
gem 'rubyXL'
4+
gem 'roo'
5+
gem 'creek'

‎Gemfile.lock

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
GEM
2+
remote: https://rubygems.org/
3+
specs:
4+
creek (1.1.2)
5+
nokogiri (~> 1.6.0)
6+
rubyzip (>= 1.0.0)
7+
mini_portile2 (2.1.0)
8+
nokogiri (1.6.8.1)
9+
mini_portile2 (~> 2.1.0)
10+
roo (2.7.1)
11+
nokogiri (~> 1)
12+
rubyzip (~> 1.1, < 2.0.0)
13+
rubyXL (3.3.23)
14+
nokogiri (>= 1.4.4)
15+
rubyzip (>= 1.1.6)
16+
rubyzip (1.2.1)
17+
18+
PLATFORMS
19+
ruby
20+
21+
DEPENDENCIES
22+
creek
23+
roo
24+
rubyXL
25+
26+
BUNDLED WITH
27+
1.14.5

‎creek_example.rb

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
require 'creek'
3+
4+
# ============================================
5+
# =========== Read Example ===============
6+
# ============================================
7+
8+
workbook = Creek::Book.new "sample_excel_file.xlsx"
9+
10+
worksheets = workbook.sheets
11+
puts "Found #{worksheets.count} worksheets"
12+
13+
worksheets.each do |worksheet|
14+
puts "Reading: #{worksheet}"
15+
num_rows = 0
16+
17+
worksheet.rows.each do |row|
18+
row_cells = row.values
19+
num_rows += 1
20+
21+
# uncomment to print out row values
22+
# puts row_cells.join " "
23+
end
24+
puts "Read #{num_rows} rows"
25+
end
26+
27+
puts 'Done'

‎roo_example.rb

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
require 'roo'
3+
4+
# ============================================
5+
# =========== Read Example ===============
6+
# ============================================
7+
8+
workbook = Roo::Spreadsheet.open('./sample_excel_file.xlsx')
9+
10+
worksheets = workbook.sheets
11+
puts "Found #{worksheets.count} worksheets"
12+
13+
worksheets.each do |worksheet|
14+
puts "Reading: #{worksheet}"
15+
num_rows = 0
16+
17+
workbook.sheet(worksheet).each_row_streaming do |row|
18+
row_cells = row.map { |cell| cell.value }
19+
num_rows += 1
20+
21+
# uncomment to print out row values
22+
# puts row_cells.join ' '
23+
end
24+
puts "Read #{num_rows} rows"
25+
end
26+
27+
puts 'Done'

‎ruby_xl_example.rb

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
require 'rubyXL'
3+
4+
# ============================================
5+
# =========== Read Example ===============
6+
# ============================================
7+
8+
workbook = RubyXL::Parser.parse("sample_excel_file.xlsx")
9+
10+
worksheets = workbook.worksheets
11+
puts "Found #{worksheets.count} worksheets"
12+
13+
worksheets.each do |worksheet|
14+
puts "Reading: #{worksheet.sheet_name}"
15+
num_rows = 0
16+
17+
worksheet.each do |row|
18+
row_cells = row.cells.map{ |cell| cell.value }
19+
num_rows += 1
20+
21+
# uncomment to print out row values
22+
# puts row_cells.join " "
23+
end
24+
puts "Read #{num_rows} rows"
25+
end
26+
27+
puts 'Done'

‎sample_excel_file.xlsx

45.6 KB
Binary file not shown.

0 commit comments

Comments
 (0)
Please sign in to comment.