0

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?

user823148
  • 117
  • 2
  • 14
  • 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 Answers4

0

phpMyAdmin has an Export tab, and you can export in CSV. This can be imported into Excel.

Scott C Wilson
  • 16,711
  • 9
  • 54
  • 76
0

http://pypi.python.org/pypi/xlwt

Denis
  • 6,117
  • 6
  • 35
  • 56
0

If you need a xlsx (excel 2007) exporter, you can use openpyxl. Otherwise xlwt is an option.

shanyu
  • 8,990
  • 5
  • 55
  • 68
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,208
  • 9
  • 8