python xlwt 存成excel并设置行高列宽,自动换行

import xlwt
#先创建excel
style = xlwt.XFStyle()
style.alignment.wrap = 1  #设置自动换行
workbook = xlwt.Workbook(encoding='utf-8')
worksheet = workbook.add_sheet('My Worksheet')
#改变行高或者列宽  xlwt中是行和列都是从0开始计算的
first_col = worksheet.col(9)
two_col = worksheet.col(1)
three_col = worksheet.col(2)
# sec_col = worksheet.col(0)
first_col.width = 720*20
two_col.width = 320*20
three_col.width = 320*20
#保存excel
head = ['username', 'email', 'job_title', 'phone', 'company_name', 'status', 'country', 'city', 'Registration_time', 'profile', 'logo_address']
for index, value in enumerate(head):
    worksheet.write(0, index, value, style)
content = [[u'1231', u'123@123.com', u'12312', u'1321', u'ACE-Speed International Logistics Co., Ltd.', '\xe5\xae\xa1\xe6\xa0\xb8\xe9\x80\x9a\xe8\xbf\x87', u'China', u'Beijing', '2019-05-30 19:09:48', u'123', None], [u'1321', u'xweaweqw@124.com', u'31231', u'3123123', u'ACE-Speed International Logistics Co., Ltd.', '\xe5\xae\xa1\xe6\xa0\xb8\xe9\x80\x9a\xe8\xbf\x87', u'China', u'Beijing', '2019-10-14 15:27:03', u'123', None], [u'lileieli', u'a17634810426@126.com', u'lielilei', u'784957430', u'Beijing Elan-Jet International Logistics Co., Ltd.', '\xe5\xae\xa1\xe6\xa0\xb8\xe9\x80\x9a\xe8\xbf\x87', u'China', u'Beijing', '1970-01-01 08:33:39', u'Beijing Elan-Jet International Logistics Co., Ltd. was incorporated in 1994.  It is one of the first privately owned freight forwarding enterprises in China.     Targeting "to be the most competitive logistics service provider," Elan-jet is committed to providing professional air and ocean logistics and distribution services, including international freight forwarding, customs brokerage, and related services.    Honesty, strictness, high efficiency, and initiative are our attitude. Benefiting each other and developing together are our principles. Beijing Elan-Jet International Logistics Co., Ltd. is your best choice for helping your company to achieve success.', None]]
for index, value_list in enumerate(content, 1):
    for i, value in enumerate(value_list):
        worksheet.write(index, i, value, style)
workbook.save('user_info.xls')

 

  • 6
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值