国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > Python > 正文

django使用xlwt導(dǎo)出excel文件實(shí)例代碼

2020-02-22 23:08:24
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

本文研究的主要是記錄一下下導(dǎo)出的方法,并沒(méi)有做什么REST處理和異常處理。

維護(hù)統(tǒng)一的style樣式,可以使導(dǎo)出的數(shù)據(jù)更加美觀。

def export_excel(request):   # 設(shè)置HttpResponse的類型  response = HttpResponse(content_type='application/vnd.ms-excel')   response['Content-Disposition'] = 'attachment;filename=user.xls'   # new一個(gè)文件  wb = xlwt.Workbook(encoding = 'utf-8')   # new一個(gè)sheet  sheet = wb.add_sheet(u'人員表單')  # 維護(hù)一些樣式, 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]  # 寫標(biāo)題欄  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, '手機(jī)', 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, '辦公地點(diǎn)', style_heading)   sheet.write(0,9, '部門', style_heading)  sheet.write(0,10, '人員狀態(tài)', style_heading)     # 寫數(shù)據(jù)  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)  # 重新定位到開(kāi)始  output.seek(0)  response.write(output.getvalue())   return response

總結(jié)

以上就是本文關(guān)于django使用xlwt導(dǎo)出excel文件實(shí)例代碼的全部?jī)?nèi)容,希望對(duì)大家有所幫助。感興趣的朋友可以繼續(xù)參閱本站其他相關(guān)專題,如有不足之處,歡迎留言指出。感謝朋友們對(duì)本站的支持!

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 保德县| 南开区| 城口县| 临高县| 池州市| 隆林| 巫山县| 微博| 高碑店市| 保定市| 武邑县| 迭部县| 托克逊县| 抚宁县| 云龙县| 福建省| 元朗区| 社旗县| 福泉市| 瓦房店市| 宁蒗| 霍邱县| 淮阳县| 大渡口区| 偏关县| 东乡县| 会泽县| 保康县| 桓台县| 茌平县| 武城县| 灌云县| 达拉特旗| 崇义县| 三穗县| 兰考县| 汉川市| 西畴县| 黄龙县| 潮州市| 贵德县|