Skip to content

Commit 7ca53a1

Browse files
committed
update README
1 parent b3e9db6 commit 7ca53a1

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

README.md

+60
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,63 @@ If [available in Hex](https://hex.pm/docs/publish), the package can be installed
1111
def deps do
1212
[{:excelerator, "~> 0.0.1"}]
1313
end
14+
15+
## Usage
16+
17+
1. Import `Excelerator.Workbook` into your module, then generate the XML content:
18+
19+
workbook do
20+
worksheet "My Sheet" do
21+
row do
22+
cell "Name"
23+
cell "Status"
24+
end
25+
26+
row do
27+
cell "Elixir"
28+
cell 1
29+
end
30+
end
31+
end
32+
33+
# => <?xml version="1.0" encoding="UTF-8" ?><Workbook ...
34+
35+
## Usage with Phoenix
36+
37+
1. Use `Excelerator.Phoenix` in your controller:
38+
39+
defmodule MyApp.MyController do
40+
use MyApp.Web, :controller
41+
use Excelerator.Phoenix
42+
43+
1. Import `Excelerator.Workbook` into your view module:
44+
45+
defmodule MyApp.MyView do
46+
use MyApp.Web, :view
47+
import Excelerator.Workbook
48+
49+
1. Alternatively, add the use / import statements to the appropriate sections
50+
of `web/web.ex`, which will make excelerator available in all controllers/
51+
views.
52+
53+
1. Call `xls` in your controller action to send content as a file download:
54+
55+
def show(conn, %{"format" => "xls"} = params) do
56+
xls conn, "show.xls", favorite: "Elixir"
57+
end
58+
59+
1. Create `web/templates/RESOURCE/NAME.xls.exs`
60+
61+
workbook do
62+
worksheet "My Sheet" do
63+
row do
64+
cell "Name"
65+
cell "Status"
66+
end
67+
68+
row do
69+
cell assigns.favorite
70+
cell 1
71+
end
72+
end
73+
end

0 commit comments

Comments
 (0)