Home >Backend Development >Python Tutorial >Example of how Python uses tablib to generate excel files

Example of how Python uses tablib to generate excel files

高洛峰
高洛峰Original
2017-03-07 15:40:511885browse

The example in this article describes how Python uses tablib to generate excel files. Share it with everyone for your reference, the details are as follows:

import tablib
headers = ('lie1', 'lie2', 'lie3', 'lie4', 'lie5')
mylist = [('23','23','34','23','34'),('sadf','23','sdf','23','fsad')]
mylist = tablib.Dataset(*mylist, headers=headers)
with open('excel.xlsx', 'wb') as f:
  f.write(mylist.xlsx)

This is a basic and simple example of using tablib to generate an excel file. First, you need to To install the tablib module, enter: pip intall tablib on the command line to automatically download and install it.

The effect is as follows:

Example of how Python uses tablib to generate excel files

For more examples of how Python uses tablib to generate excel files, please pay attention to the PHP Chinese website for related articles!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn