How do I upload and manipulate excel file with Django? - python

Ok,
I had a look at the UploadFile Class documentation of the Django framework. Didn't find exactly what I am looking for?
I am creating a membership management system with Django. I need the staff to have the ability to upload excel files containing list of members (and their details) which I will then manipulate to map to the Model fields.
It's easy to do this with pandas framework for example, but I want to do it with Django if I can.
Any suggestions.
Thanks in advance

you can use xlrd to read excel files
in client side you just submit a form with file input.
on server uploaded file stored on request.FILES
read file and pass it to xlrd then process sheets and cells of each sheet

Related

Django - accessing a stored excel file in Django model viewer

I am trying to access excel files through the django-admin model viewing portal.
Each excel file is generated through a seperate algorithm, and is already in a directory called excel_stored
each excel file is generated with an ID that corresponds to its model # in django. So it would be excel_%ID%.xlsx or excel_23.xlsx for example.
I want my django FileField() to access the relevant excel file so that I can download it from my django admin portal, just like I can access my other model information (city name, time uploaded, etc).
Here is a pseudo-code of what I'd want to do:
My models.py would look like this
excel = models.FileField()
The process of saving would look like this
create_excel()
### EXCEL WAS SAVED TO DIR: excel_stored ###
save_excel = Model(excel = file.directory((os.path.join(BASE_DIR, 'lead/excel_stored/excel_%s.xlsx' %ID))
save_excel.save()
Id then be able to download it like this https://i.stack.imgur.com/4HRUU.gif
I know there's a lot I'm missing, but most documentation I find refers to uploading an excel file through forms, not accessing it.
I've been stuck on this for a while, so I'd appreciate some direction! Thank you!

OpenERP 6.1 module with upload file field

I want to create OpenERP 6.1 module with a upload binary file field as one of the fields in view.
The file will be stored in database as binary data, but before storage in database I need to parse that file, and save data as part of the other created module.
So, I don't know how to specifiy filed for upload files in a view xml file, and also how to run the uploading process. Can somebody help me about this? Some code snippets or advice how to do that.
Take a look at the way the attachments module works, particularly the binary data column. You should also look at the screen definition.

Creating spreadsheets for download in django

I am using xlrd to create spreadsheets. On a website, a user will be able to create a custom report and download that xls file.
Usually, I am storing files on S3, but in this case, is there a way not to store the file anywhere and just give it directly to the user? Or how should I do this if I don't want to use S3 to save the file?
xlrd is a good choice. About the generation and download processes - it depends on the web framework in usage, here is an example with web2py.

upload csv/excel file to appengine (python) for processing

I need to be able to upload an excel or csv file to appengine so that the server can process the rows and create objects. Can anyone provide or point me to an example of how this is done? Thanks for your help.
Uploading to the Blobstore is probably what you are after. Then reading the data and processing it with the csv module.
You might want to look into sending your file to google docs in the case of excel (and other) formats then reading the rows back via the Spreadsheets API
If you mean a one-off (or a few) transfers, you're probably looking for the bulk upload system: http://code.google.com/appengine/docs/python/tools/uploadingdata.html
If you're talking about regular uploads during use, you'll need to handle them as post requests to the application.

Saving a Django form to a csv file

I have a Django form that is working fine. I'd like to save the data it submits to a CSV file. Is there a "best practice" way to do this?
I need to include blank fields in the CSV file where the user has not filled in a "required=False" field
You can find the document CSV File Reading and Writing very helpful for your problem.

Categories