[Django]-Import data from excel spreadsheet to django model

17๐Ÿ‘

โœ…

Use http://www.python-excel.org/ and consider this process:

  1. Make a view where user can upload the xls file.
  2. Open the file with xlrd. xlrd.open_workbook(filename)
  3. Extract, create dict to map the data you want to sync in db.
  4. Use the models to add, update or delete the information.

If you follow the process, you can learn a lot of how loading and extracting works and how does it fits with the requirements. I recommend to you first do the step 2 and 3 in shell to get more quicker experiments and avoid to be uploading/testing/error with a django view.

Hope this kickoff base works for you.

๐Ÿ‘คpanchicore

12๐Ÿ‘

Why donโ€™t you use django-import-export?

Itโ€™s a widget that allows you to import excel files from admin section.

Itโ€™s very easy to install, here you find the installation tutorial, and here an example.

๐Ÿ‘คTms91

5๐Ÿ‘

Excel spreadsheets are saved as .csv files, and there are plenty of examples and explanations on how to work with them, such as here and here, online already.

In general, if you are having difficulty understanding documentation or packages, my advice would be to search for specific examples or see if whatever you are trying to do has already been done. Play with it to get a working understanding, and then modify it to fit your needs.

๐Ÿ‘คMetalGearSamus

Leave a comment