pip install tablib

详细文档:http://python-tablib.org

生成一个新数据集

headers = ('first_name', 'last_name')
data = [
    ('John', 'Adams'),
    ('George', 'Washington')
]
data = tablib.Dataset(*data, headers=headers)

添加新行

>>> data.append(('Henry', 'Ford'))

添加新列

>>> data.append_col((90, 67, 83), header='age')

导出JSON

>>> print data.json
[
  {
    "last_name": "Adams",
    "age": 90,
    "first_name": "John"
  },
  {
    "last_name": "Ford",
    "age": 83,
    "first_name": "Henry"
  }
]

导出yaml

>>> data.yaml
- {Age: 22, First Name: Kenneth, Last Name: Reitz}
- {Age: 21, First Name: Bessie, Last Name: Monke}

导出xlsx

>>> x = data.xlsx

In [11]: cc =open("/tmp/data.xlsx", "w")

In [12]: cc.write(x)

In [13]: cc.flush()

In [14]: cc.close()