my code actually worked. I thought it was going to save the excel file to
'C:\excel' folder so i was looking for the file in the folder but i
couldn't find the excel file. The excel file was actually exported to my
django project folder instead.
How to i allow the end user to be able to download the file to their
desktop instead of exporting it to the server itself
On Mon, Apr 16, 2018 at 3:27 PM, sum abiut <suab...@gmail.com> wrote:
> I wrote a function to export sql query to an excel file, but some how the
> excel file wasn't created when the function was call. appreciate any
> here is my view.py
> def download_excel(request):
> if "selectdate" in request.POST:
> if "selectaccount" in request.POST:
> selected_date = request.POST["selectdate"]
> selected_acc = request.POST["selectaccount"]
> if selected_date==selected_date:
> if selected_acc==selected_acc:
> engine=create_engine('mssql+pymssql://username:password@servername /db')
> connection = engine.connect()
> df = pd.read_sql(stmt,connection)
> writer = pd.ExcelWriter('C:\excel\export.xls')
> df.to_excel(writer, sheet_name ='bar')
You received this message because you are subscribed to the Google Groups
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
To post to this group, send email to firstname.lastname@example.org.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
For more options, visit https://groups.google.com/d/optout.