开发者

MySQLdb to Excel

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?


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


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


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜