公司有个需求,需要把 json 文件,转成 excel 格式.
虽然,我刚学 python 不久,也深深的被 python 的简单易用和丰富的模块所吸引.
tablib 模块可以完美实现,json 转 excel
官方网址:https://pypi.python.org/pypi/tablib/0.9.3
代码如下:
#!/usr/bin/env python # -*- coding: utf-8 -*- import tablib headers = ("name","age","weight") data = [("buhaoxun","33","75kg"),("shaoxun","33","80kg"),("xun","33","85kg")] data.append(("meili","33","90kg")) data = tablib.Dataset(*data,headers=headers) print data.json open(‘xinxi.xls‘, ‘wb‘).write(data.xls)