robust_excel_ole 1.18 → 1.18.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Changelog +7 -2
- data/benchmarking/Gemfile +7 -0
- data/benchmarking/README.md +131 -0
- data/benchmarking/creek_example.rb +33 -0
- data/benchmarking/generating_excel_files.rb +28 -0
- data/benchmarking/reo_example.rb +26 -0
- data/benchmarking/reo_example1.rb +31 -0
- data/benchmarking/reo_example2.rb +26 -0
- data/benchmarking/roo_example.rb +33 -0
- data/benchmarking/ruby_xl_example.rb +36 -0
- data/benchmarking/sample_excel_files/xlsx_500_rows.xlsx +0 -0
- data/benchmarking/simple_xlsx_reader_example.rb +33 -0
- data/benchmarking/spreadsheet_example.rb +36 -0
- data/bin/jreo +3 -0
- data/bin/reo +61 -0
- data/docs/README_ranges.rdoc +0 -36
- data/docs/README_sheet.rdoc +72 -0
- data/lib/reo_console.rb +8 -1
- data/lib/robust_excel_ole/version.rb +1 -1
- data/lib/robust_excel_ole/worksheet.rb +12 -5
- data/lib/rubygems_plugin.rb +3 -0
- data/reo.bat +3 -1
- data/robust_excel_ole.gemspec +1 -2
- data/spec/worksheet_spec.rb +12 -4
- metadata +22 -7
- data/extconf.rb +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7c46520c55bdc3ba5f7d94a7bfb2e880565d52fa640ce8d2ce08204b98a5a12d
|
4
|
+
data.tar.gz: 032fb5333b2f417131091f12d1d2d9276b5c1fb46bfcae0b9327cf75dd0098d7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 05d1175039ff47dc11e3f40743667c4d90653b7f9f21f7f6d168c1dda6566c1a9a2dc66bc207ba6d5347363097e8642145d0f66d9b6e46a0cbd748f4d44701f8
|
7
|
+
data.tar.gz: 637513fd4f21062f6ea480c1795737cfc5509214408aead3f2bc6aa2fe67750f43264eac872ff817eb069e810686216f8b42cbaffcff180251177f0030977c47
|
data/Changelog
CHANGED
@@ -1,14 +1,19 @@
|
|
1
1
|
# Change Log
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
|
4
|
+
|
5
|
+
## [1.19] 2020-30-5
|
6
|
+
|
7
|
+
### Added
|
8
|
+
- Workheet#values, each_rowvalue
|
9
|
+
|
10
|
+
|
4
11
|
## [1.18] 2020-30-4
|
5
12
|
|
6
13
|
### Added
|
7
14
|
- Workbook#worksheets, worksheets_count
|
8
15
|
- Worksheet#each_value
|
9
16
|
- Range#value, value=
|
10
|
-
|
11
|
-
### Changed
|
12
17
|
- Range#initialize: optional paramter worksheet
|
13
18
|
|
14
19
|
## [1.17]
|
@@ -0,0 +1,131 @@
|
|
1
|
+
# ruby-excel-library-examples
|
2
|
+
This project contains sample code for reading Excel files with different Ruby libraries.
|
3
|
+
|
4
|
+
## `.xlsx` File Examples
|
5
|
+
Below are code samples for reading current OOXML Excel files using [**rubyXL**](https://github.com/weshatheleopard/rubyXL), [**roo**](https://github.com/roo-rb/roo), [**creek**](https://github.com/pythonicrubyist/creek), and [**simple_xlsx_reader**](https://github.com/woahdae/simple_xlsx_reader).
|
6
|
+
|
7
|
+
### [rubyXL](https://github.com/weshatheleopard/rubyXL)
|
8
|
+
```ruby
|
9
|
+
require 'rubyXL'
|
10
|
+
|
11
|
+
workbook = RubyXL::Parser.parse './sample_excel_files/xlsx_500_rows.xlsx'
|
12
|
+
worksheets = workbook.worksheets
|
13
|
+
puts "Found #{worksheets.count} worksheets"
|
14
|
+
|
15
|
+
worksheets.each do |worksheet|
|
16
|
+
puts "Reading: #{worksheet.sheet_name}"
|
17
|
+
num_rows = 0
|
18
|
+
|
19
|
+
worksheet.each do |row|
|
20
|
+
row_cells = row.cells.map{ |cell| cell.value }
|
21
|
+
num_rows += 1
|
22
|
+
|
23
|
+
# uncomment to print out row values
|
24
|
+
# puts row_cells.join " "
|
25
|
+
end
|
26
|
+
puts "Read #{num_rows} rows"
|
27
|
+
end
|
28
|
+
|
29
|
+
puts 'Done'
|
30
|
+
```
|
31
|
+
### [roo](https://github.com/roo-rb/roo)
|
32
|
+
```ruby
|
33
|
+
require 'roo'
|
34
|
+
|
35
|
+
workbook = Roo::Spreadsheet.open './sample_excel_files/xlsx_500_rows.xlsx'
|
36
|
+
worksheets = workbook.sheets
|
37
|
+
puts "Found #{worksheets.count} worksheets"
|
38
|
+
|
39
|
+
worksheets.each do |worksheet|
|
40
|
+
puts "Reading: #{worksheet}"
|
41
|
+
num_rows = 0
|
42
|
+
|
43
|
+
workbook.sheet(worksheet).each_row_streaming do |row|
|
44
|
+
row_cells = row.map { |cell| cell.value }
|
45
|
+
num_rows += 1
|
46
|
+
|
47
|
+
# uncomment to print out row values
|
48
|
+
# puts row_cells.join ' '
|
49
|
+
end
|
50
|
+
puts "Read #{num_rows} rows"
|
51
|
+
end
|
52
|
+
|
53
|
+
puts 'Done'
|
54
|
+
```
|
55
|
+
### [creek](https://github.com/pythonicrubyist/creek)
|
56
|
+
```ruby
|
57
|
+
require 'creek'
|
58
|
+
|
59
|
+
workbook = Creek::Book.new './sample_excel_files/xlsx_500_rows.xlsx'
|
60
|
+
worksheets = workbook.sheets
|
61
|
+
puts "Found #{worksheets.count} worksheets"
|
62
|
+
|
63
|
+
worksheets.each do |worksheet|
|
64
|
+
puts "Reading: #{worksheet.name}"
|
65
|
+
num_rows = 0
|
66
|
+
|
67
|
+
worksheet.rows.each do |row|
|
68
|
+
row_cells = row.values
|
69
|
+
num_rows += 1
|
70
|
+
|
71
|
+
# uncomment to print out row values
|
72
|
+
# puts row_cells.join " "
|
73
|
+
end
|
74
|
+
puts "Read #{num_rows} rows"
|
75
|
+
end
|
76
|
+
|
77
|
+
puts 'Done'
|
78
|
+
```
|
79
|
+
### [simple_xlsx_reader](https://github.com/woahdae/simple_xlsx_reader)
|
80
|
+
```ruby
|
81
|
+
require 'simple_xlsx_reader'
|
82
|
+
|
83
|
+
workbook = SimpleXlsxReader.open './sample_excel_files/xlsx_500000_rows.xlsx'
|
84
|
+
worksheets = workbook.sheets
|
85
|
+
puts "Found #{worksheets.count} worksheets"
|
86
|
+
|
87
|
+
worksheets.each do |worksheet|
|
88
|
+
puts "Reading: #{worksheet.name}"
|
89
|
+
num_rows = 0
|
90
|
+
|
91
|
+
worksheet.rows.each do |row|
|
92
|
+
row_cells = row
|
93
|
+
num_rows += 1
|
94
|
+
|
95
|
+
# uncomment to print out row values
|
96
|
+
# puts row_cells.join ' '
|
97
|
+
end
|
98
|
+
puts "Read #{num_rows} rows"
|
99
|
+
end
|
100
|
+
|
101
|
+
puts 'Done'
|
102
|
+
```
|
103
|
+
|
104
|
+
## Legacy `.xls` Files
|
105
|
+
Below are code samples for reading legacy Excel files using [**spreadsheet**](https://github.com/zdavatz/spreadsheet)
|
106
|
+
|
107
|
+
### [spreadsheet](https://github.com/zdavatz/spreadsheet)
|
108
|
+
```ruby
|
109
|
+
require 'spreadsheet'
|
110
|
+
|
111
|
+
# Note: spreadsheet only supports .xls files (not .xlsx)
|
112
|
+
workbook = Spreadsheet.open './sample_excel_files/xls_500_rows.xls'
|
113
|
+
worksheets = workbook.worksheets
|
114
|
+
puts "Found #{worksheets.count} worksheets"
|
115
|
+
|
116
|
+
worksheets.each do |worksheet|
|
117
|
+
puts "Reading: #{worksheet.name}"
|
118
|
+
num_rows = 0
|
119
|
+
|
120
|
+
worksheet.rows.each do |row|
|
121
|
+
row_cells = row.to_a.map{ |v| v.methods.include?(:value) ? v.value : v }
|
122
|
+
num_rows += 1
|
123
|
+
|
124
|
+
# uncomment to print out row values
|
125
|
+
# puts row_cells.join " "
|
126
|
+
end
|
127
|
+
puts "Read #{num_rows} rows"
|
128
|
+
end
|
129
|
+
|
130
|
+
puts 'Done'
|
131
|
+
```
|
@@ -0,0 +1,33 @@
|
|
1
|
+
|
2
|
+
require 'creek'
|
3
|
+
|
4
|
+
start_time = Time.now
|
5
|
+
|
6
|
+
# ============================================
|
7
|
+
# =========== Read Example ===============
|
8
|
+
# ============================================
|
9
|
+
|
10
|
+
workbook = Creek::Book.new './sample_excel_files/xlsx_500_rows.xlsx'
|
11
|
+
|
12
|
+
worksheets = workbook.sheets
|
13
|
+
puts "Found #{worksheets.count} worksheets"
|
14
|
+
|
15
|
+
worksheets.each do |worksheet|
|
16
|
+
puts "Reading: #{worksheet.name}"
|
17
|
+
num_rows = 0
|
18
|
+
|
19
|
+
worksheet.rows.each do |row|
|
20
|
+
row_cells = row.values
|
21
|
+
num_rows += 1
|
22
|
+
|
23
|
+
# uncomment to print out row values
|
24
|
+
# puts row_cells.join " "
|
25
|
+
end
|
26
|
+
puts "Read #{num_rows} rows"
|
27
|
+
end
|
28
|
+
|
29
|
+
end_time = Time.now
|
30
|
+
running_time = end_time - start_time
|
31
|
+
puts "time: #{running_time} sec."
|
32
|
+
|
33
|
+
puts 'Done'
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require_relative '../lib/robust_excel_ole'
|
2
|
+
|
3
|
+
include RobustExcelOle
|
4
|
+
|
5
|
+
begin
|
6
|
+
|
7
|
+
filename = './large_excel_files/xlsx_10_rows.xlsx'
|
8
|
+
Excel.kill_all
|
9
|
+
|
10
|
+
Workbook.open(filename, :if_absent => :create) do |workbook|
|
11
|
+
# default: 3 worksheets
|
12
|
+
num_worksheets = 1
|
13
|
+
workbook.each do |worksheet|
|
14
|
+
puts "worksheet-number #{num_worksheets}"
|
15
|
+
num_rows = 1
|
16
|
+
(1..10).each do |row|
|
17
|
+
puts "row-number: #{num_rows}"
|
18
|
+
(1..10).each do |column|
|
19
|
+
worksheet[num_rows,column].value = (num_rows-1)*10+column
|
20
|
+
end
|
21
|
+
num_rows += 1
|
22
|
+
end
|
23
|
+
num_worksheets += 1
|
24
|
+
end
|
25
|
+
workbook.save
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '../lib/robust_excel_ole')
|
2
|
+
|
3
|
+
start_time = Time.now
|
4
|
+
|
5
|
+
workbook = RobustExcelOle::Workbook.open './sample_excel_files/xlsx_500_rows.xlsx'
|
6
|
+
|
7
|
+
puts "Found #{workbook.worksheets_count} worksheets"
|
8
|
+
|
9
|
+
workbook.each do |worksheet|
|
10
|
+
puts "Reading: #{worksheet.name}"
|
11
|
+
num_rows = 0
|
12
|
+
|
13
|
+
worksheet.values.each do |row_vals|
|
14
|
+
row_cells = row_vals
|
15
|
+
num_rows += 1
|
16
|
+
end
|
17
|
+
|
18
|
+
puts "Read #{num_rows} rows"
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
end_time = Time.now
|
23
|
+
running_time = end_time - start_time
|
24
|
+
puts "time: #{running_time} sec."
|
25
|
+
|
26
|
+
puts 'Done'
|
@@ -0,0 +1,31 @@
|
|
1
|
+
#require 'robust_excel_ole'
|
2
|
+
require File.join(File.dirname(__FILE__), '../lib/robust_excel_ole')
|
3
|
+
|
4
|
+
start_time = Time.now
|
5
|
+
|
6
|
+
workbook = RobustExcelOle::Workbook.open './sample_excel_files/xlsx_500_rows.xlsx'
|
7
|
+
|
8
|
+
puts "Found #{workbook.Worksheets.Count} worksheets"
|
9
|
+
|
10
|
+
workbook.each do |worksheet|
|
11
|
+
puts "Reading: #{worksheet.name}"
|
12
|
+
num_rows = 0
|
13
|
+
|
14
|
+
worksheet.each_row do |row|
|
15
|
+
row_cells = row.map{ |cell| cell.value }
|
16
|
+
num_rows += 1
|
17
|
+
|
18
|
+
# uncomment to print out row values
|
19
|
+
# puts row_cells.join " "
|
20
|
+
end
|
21
|
+
puts "Read #{num_rows} rows"
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
end_time = Time.now
|
28
|
+
running_time = end_time - start_time
|
29
|
+
puts "time: #{running_time} sec."
|
30
|
+
|
31
|
+
puts 'Done'
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '../lib/robust_excel_ole')
|
2
|
+
|
3
|
+
start_time = Time.now
|
4
|
+
|
5
|
+
workbook = RobustExcelOle::Workbook.open './sample_excel_files/xlsx_500_rows.xlsx'
|
6
|
+
|
7
|
+
puts "Found #{workbook.worksheets_count} worksheets"
|
8
|
+
|
9
|
+
workbook.each do |worksheet|
|
10
|
+
puts "Reading: #{worksheet.name}"
|
11
|
+
num_rows = 0
|
12
|
+
|
13
|
+
worksheet.each_rowvalue do |row_vals|
|
14
|
+
row_cells = row_vals
|
15
|
+
num_rows += 1
|
16
|
+
end
|
17
|
+
|
18
|
+
puts "Read #{num_rows} rows"
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
end_time = Time.now
|
23
|
+
running_time = end_time - start_time
|
24
|
+
puts "time: #{running_time} sec."
|
25
|
+
|
26
|
+
puts 'Done'
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'roo'
|
2
|
+
|
3
|
+
# ============================================
|
4
|
+
# =========== Read Example ===============
|
5
|
+
# ============================================
|
6
|
+
|
7
|
+
start_time = Time.now
|
8
|
+
|
9
|
+
workbook = Roo::Spreadsheet.open './sample_excel_files/xlsx_500_rows.xlsx'
|
10
|
+
|
11
|
+
worksheets = workbook.sheets
|
12
|
+
puts "Found #{worksheets.count} worksheets"
|
13
|
+
|
14
|
+
worksheets.each do |worksheet|
|
15
|
+
puts "Reading: #{worksheet}"
|
16
|
+
num_rows = 0
|
17
|
+
|
18
|
+
workbook.sheet(worksheet).each_row_streaming do |row|
|
19
|
+
row_cells = row.map { |cell| cell.value }
|
20
|
+
#puts row_cells.inspect
|
21
|
+
num_rows += 1
|
22
|
+
|
23
|
+
# uncomment to print out row values
|
24
|
+
# puts row_cells.join ' '
|
25
|
+
end
|
26
|
+
puts "Read #{num_rows} rows"
|
27
|
+
end
|
28
|
+
|
29
|
+
end_time = Time.now
|
30
|
+
running_time = end_time - start_time
|
31
|
+
puts "time: #{running_time} sec."
|
32
|
+
|
33
|
+
puts 'Done'
|
@@ -0,0 +1,36 @@
|
|
1
|
+
|
2
|
+
require 'rubyXL'
|
3
|
+
|
4
|
+
start_time = Time.now
|
5
|
+
|
6
|
+
# ============================================
|
7
|
+
# =========== Read Example ===============
|
8
|
+
# ============================================
|
9
|
+
|
10
|
+
workbook = RubyXL::Parser.parse './sample_excel_files/xlsx_500_rows.xlsx'
|
11
|
+
|
12
|
+
worksheets = workbook.worksheets
|
13
|
+
puts "Found #{worksheets.count} worksheets"
|
14
|
+
|
15
|
+
worksheets.each do |worksheet|
|
16
|
+
puts "Reading: #{worksheet.sheet_name}"
|
17
|
+
num_rows = 0
|
18
|
+
|
19
|
+
worksheet.each do |row|
|
20
|
+
row_cells = row.cells.map{ |cell| cell.value }
|
21
|
+
num_rows += 1
|
22
|
+
|
23
|
+
# uncomment to print out row values
|
24
|
+
# puts row_cells.join " "
|
25
|
+
end
|
26
|
+
puts "Read #{num_rows} rows"
|
27
|
+
end
|
28
|
+
|
29
|
+
end_time = Time.now
|
30
|
+
running_time = end_time - start_time
|
31
|
+
puts "time: #{running_time} sec."
|
32
|
+
|
33
|
+
puts 'Done'
|
34
|
+
|
35
|
+
|
36
|
+
puts 'Done'
|
Binary file
|
@@ -0,0 +1,33 @@
|
|
1
|
+
|
2
|
+
require 'simple_xlsx_reader'
|
3
|
+
|
4
|
+
start_time = Time.now
|
5
|
+
|
6
|
+
# ============================================
|
7
|
+
# =========== Read Example ==============
|
8
|
+
# ============================================
|
9
|
+
|
10
|
+
workbook = SimpleXlsxReader.open './sample_excel_files/xlsx_500_rows.xlsx'
|
11
|
+
|
12
|
+
worksheets = workbook.sheets
|
13
|
+
puts "Found #{worksheets.count} worksheets"
|
14
|
+
|
15
|
+
worksheets.each do |worksheet|
|
16
|
+
puts "Reading: #{worksheet.name}"
|
17
|
+
num_rows = 0
|
18
|
+
|
19
|
+
worksheet.rows.each do |row|
|
20
|
+
row_cells = row
|
21
|
+
num_rows += 1
|
22
|
+
|
23
|
+
# uncomment to print out row values
|
24
|
+
# puts row_cells.join ' '
|
25
|
+
end
|
26
|
+
puts "Read #{num_rows} rows"
|
27
|
+
end
|
28
|
+
|
29
|
+
end_time = Time.now
|
30
|
+
running_time = end_time - start_time
|
31
|
+
puts "time: #{running_time} sec."
|
32
|
+
|
33
|
+
puts 'Done'
|
@@ -0,0 +1,36 @@
|
|
1
|
+
|
2
|
+
require 'spreadsheet'
|
3
|
+
|
4
|
+
start_time = Time.now
|
5
|
+
|
6
|
+
# ============================================
|
7
|
+
# =========== Read Example ===============
|
8
|
+
# ============================================
|
9
|
+
|
10
|
+
# Note: spreadsheet only supports .xls files (not .xlsx)
|
11
|
+
workbook = Spreadsheet.open './sample_excel_files/xls_25000_rows.xls'
|
12
|
+
|
13
|
+
worksheets = workbook.worksheets
|
14
|
+
puts "Found #{worksheets.count} worksheets"
|
15
|
+
|
16
|
+
|
17
|
+
worksheets.each do |worksheet|
|
18
|
+
puts "Reading: #{worksheet.name}"
|
19
|
+
num_rows = 0
|
20
|
+
|
21
|
+
worksheet.rows.each do |row|
|
22
|
+
row_cells = row.to_a.map{ |v| v.methods.include?(:value) ? v.value : v }
|
23
|
+
num_rows += 1
|
24
|
+
|
25
|
+
# uncomment to print out row values
|
26
|
+
# puts row_cells.join " "
|
27
|
+
end
|
28
|
+
puts "Read #{num_rows} rows"
|
29
|
+
end
|
30
|
+
|
31
|
+
end_time = Time.now
|
32
|
+
running_time = end_time - start_time
|
33
|
+
puts "time: #{running_time} sec."
|
34
|
+
|
35
|
+
|
36
|
+
puts 'Done'
|
data/bin/jreo
ADDED
data/bin/reo
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# -*- mode: ruby -*-
|
3
|
+
|
4
|
+
require 'robust_excel_ole'
|
5
|
+
include REO
|
6
|
+
# include RobustExcelOle
|
7
|
+
include General
|
8
|
+
|
9
|
+
require 'irb'
|
10
|
+
require 'irb/completion'
|
11
|
+
require 'irb/ext/save-history'
|
12
|
+
|
13
|
+
ARGV.concat ['--readline',
|
14
|
+
'--prompt-mode',
|
15
|
+
'simple']
|
16
|
+
|
17
|
+
# 250 entries in the list
|
18
|
+
IRB.conf[:SAVE_HISTORY] = 250
|
19
|
+
|
20
|
+
# Store results in home directory with specified file name
|
21
|
+
# IRB.conf[:HISTORY_FILE] = "#{ENV['HOME']}/.irb-history"
|
22
|
+
IRB.conf[:HISTORY_FILE] = "#{ENV['HOME']}/.reo-history"
|
23
|
+
|
24
|
+
# @private
|
25
|
+
module Readline
|
26
|
+
module Hist
|
27
|
+
LOG = IRB.conf[:HISTORY_FILE]
|
28
|
+
# LOG = "#{ENV['HOME']}/.irb-history"
|
29
|
+
|
30
|
+
def self.write_log(line)
|
31
|
+
File.open(LOG, 'ab') do |f|
|
32
|
+
f << "#{line}
|
33
|
+
"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.start_session_log
|
38
|
+
timestamp = proc { Time.now.strftime('%Y-%m-%d, %H:%M:%S') }
|
39
|
+
# @private
|
40
|
+
class <<timestamp
|
41
|
+
alias_method :to_s, :call
|
42
|
+
end
|
43
|
+
write_log("###### session start: #{timestamp}")
|
44
|
+
at_exit { write_log("###### session stop: #{timestamp}") }
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
alias old_readline readline
|
49
|
+
def readline(*args)
|
50
|
+
ln = old_readline(*args)
|
51
|
+
begin
|
52
|
+
Hist.write_log(ln)
|
53
|
+
rescue StandardError
|
54
|
+
end
|
55
|
+
ln
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
Readline::Hist.start_session_log
|
60
|
+
puts 'REO console started'
|
61
|
+
IRB.start
|
data/docs/README_ranges.rdoc
CHANGED
@@ -377,43 +377,7 @@ or
|
|
377
377
|
|
378
378
|
worksheet.set_cellval(1,1,"new_value")
|
379
379
|
|
380
|
-
=== Accessing rows and columns
|
381
380
|
|
382
|
-
The methods Worksheet#each, Worksheet#each_row and Worksheet#each_column enable to access each cell, row and column, respectively.
|
383
|
-
|
384
|
-
worksheet.each do |cell|
|
385
|
-
# do something with cell
|
386
|
-
# read every row, every column
|
387
|
-
end
|
388
|
-
|
389
|
-
worksheet.each_row do |row|
|
390
|
-
# do something with row
|
391
|
-
end
|
392
|
-
|
393
|
-
worksheet.each_column do |column|
|
394
|
-
# do something with column
|
395
|
-
end
|
396
|
-
|
397
|
-
The method Worksheet#each_value accesses the values of each row.
|
398
|
-
|
399
|
-
worksheet.each_value do |row_values|
|
400
|
-
# do something with the row_values
|
401
|
-
end
|
402
|
-
|
403
|
-
You access a range of a row by giving the number of the row, and optionally, the range of the cell numbers.
|
404
|
-
|
405
|
-
worksheet.row_range(1) # => first row
|
406
|
-
worksheet.row_range(1, 1..3 ) # => first three cells of the first row
|
407
|
-
|
408
|
-
Simarly you can access a range of a column.
|
409
|
-
|
410
|
-
worksheet.col_range(3) # => third column
|
411
|
-
worksheet.col_range(3, 1..2) # => first two cells of the third column
|
412
|
-
|
413
|
-
Within a row or column range you can access a certain cell.
|
414
|
-
|
415
|
-
row_range[1] # => first cell in row_range
|
416
|
-
column_range[2] # => second cell in column_range
|
417
381
|
|
418
382
|
== Code
|
419
383
|
|
data/docs/README_sheet.rdoc
CHANGED
@@ -75,6 +75,78 @@ If you want to copy a worksheet, if a worksheet +sheet+ is given, and add an emp
|
|
75
75
|
|
76
76
|
Note, that running in jruby, due to some restrictions of jruby, there is a workaround when adding or copy a worksheet at the end (appending): the last worksheet is being copied and deleted afterwards, in order to serve as a dummy worksheet. This may cause a different behaviour.
|
77
77
|
|
78
|
+
=== Accessing rows and columns
|
79
|
+
|
80
|
+
The methods Worksheet#each, Worksheet#each_row and Worksheet#each_column enable to access each cell, row and column, respectively.
|
81
|
+
|
82
|
+
worksheet.each do |cell|
|
83
|
+
# do something with cell
|
84
|
+
# read every row, every column
|
85
|
+
end
|
86
|
+
|
87
|
+
worksheet.each_row do |row|
|
88
|
+
# do something with row
|
89
|
+
end
|
90
|
+
|
91
|
+
worksheet.each_column do |column|
|
92
|
+
# do something with column
|
93
|
+
end
|
94
|
+
|
95
|
+
The method Worksheet#values yields all cell values of the used range of the worksheet into a 2-dimensional array. For example:
|
96
|
+
|
97
|
+
worksheet.values
|
98
|
+
=> [["foo", "workbook", "sheet1"], ["foo", nil, "foobaaa"], ["matz", "is", "nice"]]
|
99
|
+
|
100
|
+
The method Worksheet#each_rowvalue provides enable to access the values of each row.
|
101
|
+
|
102
|
+
worksheet.each_rowvalue do |row_values|
|
103
|
+
# do something with the row_values
|
104
|
+
end
|
105
|
+
|
106
|
+
You access a range of a row by giving the number of the row, and optionally, the range of the cell numbers.
|
107
|
+
|
108
|
+
worksheet.row_range(1) # => first row
|
109
|
+
worksheet.row_range(1, 1..3 ) # => first three cells of the first row
|
110
|
+
|
111
|
+
Reading the values is enabled with help of #values:
|
112
|
+
|
113
|
+
worksheet.row_range(1).values
|
114
|
+
|
115
|
+
Simarly you can access a range of a column.
|
116
|
+
|
117
|
+
worksheet.col_range(3) # => third column
|
118
|
+
worksheet.col_range(3, 1..2) # => first two cells of the third column
|
119
|
+
|
120
|
+
Within a row or column range you can access a certain cell.
|
121
|
+
|
122
|
+
row_range[1] # => first cell in row_range
|
123
|
+
column_range[2] # => second cell in column_range
|
124
|
+
|
125
|
+
=== Deleting and inserting rows and columns
|
126
|
+
|
127
|
+
As mentioned above, VBA methods can be applied to the RobustExcelOle objects, e.g. when deleting or inserting rows and columns.
|
128
|
+
|
129
|
+
row1 = worksheet.row_range(1)
|
130
|
+
row1.Delete
|
131
|
+
|
132
|
+
row1.Insert(XlShiftDown,XlFormatFromLeftOrAbove)
|
133
|
+
|
134
|
+
col1 = worksheet.col_range(1)
|
135
|
+
col1.Insert
|
136
|
+
|
137
|
+
=== Getting and setting row height and column width
|
138
|
+
|
139
|
+
row_hight = row1.RowHight
|
140
|
+
row1.RowHeight = row_hight * 2
|
141
|
+
|
142
|
+
col_width = col1.ColumnWidth
|
143
|
+
col1.ColumnWidth = col_width * 2
|
144
|
+
|
145
|
+
=== Vertical and horizontal alignment of contents of rows
|
146
|
+
|
147
|
+
row1.VerticalAlignment = XlVAlignCenter
|
148
|
+
row1.HorizontalAlignment = XlHAlignLeft
|
149
|
+
|
78
150
|
== Code
|
79
151
|
|
80
152
|
worksheet.rb[https://github.com/Thomas008/robust_excel_ole/blob/master/lib/robust_excel_ole/worksheet.rb]
|
data/lib/reo_console.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
|
-
|
1
|
+
require '../robust_excel_ole/lib/robust_excel_ole'
|
2
2
|
include REO
|
3
3
|
# include RobustExcelOle
|
4
4
|
include General
|
5
5
|
|
6
|
+
require 'irb'
|
6
7
|
require 'irb/completion'
|
7
8
|
require 'irb/ext/save-history'
|
8
9
|
|
@@ -17,6 +18,10 @@ IRB.conf[:SAVE_HISTORY] = 250
|
|
17
18
|
# IRB.conf[:HISTORY_FILE] = "#{ENV['HOME']}/.irb-history"
|
18
19
|
IRB.conf[:HISTORY_FILE] = "#{ENV['HOME']}/.reo-history"
|
19
20
|
|
21
|
+
IRB.conf[:PROMPT_MODE] = 'ert' #:SIMPLE
|
22
|
+
#IRB.conf[:USE_READLINE] = true
|
23
|
+
#IRB.conf[:AUTO_INDENT] = true
|
24
|
+
|
20
25
|
# @private
|
21
26
|
module Readline
|
22
27
|
module Hist
|
@@ -54,3 +59,5 @@ end
|
|
54
59
|
|
55
60
|
Readline::Hist.start_session_log
|
56
61
|
puts 'REO console started'
|
62
|
+
IRB.start
|
63
|
+
|
@@ -109,11 +109,10 @@ module RobustExcelOle
|
|
109
109
|
# @params row and column
|
110
110
|
# @returns value of the cell
|
111
111
|
def cellval(x,y)
|
112
|
-
xy = "#{x}_#{y}"
|
113
112
|
begin
|
114
113
|
@ole_worksheet.Cells.Item(x, y).Value
|
115
114
|
rescue
|
116
|
-
raise RangeNotEvaluatable, "cannot read cell (#{
|
115
|
+
raise RangeNotEvaluatable, "cannot read cell (#{x.inspect},#{y.inspect})"
|
117
116
|
end
|
118
117
|
end
|
119
118
|
|
@@ -122,7 +121,7 @@ module RobustExcelOle
|
|
122
121
|
xy = "#{x}_#{y}"
|
123
122
|
@cells = { }
|
124
123
|
begin
|
125
|
-
@cells[xy]
|
124
|
+
@cells[xy] ||= RobustExcelOle::Cell.new(@ole_worksheet.Cells.Item(x, y), @worksheet)
|
126
125
|
@cells[xy].Value
|
127
126
|
rescue
|
128
127
|
raise RangeNotEvaluatable, "cannot read cell (#{p1.inspect},#{p2.inspect})"
|
@@ -141,6 +140,10 @@ module RobustExcelOle
|
|
141
140
|
raise RangeNotEvaluatable, "cannot assign value #{value.inspect} to cell (#{y.inspect},#{x.inspect})"
|
142
141
|
end
|
143
142
|
|
143
|
+
def values
|
144
|
+
@ole_worksheet.UsedRange.Value
|
145
|
+
end
|
146
|
+
|
144
147
|
def each
|
145
148
|
each_row do |row_range|
|
146
149
|
row_range.each do |cell|
|
@@ -159,13 +162,17 @@ module RobustExcelOle
|
|
159
162
|
end
|
160
163
|
end
|
161
164
|
|
162
|
-
def
|
165
|
+
def each_rowvalue
|
163
166
|
@ole_worksheet.UsedRange.Value.each do |row_values|
|
164
167
|
yield row_values
|
165
168
|
end
|
166
169
|
end
|
167
170
|
|
168
|
-
def
|
171
|
+
def each_value # :deprecated: #
|
172
|
+
each_rowvalue
|
173
|
+
end
|
174
|
+
|
175
|
+
def each_rowvalue_with_index(offset = 0)
|
169
176
|
i = offset
|
170
177
|
@ole_worksheet.UsedRange.Value.each do |row_values|
|
171
178
|
yield row_values, i
|
data/reo.bat
CHANGED
data/robust_excel_ole.gemspec
CHANGED
@@ -34,6 +34,5 @@ Gem::Specification.new do |s|
|
|
34
34
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
35
35
|
s.require_paths = ["lib"]
|
36
36
|
s.add_development_dependency "rspec", '>= 2.6.0'
|
37
|
-
s.required_ruby_version = '>= 1
|
38
|
-
s.extensions << 'extconf.rb'
|
37
|
+
s.required_ruby_version = '>= 2.1'
|
39
38
|
end
|
data/spec/worksheet_spec.rb
CHANGED
@@ -295,17 +295,25 @@ describe Worksheet do
|
|
295
295
|
|
296
296
|
end
|
297
297
|
|
298
|
-
describe "#
|
298
|
+
describe "#values" do
|
299
|
+
|
300
|
+
it "should yield cell values of the used range" do
|
301
|
+
@sheet.values.should == [["foo", "workbook", "sheet1"], ["foo", nil, "foobaaa"], ["matz", "is", "nice"]]
|
302
|
+
end
|
303
|
+
|
304
|
+
end
|
305
|
+
|
306
|
+
describe "#each_rowvalue" do
|
299
307
|
|
300
308
|
it "should yield arrays" do
|
301
|
-
@sheet.
|
309
|
+
@sheet.each_rowvalue do |row_value|
|
302
310
|
row_value.should be_kind_of Array
|
303
311
|
end
|
304
312
|
end
|
305
313
|
|
306
314
|
it "should read the rows" do
|
307
315
|
i = 0
|
308
|
-
@sheet.
|
316
|
+
@sheet.each_rowvalue do |row_values|
|
309
317
|
case i
|
310
318
|
when 0
|
311
319
|
row_values.should == ['foo', 'workbook', 'sheet1']
|
@@ -317,7 +325,7 @@ describe Worksheet do
|
|
317
325
|
end
|
318
326
|
|
319
327
|
it "should read the rows with index" do
|
320
|
-
@sheet.
|
328
|
+
@sheet.each_rowvalue_with_index do |row_values, i|
|
321
329
|
case i
|
322
330
|
when 0
|
323
331
|
row_values.should == ['foo', 'workbook', 'sheet1']
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: robust_excel_ole
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.18.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- traths
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-06-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -33,9 +33,10 @@ description: "RobustExcelOle helps controlling Excel. \n This
|
|
33
33
|
are supported.\n It runs on Windows and uses the win32ole library."
|
34
34
|
email:
|
35
35
|
- Thomas.Raths@gmx.net
|
36
|
-
executables:
|
37
|
-
|
38
|
-
-
|
36
|
+
executables:
|
37
|
+
- jreo
|
38
|
+
- reo
|
39
|
+
extensions: []
|
39
40
|
extra_rdoc_files:
|
40
41
|
- README.rdoc
|
41
42
|
- LICENSE
|
@@ -51,6 +52,20 @@ files:
|
|
51
52
|
- Rakefile
|
52
53
|
- TodoList.md
|
53
54
|
- ___dummy_workbook.xls
|
55
|
+
- benchmarking/Gemfile
|
56
|
+
- benchmarking/README.md
|
57
|
+
- benchmarking/creek_example.rb
|
58
|
+
- benchmarking/generating_excel_files.rb
|
59
|
+
- benchmarking/reo_example.rb
|
60
|
+
- benchmarking/reo_example1.rb
|
61
|
+
- benchmarking/reo_example2.rb
|
62
|
+
- benchmarking/roo_example.rb
|
63
|
+
- benchmarking/ruby_xl_example.rb
|
64
|
+
- benchmarking/sample_excel_files/xlsx_500_rows.xlsx
|
65
|
+
- benchmarking/simple_xlsx_reader_example.rb
|
66
|
+
- benchmarking/spreadsheet_example.rb
|
67
|
+
- bin/jreo
|
68
|
+
- bin/reo
|
54
69
|
- docs/README_excel.rdoc
|
55
70
|
- docs/README_open.rdoc
|
56
71
|
- docs/README_ranges.rdoc
|
@@ -83,7 +98,6 @@ files:
|
|
83
98
|
- examples/open_save_close/example_reuse.rb
|
84
99
|
- examples/open_save_close/example_simple.rb
|
85
100
|
- examples/open_save_close/example_unobtrusively.rb
|
86
|
-
- extconf.rb
|
87
101
|
- jreo.bat
|
88
102
|
- lib/jreo_console.rb
|
89
103
|
- lib/reo_console.rb
|
@@ -103,6 +117,7 @@ files:
|
|
103
117
|
- lib/robust_excel_ole/version.rb
|
104
118
|
- lib/robust_excel_ole/workbook.rb
|
105
119
|
- lib/robust_excel_ole/worksheet.rb
|
120
|
+
- lib/rubygems_plugin.rb
|
106
121
|
- lib/spec_helper.rb
|
107
122
|
- reo.bat
|
108
123
|
- robust_excel_ole.gemspec
|
@@ -159,7 +174,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
159
174
|
requirements:
|
160
175
|
- - ">="
|
161
176
|
- !ruby/object:Gem::Version
|
162
|
-
version: 1
|
177
|
+
version: '2.1'
|
163
178
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
164
179
|
requirements:
|
165
180
|
- - ">="
|