-
Notifications
You must be signed in to change notification settings - Fork 3
/
README
72 lines (44 loc) · 1.88 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
EXCELlent is a custom template handler (XERB) for specifying XLS files just as regular XHTML tables.
This is kind of limited at the moment, but damn - this is 0.0.1 alpha release :)
Currently EXCELlent (or XERB) supports
* table, tr, td, th tags
* table name property for naming sheet
* font-size, font-weight, background-color and color css attributes of cells
First things first - installation
ruby script/plugin install git://github.com/stevo/excellent.git
EXCELlent relies on spreadsheet and nokogiri gems, so if you haven't already...
gem install spreadsheet
gem install nokogiri
Then in your controller, add new respond_to format
def index
@fruits = [{:name => "apple", :color => "green"},{:name => "peach", :color => "orange"}]
respond_to do |format|
format.html
format.xml { render :xml => @fruits }
format.xls # Here it is !
end
end
Then we need our view. Just create file named index.xls.xerb and create a simple table
<table name="Fruits">
<tr>
<td></td>
<td></td>
</tr>
<tr>
<td style="font-size:20px;">Name</td>
<td>Color</td>
</tr>
<% @fruits.each do |fruit| %>
<tr>
<td style="color:red;font-weight:bold;"><%= fruit[:name] %></td>
<td><%= fruit[:color] %></td>
</tr>
<% end %>
</table>
From now on, simple link
<%= link_to 'xls', fruits_path(:format => :xls) %>
will enable you to download Excel version of your table :)
Styling issues:
For unknown reason executing spreadsheet::row::set_format method on the first row and it's last cell make whole
last column disappeared in the result file. Because of it styling in the first row is currently ignored.
Copyright (c) 2009 [email protected] [Stevo], released under the MIT license