zoukankan      html  css  js  c++  java
  • xlwt模块的使用

    前记:Python处理表格时会用到xlwt和xlrd模块

    xlwt设置行高:row

    sheet.row(2).set_style(xlwt.easyxf('font:height 440;'))
    13.5(220)是默认行高,13.5=220,27=440
    

    xlwt设置列宽:col

    sheet.col(2).width = 256*8
    8.43(2343,256*9.15)是默认列宽,8.29=256*9,10.29=256*11
    
    

    xlwt设置字体

    style = xlwt.easyxf("""
                    font: 
                        height 220, 
                        name SimSun, 
                        colour_index black, 
                        bold off; 
                    align: 
                        wrap on, 
                        vert centre, 
                        horiz center;
                    borders:
                        left thin, 
                        right thin, 
                        top thin, 
                        bottom thin
                     """)
    sheet.write_merge(0, 0, 0, 21, '哈哈哈', style) 
    sheet.write(2, 3, '哈哈哈', style)    
    
    

    xlwt导出表的开头和结尾

    response = HttpResponse(content_type='application/vnd.ms-excel')
    response['Content-Disposition'] = u'attachment;filename=dami.xls'
    wb = xlwt.Workbook(encoding='utf8')
    sheet = wb.add_sheet(u'商品库存', cell_overwrite_ok=True)
    
    output = BytesIO()
    wb.save(output)
    output.seek(0)
    response.write(output.getvalue())
    return response
    
    

    写表格方法

    sheet.write(行,列,标签,样式)
    sheet.write_merge(上,下,左,右,标签,样式)
    
    

    另外常用样式

    xlwt模块:
    style = xlwt.easyxf("""
                font:
                    name Arial,
                    colour_index white,
                    bold on,
                    height 0xA0;
                align:
                    wrap off,
                    vert center,
                    horiz center;
                pattern:
                    pattern solid,
                    fore-colour 0x19;
                borders:
                    left thin,
                    right thin,
                    top thin,
                    bottom thin;
                """)
    style2 = xlwt.easyxf("""
                    font: 
                        height 220, 
                        name SimSun, 
                        colour_index black, 
                        bold off; 
                    align: 
                        wrap on, 
                        vert centre, 
                        horiz center;
                    borders:
                        left thin, 
                        right thin, 
                        top thin, 
                        bottom thin
                     """)
    写入时设置样式改变字体属性,改变边框属性,改变底色属性,改变行高(起码显示上改变),但没改变行宽。
    行高行宽可以自行设置。
    
    
  • 相关阅读:
    Java并发编程:同步容器
    Java并发编程:深入剖析ThreadLocal
    使用jQuery开发一个响应式超酷整合RSS信息阅读杂志
    Javascript 严格模式
    参数传递的四种形式----- URL,超链接,js,form表单
    《CSS 设计指南》学习笔记 一
    【BootStrap】初步教程
    JavaScript日期对象使用总结
    Web前端知识技能大汇总
    浏览器 CSS Hack 收集
  • 原文地址:https://www.cnblogs.com/bqwzx/p/10658322.html
Copyright © 2011-2022 走看看