Excel spreadsheet generation for Elixir
If available in Hex, the package can be installed as:
-
Add excelerator to your list of dependencies in
mix.exs:def deps do [{:excelerator, "~> 0.0.1"}] end
-
Import
Excelerator.Workbookinto your module, then generate the XML content:workbook do worksheet "My Sheet" do row do cell "Name" cell "Status" end
row do cell "Elixir" cell 1 end endend
-
Use
Excelerator.Phoenixin your controller:defmodule MyApp.MyController do use MyApp.Web, :controller use Excelerator.Phoenix
-
Import
Excelerator.Workbookinto your view module:defmodule MyApp.MyView do use MyApp.Web, :view import Excelerator.Workbook
(Alternatively, add the use / import statements to the appropriate sections of
web/web.ex, which will make excelerator available in all controllers/ views.) -
Call
xlsin your controller action to send content as a file download:def show(conn, %{"format" => "xls"} = params) do xls conn, "show.xls", favorite: "Elixir" end
-
Create
web/templates/RESOURCE/NAME.xls.exsworkbook do worksheet "My Sheet" do row do cell "Name" cell "Status" end
row do cell assigns.favorite cell 1 end endend