We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 6f5608a commit b3e9db6Copy full SHA for b3e9db6
lib/excelerator/phoenix.ex
@@ -0,0 +1,17 @@
1
+defmodule Excelerator.Phoenix do
2
+ defmacro __using__(options) do
3
+ quote do
4
+ def xls(conn, template, data, opts \\ []) do
5
+ excel_data = view_module(conn).render(template, data)
6
+
7
+ default_filename = Phoenix.Naming.resource_name(__MODULE__, "Controller") <> ".xls"
8
+ filename = Keyword.get(opts, :filename, default_filename)
9
10
+ conn
11
+ |> put_resp_content_type("application/vnd.ms-excel")
12
+ |> put_resp_header("content-disposition", "attachment; filename=#{ filename }")
13
+ |> send_resp(conn.status || 200, excel_data)
14
+ end
15
16
17
+end
0 commit comments