Python安装XlsxWriter库
2019-02-13XlsxWriter库:处理Excel XLSX files有关的Python库。
centos 6.10安装XlsxWriter错误
python setup.py build
setup.py:11: UserWarning: The minimum Python version supported by XlsxWriter is 2.7.
warn("The minimum Python version supported by XlsxWriter is 2.7.")
wget https://pypi.python.org/packages/e4/63/e53deacc293c7fadf95b840471f4bd56573d084af993e6aeeee2d5f1bd32/
XlsxWriter-1.0.2.tar.gz
python setup.py install
1、源码安装:
ubuntu16.04 安装成功/CentOS7.6
$ git clone https://github.com/jmcnamara/XlsxWriter.git
Receiving objects: 100% (19925/19925), 162.76 MiB | 127.00 KiB/s, done.
$ cd XlsxWriter
$ sudo python setup.py install
2、地址:http://xlsxwriter.readthedocs.org/
0000
0000
3、实例:
注意:xlsxwriter 只能创建新文件,不可以修改原有文件。如果创建新文件时与原有文件同名,则会覆盖原有文件
#!/usr/bin/python2.7
# coding:utf-8
import re
import xlsxwriter
import sys
import datetime
reload(sys)
sys.setdefaultencoding('utf-8')
userlistfile='./user.txt'
def getvpnuser(userlistfile):
with open(userlistfile,'r') as f:
for line in f:
line=re.split('[,;]',line)
line[5]=line[5][:-1]
line.append('180')
yield line
def main():
weeknum=datetime.datetime.now().isocalendar()[1]
filename=u'./%d.xlsx' %weeknum
print filename
workbook=xlsxwriter.Workbook(filename)
sheet1 = workbook.add_worksheet()
sheet1.set_column('A:A', 14)
sheet1.set_column('B:B', 12)
sheet1.set_column('C:C', 25)
sheet1.set_column('D:D', 42)
sheet1.set_column('E:E', 20)
sheet1.set_column('F:F', 13)
sheet1.set_column('G:G', 17)
title=['1,'1','2,'3,'5,'8,'13']
sheet1.write_row(0, 0, title)
num=1
for i in getvpnuser(userlistfile):
line=i
sheet1.write_row(num,0,line)
num+=1
workbook.close()
if __name__=='__main__':
main()