to_xls 0.0.3 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/MIT-LICENSE +1 -1
  2. data/README.rdoc +11 -15
  3. data/lib/to_xls.rb +7 -0
  4. data/to_xls.gemspec +1 -1
  5. metadata +3 -3
@@ -1,4 +1,4 @@
1
- Copyright (c) 2009 Ary Djmal
1
+ Copyright (c) 2009 Ary Djmal, Enrique García, Francisco Juan
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
@@ -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.to_xls }
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
 
@@ -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)
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = %q{to_xls}
3
- s.version = "0.0.3"
3
+ s.version = "0.1.0"
4
4
 
5
5
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
6
6
  s.authors = ["Enrique Garcia Cota", "Francisco de Juan"]
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: 25
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
+ - 1
8
9
  - 0
9
- - 3
10
- version: 0.0.3
10
+ version: 0.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Enrique Garcia Cota