Not Logged In

django-tabular-export 1.1.0

Documentation

This module contains functions which take (headers, rows) pairs and return HttpResponses with either XLSX or
CSV downloads and Django admin actions which can be added to any ModelAdmin for generic exports. It provides
two functions (export_to_csv_response and export_to_xlsx_response) which take a filename,
a list of column headers, and a Django QuerySet, list-like object, or generator and return a response.

Goals

This project is not intended to be a general-purpose spreadsheet manipulation library. The only goal is to
export data quickly and safely.

The API is intentionally simple, giving you full control over the display and formatting of headers or your
data. flatten_queryset has special handling for only two types of data: None will be converted to an
empty string and date or datetime instances will serialized using isoformat(). All
other values will be specified as the text data type to avoid data corruption in Excel if the values happen
to resemble a date in the current locale.

Unicode-safety: input values, including lazy objects, are converted using Django’s
force_text
function and will always be emitted as UTF-8

Performance: the code is known to work with data sets up to hundreds of thousands of rows. CSV responses
use StreamingHttpResponse, use minimal memory, and start very quickly. Excel (XLSX) responses cannot be
streamed but xlsxwriter is one of the faster implementations
and its memory-size optimizations are enabled.

The default columns will be the same as you would get calling values_list on your ModelAdmin’s default
queryset as returned by ModelAdmin.get_queryset(). If you want to customize this, simply declare a new
action on your ModelAdmin which does whatever data preparation is necessary: