fast_xlsx_exporter v0.2.2 FastXlsxExporter View Source
Fast XLSX Exporter
Installation
Add fast_xlsx_exporter
to your mix.ex deps:
def deps do
[
{:fast_xlsx_exporter, "~> 0.2.2"}
]
end
Explanation
Elixlsx was fine, until really huge exports appeared. Then it took more and more time to generate xlsx reports. And RAM.
So, being really primitive (8 hour at night from scratch knowing nothing about xlsx) this library does not store document in memory. It writes straight to file system.
Some example:
rows = [[1, 2, 3, 10], [4, 5, 6], [7, 8, 9]]
context = FastXlsxExporter.initialize()
context = Enum.reduce(rows, context, &FastXlsxExporter.put_row/2)
{:ok, document} = FastXlsxExporter.finalize(context)
File.write("/home/george/failures.xlsx", document)
See? Really simple thing, nothing special.
If you're looking for something that really supports xlsx, go with elixlsx.
Supported cell values
Numbers
Both float
and integer
values are supported and special form of {<float>, :percents}
to write number as xlsx percent.
Example row:
[1, 12.5, {0.59, :percents}]
Strings
Strings could be written in two ways.
First one is straight (no special form). In this case strings are written sequentially to shared strings, which is RAM-friendly but bloats resulting xlsx file.
Second one requires special form of {<string>, :dictionary}
. In this case strings are put into dictionary and are put into shared strings only once, but are stored in memory, which is good for limited set of values but can cause OOMKilled
if strings are random.
Example rows:
# first row
["Vladimir Putin", "Donald Trump", "Literally Hitler"]
# second row
[{"some_string", :dictionary}, {"some_other_string", :dictionary}, {"some_string", :dictionary}]
# third row
["wow!", {"some_other_string", :dictionary}, "yay!"]
Date and time
Both %Date{}
and %NaiveDateTime{}
are rendered as dates (not strings).
Example row:
[~D[1905-12-11], ~D[2020-04-09], ~N[2020-04-09 12:00:00]]
Link to this section Summary
Functions
Finalizes export and returns xlsx file binary
Finalizes export and writes result to file
Initializes export
Adds row to document
Link to this section Types
context()
View Sourcecontext() :: {temp_dir_name :: binary(), FastXlsxExporter.Sheet.context()}
Link to this section Functions
Finalizes export and returns xlsx file binary
Removes temporary directory, closes file descriptors
finalize_to_file(context, filename)
View Sourcefinalize_to_file(context :: context(), :file.name()) :: :ok | {:error, term()}
Finalizes export and writes result to file
Removes temporary directory, closes file descriptors
Initializes export
Creates temporary export directory at System.tmp_dir!()
, writes common files and content file header
put_row(row, arg)
View Sourceput_row(FastXlsxExporter.Sheet.row(), context()) :: context()
Adds row to document