pythonflaskflask-sqlalchemypyexcel

Can I control column order when I use function make_response_from_records in Flask-excel?


I am using flask-excel to export a list of dict to excel file. This is my code.

return excel.make_response_from_records(
    result,
    "csv",
    file_name="export_data",
    dest_encoding="gb2312"
)

I successfully got an Excel file with columns sorted by 'a b c'. How can I control the order? Thanks.


Solution

  • Please supply a list of ordered dictionary instances. According to the source, yield_from_records() will follow your order, as long as the first one is of an ordered dictionary.