I have a Django project which has a mysql database backend. How can I export contents from my db to an Excel (xls, xlsx) format?
Asked
Active
Viewed 1,034 times
0
-
export to csv - see http://stackoverflow.com/questions/356578/how-to-output-mysql-query-results-in-csv-format – JamesO Jul 11 '11 at 12:22
4 Answers
0
phpMyAdmin has an Export tab, and you can export in CSV. This can be imported into Excel.

Scott C Wilson
- 19,102
- 10
- 61
- 83
-
Yes, I know that, but how can I directly export xls or xlsx without phpMyAdmin? – user823148 Jul 11 '11 at 12:23
0
Openpyxl is a great choice, but if you don't wanna go through a new thing you can simply write you own exporting function:
for example you can export things in CSV format like this:
def CVSExport(database_array):
f_csv = open('mydatabase.csv', 'w')
for row in database_array:
f_csv.write('"%s";;;;;"%s"\n'%(row[0], row[1]))
f_csv.close()
when you open exported file by excel you should set ";;;;;" as separator.

Kambiz
- 1,217
- 9
- 8