你好! 这是你第一次使用 Markdown编辑器 所展示的欢迎页。如果你想学习如何使用Markdown编辑器, 可以仔细阅读这篇文章,了解一下Markdown的基本语法知识。
# out = xlwt.Workbook("UTF-8") worksheet = out.add_sheet("test") # 设置单元格格式 pr_pattern = xlwt.Pattern() pr_pattern.pattern = xlwt.Pattern.SOLID_PATTERN pr_pattern.pattern_fore_colour = 5 # yellow style = xlwt.XFStyle() style.pattern = pr_pattern worksheet.write(0, 1, "填充黄色", pr_style) # out.save("/home/data/out.xls")
worksheet.col(2).width = 256 * 15 # 15个字符宽度
style_head = xlwt.easyxf('alignment: wrap True') worksheet.write(0, 3, "a long line would be wrapped", style_head)
style_head = xlwt.XFStyle() style_head.alignment.wrap = 1 # 设置自动换行 worksheet.write(0, 1, "a long line would be wrapped", style_head)
注意,如果设置自动换行后,行高会自动调整,无需设置
row = worksheet.row(0) header_height = xlwt.easyxf('font:height 720') row.set_style(header_height)
row.height_mismatch = True row.height = 1280