本文主要是介绍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')
这篇关于python xlwt 存成excel并设置行高列宽,自动换行的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!