export_to_spreadsheet 0.1.2 → 0.2.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/lib/export_to_spreadsheet.rb +2 -2
- data/lib/sales_clic_exporter/base.rb +1 -2
- metadata +3271 -6620
- data/CHANGELOG +0 -3
- data/MIT-LICENSE +0 -20
- data/Manifest +0 -3354
- data/README.rdoc +0 -267
- data/Rakefile +0 -23
- data/export_to_spreadsheet.gemspec +0 -54
- data/init.rb +0 -3
- data/install.rb +0 -2
- data/test/excel_test.rb +0 -308
- data/test/google_spreadsheets_test.rb +0 -337
- data/test/resources/invalid_excel_import_with_duplicates_values.xls +0 -0
- data/test/resources/invalid_file_format.txt +0 -1
- data/test/resources/valid_excel_import.xls +0 -0
- data/test/spreadsheet_to_array_test.rb +0 -30
- data/test/test_helper.rb +0 -47
data/README.rdoc
DELETED
@@ -1,267 +0,0 @@
|
|
1
|
-
= ExportToSpreadsheet
|
2
|
-
|
3
|
-
This plugin allows to add some export functionalities to a Rails Application. The supported output formats are Microsoft Excel and Google Spreadsheets.
|
4
|
-
|
5
|
-
== Dependencies
|
6
|
-
|
7
|
-
It requires both JAVA (JDK and JRE) and the following gems :
|
8
|
-
- portablecontacts
|
9
|
-
- google-spreadsheet-ruby
|
10
|
-
- RJB
|
11
|
-
- oauth
|
12
|
-
- oauth-plugin
|
13
|
-
- restful-authentication
|
14
|
-
- highline
|
15
|
-
|
16
|
-
Apache POI is also necessary but provided with this plugin.
|
17
|
-
|
18
|
-
Depending on the target plateform (Linux, Mac or Windows), RJB could require some path configuration, see http://rjb.rubyforge.org/
|
19
|
-
|
20
|
-
For the documentation generation the yard gem is required : https://github.com/lsegal/yard
|
21
|
-
|
22
|
-
An optionnal rake task to clean the generated files was created : rake cron:tidy_exported_tmp_files
|
23
|
-
|
24
|
-
== General installation remark
|
25
|
-
|
26
|
-
You need to set the JAVA_HOME environment variable either directly in your system or in a ruby file contained in config/initializers/ where you would write for example :
|
27
|
-
|
28
|
-
ENV['JAVA_HOME'] = "/opt/SDK/jdk"
|
29
|
-
|
30
|
-
In some OS (seen in Windows), you might also have to set the CLASS_PATH adding the POI jar files :
|
31
|
-
|
32
|
-
ENV['CLASS_PATH'] = .;D:\PATH_TO_APACHE_POI\lib\apache-poi-3.7\poi-3.7-beta2-20100630.jar;D:\PATH_TO_APACHE_POI\lib\apache-poi-3.7\poi-contrib-3.7-beta2-20100630.jar;D:\PATH_TO_APACHE_POI\lib\apache-poi-3.7\poi-ooxml-3.7-beta2-20100630.jar;D:\PATH_TO_APACHE_POI\lib\apache-poi-3.7\poi-ooxml-schemas-3.7-beta2-20100630.jar;D:\PATH_TO_APACHE_POI\lib\apache-poi-3.7\poi-scratchpad-3.7-beta2-20100630.jar;C:\Program Files (x86)\Java\jre6\lib\ext\QTJava.zip
|
33
|
-
|
34
|
-
After installing the oauth-plugin (for Google Spreadsheet support), you need to generate a consumer : (check oauth -plugin documentation for full details)
|
35
|
-
|
36
|
-
RAILS_ROOT/script/generate oauth_consumer
|
37
|
-
rake db:migrate
|
38
|
-
|
39
|
-
== Installation on a production server with Apache and Passenger
|
40
|
-
|
41
|
-
Passenger has to be launched with the same user as the application files' owner to be able to write files into RAILS_ROOT/tmp
|
42
|
-
|
43
|
-
To customize this, add the following line in /etc/apache2/mods-enabled/passenger.conf :
|
44
|
-
|
45
|
-
PassengerDefaultUser app_user
|
46
|
-
|
47
|
-
== Tests
|
48
|
-
|
49
|
-
The tests of this plugin requires a Google account.
|
50
|
-
|
51
|
-
= Getting started
|
52
|
-
|
53
|
-
A full sample that uses the plugin is available here: https://github.com/nimbleapps/export_to_spreadsheet_sample_app/
|
54
|
-
|
55
|
-
The tutorial below allows you to re-build this sample step by step.
|
56
|
-
|
57
|
-
== Simple Excel export
|
58
|
-
|
59
|
-
Once the plugin is installed (see Installation section for that), you can do the following to get a valid Excel export in 10 steps :
|
60
|
-
|
61
|
-
1/ Create your Rails app :
|
62
|
-
|
63
|
-
rails my_application
|
64
|
-
|
65
|
-
2/ Add the reference to the gem in your config/environment.rb :
|
66
|
-
|
67
|
-
config.gem "export_to_spreadsheet"
|
68
|
-
|
69
|
-
3/ Generate a scaffold (for instance a User one) :
|
70
|
-
|
71
|
-
ruby script/generate scaffold User first_name:string last_name:string
|
72
|
-
|
73
|
-
4/ Perform the migration to create the SQL table :
|
74
|
-
|
75
|
-
rake db:migrate
|
76
|
-
|
77
|
-
5/ Launch your server, go to your app URL (http://localhost:3000/users)
|
78
|
-
|
79
|
-
6/ Use the interface to add some users.
|
80
|
-
|
81
|
-
7/ Add a class in your models to perform the export, this class has to include the plugin :
|
82
|
-
|
83
|
-
class UserExporter
|
84
|
-
include ExportToSpreadsheet
|
85
|
-
|
86
|
-
# Actually building the output file whatever the format
|
87
|
-
def compose_export
|
88
|
-
@doc.write do |d|
|
89
|
-
d.title_1("Sample Title User Export").title_2("We are going to export the users")
|
90
|
-
d.title_3("Date : " + Date.today.to_s)
|
91
|
-
d.newline.newline.freezepane
|
92
|
-
keys_array = ["First Name", "Last Name"]
|
93
|
-
values = []
|
94
|
-
User.all.each_with_index do |user,i|
|
95
|
-
values << [user.first_name, user.last_name]
|
96
|
-
end
|
97
|
-
d.h_table(values, keys_array, {:border_bottom => true})
|
98
|
-
d.newline.newline
|
99
|
-
end
|
100
|
-
@doc.save
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
8/ In the User controller, add a method for the export and the download of the document :
|
105
|
-
|
106
|
-
def export
|
107
|
-
# Option which is handled by default by the plugin
|
108
|
-
options = {:filename => "Users Export Example"}
|
109
|
-
u_e = UserExporter.new
|
110
|
-
export = u_e.to_excel(options)
|
111
|
-
download export.path
|
112
|
-
end
|
113
|
-
|
114
|
-
private
|
115
|
-
def download(server_file_path)
|
116
|
-
send_file server_file_path
|
117
|
-
rescue => e
|
118
|
-
raise Exception, "File not found. Please ensure that your file was saved. Error was: #{e}"
|
119
|
-
end
|
120
|
-
|
121
|
-
9/ Modify the routes.rb file to map this new action :
|
122
|
-
|
123
|
-
map.resources :users, :collection => { :export => :get }
|
124
|
-
|
125
|
-
10/ Congratulations ! You can now export all the users in an Excel Spreadsheet using the link : http://localhost:3000/users/export
|
126
|
-
|
127
|
-
== Advanced Spreadsheet export capabilities
|
128
|
-
|
129
|
-
Your first export worked. Now, what if you want to add a parameter to your export such as the number of users to export.
|
130
|
-
|
131
|
-
Let's do this :
|
132
|
-
|
133
|
-
1/ Modify your export export action in the users controller :
|
134
|
-
|
135
|
-
def export
|
136
|
-
export_format = params[:export_format]
|
137
|
-
records_nb_to_export = params[:records_nb_to_export]
|
138
|
-
|
139
|
-
# first option which is handled by default by the plugin
|
140
|
-
options = {:filename => "Users Export Example"}
|
141
|
-
# adding an option which is personalized in lib/personalized_export_properties
|
142
|
-
options.merge!({:records_nb_to_export => records_nb_to_export})
|
143
|
-
u_e = UserExporter.new
|
144
|
-
if export_format == "excel"
|
145
|
-
export = u_e.to_excel(options)
|
146
|
-
download export.path
|
147
|
-
end
|
148
|
-
|
149
|
-
end
|
150
|
-
|
151
|
-
2/ Modify the routes to handle these new parameters
|
152
|
-
|
153
|
-
map.resources :users
|
154
|
-
map.connect 'users/export/:export_format/:records_nb_to_export', :controller => 'users', :action => 'export'
|
155
|
-
|
156
|
-
3/ Add a plugin customization to handle this records_nb_to_export parameter. To do so, add a file before_prepare_export.rb in your lib folder and add the following code :
|
157
|
-
|
158
|
-
module ExportToSpreadsheet
|
159
|
-
|
160
|
-
# Configures export before generating a document
|
161
|
-
def before_prepare_export_first(target, options = {})
|
162
|
-
@records_nb_to_export = (options && ! options.empty?) ? options.delete(:records_nb_to_export) : nil
|
163
|
-
return options
|
164
|
-
end
|
165
|
-
|
166
|
-
end
|
167
|
-
|
168
|
-
|
169
|
-
4/ Change the ExportUser class where the variable @records_nb_to_export is now available :
|
170
|
-
|
171
|
-
class UserExporter
|
172
|
-
include ExportToSpreadsheet
|
173
|
-
|
174
|
-
# Actually building the output file whatever the format
|
175
|
-
def compose_export
|
176
|
-
@doc.write do |d|
|
177
|
-
d.title_1("Sample Title User Export").title_2("We are going to export the first #{@records_nb_to_export} users")
|
178
|
-
d.title_3("Date : " + Date.today.to_s)
|
179
|
-
d.newline.newline.freezepane
|
180
|
-
keys_array = ["First Name", "Last Name"]
|
181
|
-
values = []
|
182
|
-
User.all.each_with_index do |user,i|
|
183
|
-
if i < @records_nb_to_export.to_i
|
184
|
-
values << [user.first_name, user.last_name]
|
185
|
-
else
|
186
|
-
break
|
187
|
-
end
|
188
|
-
end
|
189
|
-
d.h_table(values, keys_array, {:border_bottom => true})
|
190
|
-
d.newline.newline
|
191
|
-
end
|
192
|
-
@doc.save
|
193
|
-
end
|
194
|
-
end
|
195
|
-
|
196
|
-
5/ Congratulations ! You can now export some data based on any users input parameter following this example. To check the example, visit http://localhost:3000/users/export/excel/3 which will export the three first users.
|
197
|
-
|
198
|
-
|
199
|
-
== Google Spreadsheet export
|
200
|
-
|
201
|
-
To perform the Google Spreadsheet export, you need to follow the bellow :
|
202
|
-
|
203
|
-
1/ Ensure the oauth_consumer script run properly. (See General installation remark)
|
204
|
-
|
205
|
-
2/ Follow the documentation of oauth and oauth-plugin gems to manage the oauth permission process.
|
206
|
-
Among the required steps, don't forget to add your application credentials (the credentials it uses to connect to Google Apps) in the file config/initializers/oauth_consumers.rb :
|
207
|
-
|
208
|
-
OAUTH_CREDENTIALS = {
|
209
|
-
:google => {
|
210
|
-
:key => 'your_key',
|
211
|
-
:secret => 'your_secret',
|
212
|
-
:scope => 'https://docs.google.com/feeds/ https://spreadsheets.google.com/feeds/ https://www.google.com/m8/feeds/ https://www.google.com/calendar/feeds/',
|
213
|
-
:options => {
|
214
|
-
:site => 'https://www.google.com',
|
215
|
-
:request_token_path => '/accounts/OAuthGetRequestToken',
|
216
|
-
:access_token_path => '/accounts/OAuthGetAccessToken',
|
217
|
-
:authorize_path => '/accounts/OAuthAuthorizeToken',
|
218
|
-
:signature_method => 'HMAC-SHA1'
|
219
|
-
}
|
220
|
-
}
|
221
|
-
}
|
222
|
-
|
223
|
-
3/ Modify the export action of the user controller :
|
224
|
-
|
225
|
-
def export
|
226
|
-
export_format = params[:export_format]
|
227
|
-
records_nb_to_export = params[:records_nb_to_export]
|
228
|
-
|
229
|
-
# first option which is handled by default by the plugin
|
230
|
-
options = {:filename => "Users Export Example"}
|
231
|
-
# adding an option which is personalized in lib/personalized_export_properties
|
232
|
-
options.merge!({:records_nb_to_export => records_nb_to_export})
|
233
|
-
u_e = UserExporter.new
|
234
|
-
if export_format == "google"
|
235
|
-
# assuming the user's token is the first one in the table
|
236
|
-
google_token_client = GoogleToken.first.client
|
237
|
-
export = u_e.to_google_spreadsheets({:access_token => google_token_client}.merge options)
|
238
|
-
render :text => "Generation Complete. Check your Google Apps account."
|
239
|
-
elsif export_format == "excel"
|
240
|
-
export = u_e.to_excel(options)
|
241
|
-
download export.path
|
242
|
-
end
|
243
|
-
|
244
|
-
end
|
245
|
-
|
246
|
-
4/ Congratulations ! You can now export also spreadsheet in a Google account. To check the example, visit http://localhost:3000/users/export/google/3 which will export the three first users in a Google Spreadsheet.
|
247
|
-
|
248
|
-
|
249
|
-
= Environments
|
250
|
-
|
251
|
-
Tested on Rails 2.3.8 and Ruby 1.8.7.
|
252
|
-
|
253
|
-
= Version
|
254
|
-
|
255
|
-
0.1.1 (2011)
|
256
|
-
|
257
|
-
= Disclaimer
|
258
|
-
|
259
|
-
This plugin was originaly written by Michel Pigassou and published by Nimble Apps Limited.
|
260
|
-
http://www.salesclic.com
|
261
|
-
|
262
|
-
At the time of the publication, the core features of the plugin are fully functional. Yet, Nimble Apps does not consider it as complete.
|
263
|
-
We are sure that many enhancements can be made to the plugin and hope you will contribute to it.
|
264
|
-
|
265
|
-
= Licence
|
266
|
-
|
267
|
-
MIT license
|
data/Rakefile
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'rake'
|
3
|
-
require 'rake/testtask'
|
4
|
-
require 'yard'
|
5
|
-
require 'echoe'
|
6
|
-
|
7
|
-
Echoe.new('export_to_spreadsheet') do |p|
|
8
|
-
# The version can be specified as a 2nd argument after the name, or completly left (in this case
|
9
|
-
# the last version in the CHANGELOG file will be used)
|
10
|
-
p.version = '0.1.2'
|
11
|
-
p.description = "Export model data to Google Spreadsheets or Excel through Apache POI"
|
12
|
-
p.url = "http://github.com/nimbleapps/export-to-spreadsheet"
|
13
|
-
p.author = "Nimble Apps"
|
14
|
-
p.email = "dev@nimble-apps.com"
|
15
|
-
p.ignore_pattern = ["tmp/*", "script/*"]
|
16
|
-
p.runtime_dependencies = ['portablecontacts', 'google-spreadsheet-ruby >=0.1.5', 'rjb', 'oauth', 'oauth-plugin']
|
17
|
-
p.development_dependencies = ['yard', 'highline', 'active_support']
|
18
|
-
end
|
19
|
-
|
20
|
-
desc 'Generate documentation for the export_to_files plugin using yard.'
|
21
|
-
YARD::Rake::YardocTask.new do |t|
|
22
|
-
t.files = ['lib/**/*.rb', 'README', 'CHANGELOG']
|
23
|
-
end
|