600字范文,内容丰富有趣,生活中的好帮手!
600字范文 > python设置excel自动换行_python xlwt 存成excel并设置行高列宽 自动换行

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

时间:2021-10-16 08:19:40

相关推荐

python设置excel自动换行_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@', 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', '-05-30 19:09:48', u'123', None], [u'1321', u'xweaweqw@', 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', '-10-14 15:27:03', u'123', None], [u'lileieli', u'a17634810426@', 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')

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。