Skip to main content

Easy package with helpful method to use openpyxl

Project description

Dj easy xls

Helpful class and methods to import and export xls with django framework.

Usage

Import from xls

We call method get_sheet_rows which converts the table into dict with column as keys.

excel = OpenpyxlImport(file)
rows = excel.get_sheet_rows()
if excel.tally_header(rows[0], self.fields):
    for row in rows[1:]:
        params = excel.row_to_dict(row)
        print(params)

Export from xls

Simple example to export django model queryset into csv file.

file_name = self.file_name + ' ' + datetime.datetime.today().strftime('%Y-%m-%d') or 'Untitled'
export = OpenpyxlExport(file_name)
export.generate(self.fields, True)
for object in self.queryset:
    values = [change_format(object, val) for val in self.fields]
    export.generate(values)
export.set_width() # sets proper width of each columns

Return xlsx file as a response

Once we generate the xls in an export instance we can return response as

return export.response()

Return xlsx file as a response

Saving xlsx in a directory path.

return export.wb.save("<path>/test.xlsx")

Saving response from django as a file with axios

Django http response can be saved as a file from an axios request

const url = '/download'
const config = {
  baseURL: process.env.BaseURL,
  responseType: "blob", // Very important!
};
try {
  const response = await axios.get(url, config);
  const url = window.URL.createObjectURL(new Blob([response.data]));
  const link = document.createElement("a");
  link.href = url;
  link.setAttribute("download", "file.xlsx"); //or any other extension
  document.body.appendChild(link);
  link.click();
} catch (error) {
  console.log(error);
}

Install from Pypi test

pip install -i https://test.pypi.org/simple/ dj-easy-xls

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dj-easy-xls-0.2.3.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dj_easy_xls-0.2.3-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file dj-easy-xls-0.2.3.tar.gz.

File metadata

  • Download URL: dj-easy-xls-0.2.3.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.10

File hashes

Hashes for dj-easy-xls-0.2.3.tar.gz
Algorithm Hash digest
SHA256 7ff70bac658e993541f705d5bdc7e9e086a991f38d00f1bc3104ec51636ed264
MD5 b190a1c66a326caa0fdd4f4e3a335414
BLAKE2b-256 94b3a9e092ccbef3b3dc0802dd1ecb4494bc1cab6f512f80443b6e36941f6857

See more details on using hashes here.

File details

Details for the file dj_easy_xls-0.2.3-py3-none-any.whl.

File metadata

  • Download URL: dj_easy_xls-0.2.3-py3-none-any.whl
  • Upload date:
  • Size: 4.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.10

File hashes

Hashes for dj_easy_xls-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 dc11317a46465817ccb310253484d87e530797d3cdbede19af561789a63d2ec8
MD5 2bda3f2a4ba06ae2c305303587469812
BLAKE2b-256 7d5ec49e9848458da0af1749d4bd0d3dfd4239456a0bc9eeb542e305fc1365db

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page