{"id":31933036,"url":"https://github.com/elonsoft/elixlsx_view","last_synced_at":"2025-10-14T05:51:23.145Z","repository":{"id":57494652,"uuid":"294489817","full_name":"Elonsoft/elixlsx_view","owner":"Elonsoft","description":"This library is used to render data as xlsx documents in phoenix views","archived":false,"fork":false,"pushed_at":"2020-10-20T17:39:37.000Z","size":7,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-09-20T22:52:04.620Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Elonsoft.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-09-10T18:24:57.000Z","updated_at":"2021-10-10T20:49:35.000Z","dependencies_parsed_at":"2022-09-02T19:51:16.361Z","dependency_job_id":null,"html_url":"https://github.com/Elonsoft/elixlsx_view","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Elonsoft/elixlsx_view","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Elonsoft%2Felixlsx_view","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Elonsoft%2Felixlsx_view/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Elonsoft%2Felixlsx_view/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Elonsoft%2Felixlsx_view/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Elonsoft","download_url":"https://codeload.github.com/Elonsoft/elixlsx_view/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Elonsoft%2Felixlsx_view/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279018011,"owners_count":26086237,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-14T02:00:06.444Z","response_time":60,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-10-14T05:51:20.213Z","updated_at":"2025-10-14T05:51:23.140Z","avatar_url":"https://github.com/Elonsoft.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ElixlsxView\n\n![](https://github.com/Elonsoft/elixlsx_view/workflows/mix%20test/badge.svg)\n![](https://github.com/Elonsoft/elixlsx_view/workflows/mix%20format/badge.svg)\n\nThis library is used to render data as xlsx documents in phoenix\nviews.\n\n## Instalation\n\nAdd the library into your `deps/0`:\n\n```elixir\ndefp deps do\n  [\n    {:elixlsx_view, \"~\u003e 0.1\"}\n  ]\nend\n```\n\nDocumentation can be found on [HexDocs](https://hexdocs.pm/elixlsx_view)\n\n## Usage\n\nFirst you need to register mime type for xlsx and configure phoenix\nto use this library to manage rendering. Add this to your\n`confix.exs`:\n\n```elixir\nconfig :mime, :types, %{\n  \"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\" =\u003e\n    [\"xlsx\"]\n}\n\nconfig :phoenix, :format_encoders,\n  xlsx: ElixlsxView.Encoder\n```\n\nAfter configuration is done, you can use it like you do with any\nother mime type (i.e. json or html), but the view function needs to\nreturn `%Elixlsx.Workbook{}` struct instead of a simple map like in\njson view.\n\n\u003e **Note:** You probably don't need to do content negotiation and\n\u003e instead of `plug accept, [\"xlsx\"]` put `plug put_format, \"xlsx\"`\n\u003e in your pipeline.\n\n## Example\n\nHere goes an example of application with xlsx endpint.\n\n```elixir\ndefmodule MyApp.Report do\n  @moduledoc false\n\n  def generate do\n    [\n      %{name: \"John\", number: 1},\n      %{name: \"Phil\", number: 2},\n      %{name: \"Zak\", number: 3}\n    ]\n  end\nend\n```\n\n```elixir\ndefmodule MyAppWeb.Router do\n  @moduledoc false\n\n  use MyAppWeb, :router\n\n  pipeline :xlsx do\n    plug :put_format, \"xlsx\"\n  end\n\n  scope \"/\", MyAppWeb do\n    pipe_through [:xlsx]\n    get \"/report\", ReportController, :generate\n  end\nend\n```\n\n```elixir\ndefmodule MyAppWeb.ReportController do\n  @moduledoc false\n\n  use MyAppWeb, :controller\n\n  alias MyApp.Report\n\n  def generate(conn, _params) do\n    report = Report.generate()\n    render(conn, :report, report: report)\n  end\nend\n```\n\n```elixir\ndefmodule MyAppWeb.ReportView do\n  @moduledoc false\n\n  use MyAppWeb, :view\n\n  alias Elixlsx.{Sheet, Workbook}\n  alias ElixlsxView.Style\n\n  @styles [\n    title: [size: 14, bold: true],\n    name: [italic: true],\n    number: [bg_color: \"#aaa\"]\n  ]\n\n  def render(\"report.xlsx\", %{report: report}) do\n    %Workbook{sheets: [render_sheet(report)]}\n  end\n\n  defp render_sheet(report) do\n    %Sheet{}\n    |\u003e Sheet.set_at(0, 0, \"Name\", classes: [:title])\n    |\u003e Sheet.set_at(0, 1, \"Number\", classes: [:title])\n    |\u003e put_rows(report)\n    |\u003e Style.apply(@styles)\n  end\n\n  defp put_rows(sheet, report) do\n    {sheet, _} =\n      Enum.reduce(report, {sheet, 1}, fn\n        %{name: name, number: number}, {sheet, row} -\u003e\n          sheet =\n            sheet\n            |\u003e Sheet.set_at(row, 0, name, classes: [:name])\n            |\u003e Sheet.set_at(row, 1, number, classes: [:number])\n\n          {sheet, row + 1}\n      end)\n\n    sheet\n  end\nend\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felonsoft%2Felixlsx_view","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Felonsoft%2Felixlsx_view","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felonsoft%2Felixlsx_view/lists"}