韩漫免费漫画在线观看方法,《好好疼爱里面》免费看,年轻漂亮的女士护士内衣,妈妈醉酒后把我当爸爸电视剧

文章 > Django > Django中如何用xlwt生成表格

Django中如何用xlwt生成表格

头像

2020-11-05 15:46:245747浏览 · 0收藏 · 0评论

同样是做表格,但是有些人的表格就做的很好看。融合了之前所学不同模块的知识,来讲讲Django中生成表格的特殊方法。

这里只是mark一下导出的方法,并没有做什么REST处理和异常处理。

维护统一的style样式,可以使导出的数据更加美观。


def export_excel(request):      # 设置HttpResponse的类型    response = HttpResponse(content_type='application/vnd.ms-excel')      response['Content-Disposition'] = 'attachment;filename=user.xls'      # new一个文件    wb = xlwt.Workbook(encoding = 'utf-8')      # new一个sheet    sheet = wb.add_sheet(u'人员表单')    # 维护一些样式, style_heading, style_body, style_red, style_green    style_heading = 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;        """    )    style_body = xlwt.easyxf("""        font:            name Arial,            bold off,            height 0XA0;        align:            wrap on,            vert center,            horiz left;        borders:            left THIN,            right THIN,            top THIN,            bottom THIN;        """    )    style_green = xlwt.easyxf(" pattern: pattern solid,fore-colour 0x11;")    style_red = xlwt.easyxf(" pattern: pattern solid,fore-colour 0x0A;")    fmts = [        'M/D/YY',        'D-MMM-YY',        'D-MMM',        'MMM-YY',        'h:mm AM/PM',        'h:mm:ss AM/PM',        'h:mm',        'h:mm:ss',        'M/D/YY h:mm',        'mm:ss',        '[h]:mm:ss',        'mm:ss.0',    ]    style_body.num_format_str = fmts[0]    # 写标题栏    sheet.write(0,0, '姓名', style_heading)      sheet.write(0,1, '英文名', style_heading)      sheet.write(0,2, '职位', style_heading)      sheet.write(0,3, '公司电话', style_heading)      sheet.write(0,4, '手机', style_heading)      sheet.write(0,5, 'QQ', style_heading)      sheet.write(0,6, 'MSN', style_heading)      sheet.write(0,7, 'Email', style_heading)      sheet.write(0,8, '办公地点', style_heading)      sheet.write(0,9, '部门', style_heading)    sheet.write(0,10, '人员状态', style_heading)        # 写数据    row = 1      for usa in employesInfo.objects.all():        sheet.write(row,0, usa.name, style_body)        sheet.write(row,1, usa.eName, style_body)        sheet.write(row,2, usa.postion, style_body)        sheet.write(row,3, usa.cPhone, style_body)        sheet.write(row,4, usa.pPhone, style_body)        sheet.write(row,5, usa.qq, style_body)        sheet.write(row,6, usa.msn, style_body)        sheet.write(row,7, usa.email, style_body)        sheet.write(row,8, usa.offAreas, style_body)        sheet.write(row,9, usa.depart, style_body)        if int(usa.status) == 1:            sheet.write(row,10, '在职',style_green)        else:            sheet.write(row,10,'离职', style_red)        row=row + 1          # 写出到IO    output = StringIO.StringIO()    wb.save(output)    # 重新定位到开始    output.seek(0)    response.write(output.getvalue())      return response


以上就是Django中用xlwt生成表格的方法。更多Python学习推荐:PyThon学习网教学中心

关注

关注公众号,随时随地在线学习

本教程部分素材来源于网络,版权问题联系站长!

《熟妇的荡欲》免费看| 爸爸的擎天柱让我看第二集| 白石茉莉奈| YSL口红水蜜桃色号8223| 亚洲精品久久久久久久| 国产免费观看高清电视剧在线观看| 二人努力生猴子免费观看| 穿黑色蕾丝透明胸罩说明什么| X7X7X7任意噪1060| 男男| 姐姐用脚帮你打枪| 地下室SMS录制的全部内容| 日亚M码是日本的还是中国的| 黑色黄丝包臀紧身连衣裙| 我的小后妈中字ID| 我和两个小婕子做过爱| 双面玛莎| 少女配狗视频大全播放| 《互换人妻HD中字》| 《办公室高潮秘书2》电影| 灭火宝贝| 摸摸大扔子是讽刺人还是夸人| 黑丝美女| 床戏| 性和死亡| 《厨房激战5》完整版在线观看| 坤坤赛进桃子里在线看歌词| 《如狼似虎的女人》大结局| 榴莲APP官网下载1.0.3| 欧美大妈LOGO大全及价格图| 我把刘姨俩腿扛在肩上是哪一集的| 我故意对着床上的小能做手工图片 | 亲爱的爸爸【父女】笔趣阁负责的 | 三个领导换着躁我几小时在线观看| 小俊在雪姨身上耕耘小说免费阅读| B站夫妻进入高峰期需要多久| 《湿点》未增减板相似| YSL千人千色T9T9T9T9...| 成都私人情侣免费看电视剧的软件| 妈妈我要亲亲你PPT| 97在线观看免费高清电视剧狂飙