to_xls 0.0.3 → 0.1.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.
- data/MIT-LICENSE +1 -1
- data/README.rdoc +11 -15
- data/lib/to_xls.rb +7 -0
- data/to_xls.gemspec +1 -1
- metadata +3 -3
data/MIT-LICENSE
CHANGED
data/README.rdoc
CHANGED
@@ -6,16 +6,22 @@ This gem transform an Array into a excel file using the spreadsheet gem.
|
|
6
6
|
|
7
7
|
@users = User.all
|
8
8
|
|
9
|
-
#
|
10
|
-
# defaults are export headers and all fields
|
11
|
-
#
|
12
|
-
|
13
9
|
@users.to_xls
|
14
10
|
@users.to_xls(:headers => false)
|
15
11
|
@users.to_xls(:columns => [:name, :role])
|
16
12
|
@users.to_xls(:columns => [:name, {:company => [:name, :address]}])
|
17
13
|
@users.to_xls(:columns => [:name, {:company => [:name, :address]}], :headers => [:name, :company, :address])
|
18
14
|
|
15
|
+
In order to send a file from the controller, you can save it on your server first:
|
16
|
+
|
17
|
+
@users.to_xls.write '/path/to/file/users.xls'
|
18
|
+
send_file '/path/to/file/users.xls'
|
19
|
+
|
20
|
+
Alternatively you can use the method to_xls_data and send_data
|
21
|
+
|
22
|
+
send_data @users.to_xls_data, :filename => 'users.xls'
|
23
|
+
|
24
|
+
The method to_xls_data accepts the same parameters as to_xls.
|
19
25
|
|
20
26
|
== Requirements
|
21
27
|
|
@@ -35,17 +41,9 @@ In the controller where you want to export to excel, add the format.xls line.
|
|
35
41
|
respond_to do |format|
|
36
42
|
format.html
|
37
43
|
format.xml { render :xml => @users }
|
38
|
-
format.xls { send_data @users.
|
44
|
+
format.xls { send_data @users.to_xls_data, :filename => 'users.xls' }
|
39
45
|
end
|
40
46
|
end
|
41
|
-
|
42
|
-
def show...
|
43
|
-
def new...
|
44
|
-
def edit...
|
45
|
-
def create...
|
46
|
-
def update...
|
47
|
-
def destroy...
|
48
|
-
|
49
47
|
end
|
50
48
|
|
51
49
|
|
@@ -53,11 +51,9 @@ In the controller where you want to export to excel, add the format.xls line.
|
|
53
51
|
|
54
52
|
spreadsheet gem
|
55
53
|
|
56
|
-
|
57
54
|
== Install
|
58
55
|
|
59
56
|
Include next gems in your environment.rb config file:
|
60
57
|
|
61
|
-
config.gem 'spreadsheet'
|
62
58
|
config.gem 'to_xls'
|
63
59
|
|
data/lib/to_xls.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'spreadsheet'
|
3
|
+
require 'stringio'
|
3
4
|
|
4
5
|
class Array
|
5
6
|
# Options for to_xls: columns, name, header
|
@@ -36,6 +37,12 @@ class Array
|
|
36
37
|
return book
|
37
38
|
end
|
38
39
|
|
40
|
+
def to_xls_data(options = {})
|
41
|
+
data = StringIO.new('')
|
42
|
+
self.to_xls(options).write(data)
|
43
|
+
return data.string
|
44
|
+
end
|
45
|
+
|
39
46
|
private
|
40
47
|
def aux_to_xls(item, column, row)
|
41
48
|
if column.is_a?(String) or column.is_a?(Symbol)
|
data/to_xls.gemspec
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: to_xls
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
+
- 1
|
8
9
|
- 0
|
9
|
-
|
10
|
-
version: 0.0.3
|
10
|
+
version: 0.1.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Enrique Garcia Cota
|