I'm building a website that'll have a django backend. I want to be able to serve the medical billing data from a database that django will have access to. However, all of the data we receive is in excel spreadsheets. So I've been looking for a way to get the data from a spreadsheet, and then import it into a django model. I know there are some different django packages that can do this, but I'm having a hard time understanding how to use these packages. On top of that I'm using python 3 for this project. I've used win32com for automation stuff in excel in the past. I could write a function that could grab the data from the spreadsheet. Though what I want figure out is how would I write the data to a django model? Any advice is appreciated.
-
2Have you tried anything? Every django packages has some basic documentation read and code as per your requirement. if you got any errors please update your question with code and error traceback we are happy to help. – Ravi Kumar Jun 24 '16 at 17:52
-
I have looked at the documentation for the django packages I've been looking at. Though I can't make head or tails on how to import the data into a model. – TechEmperor95 Jun 24 '16 at 19:16
-
Can someone suggest the right way to do validation. Extract data from Excel into modelform and check validation? – RL Shyam Mar 18 '17 at 09:23
3 Answers
Use http://www.python-excel.org/ and consider this process:
- Make a view where user can upload the xls file.
- Open the file with xlrd.
xlrd.open_workbook(filename)
- Extract, create dict to map the data you want to sync in db.
- 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.

- 11,451
- 12
- 74
- 100
-
Hi, can you point out a tutorial you would recommend to do these operations? – Tms91 Oct 09 '19 at 09:31
-
1read this entire doc and then read it again but this time experimenting with the python shell https://xlsxwriter.readthedocs.io/ – panchicore Oct 09 '19 at 15:33
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.

- 3,456
- 6
- 40
- 74
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.

- 1
- 1

- 81
- 6
-
Excel spreadsheets are typically .xlsx file format. CSVs are not really spreadsheets, Excel just happens to support editing them within the spreadsheet interface. – Technichor Nov 26 '21 at 23:27