django excel 3
xlwt , django_excel_templates , django-excel-response .
2 xlwt
xlwt**************************************************************************************************
http://pypi.python.org/pypi/xlwt/
packageexamples
http://nullege.com/codes/search/xlwt.easyxf
example
#################################### book sheet
import xlwt
wb =xlwt.Workbook()
ws = wb.add_sheet('Sheetname')
########################################1
style_k=xlwt.easyxf('font: bold on,colour_index green,height 360;
align: wrap off;
borders:left 1,right 1,top 1,bottom 1;
pattern: pattern alt_bars, fore_colour gray25, back_colour gray25')
#font: bold on,colour_index green,height 360,family:Arial; ,
#align: wrap on;
#pattern:fore_colour yellow, back_colour yellow2
########################################2
#font pattern class,class style
fnt =xlwt.Font()
fnt.name = 'Arial'
fnt.colour_index = 4
fnt.bold = True
pattern=xlwt.Pattern() ###
pattern.pattern = xlwt.Pattern.SOLID_PATTERN
pattern.pattern_back_colour=0x3A
pattern.pattern_fore_colour=0x3A
borders = xlwt.Borders()
borders.left = 1
borders.right = 1
borders.top = 1
borders.bottom = 1
borders.bottom_colour=0x3A
style = xlwt.XFStyle()
style.font = fnt
style.borders = borders
style.pattern = pattern
##########################################i cell
for i in range(2,8):
ws.col(i).width = 0x0d00 + 2000
##########################################i cell
#
##########################################sheet
#ws.write(row, col, data [,style])
ws.write(0, 0, 'Firstname',style)
ws.write(0, 0, 'Firstname')
##########################################
ws.write_merge(0,1,0,1,'Firstname',style. )
##########################################
style.num_format_str='YYYY-MM-DD'
##########################################
n = "HYPERLINK"
attach_report=xlwt.Formula(n +'("http://www.baidu.com";"fame.pdf" )')
#
##########################################Content-Disposition
fname = 'testfile.xls'
agent=request.META.get('HTTP_USER_AGENT')
if agent and re.search('MSIE',agent):
response =HttpResponse(mimetype="application/vnd.ms-excel") #ie
response['Content-Disposition'] ='attachment; filename=%s' % urlquote(fname) #/
else:
response =HttpResponse(mimetype="application/ms-excel")#ie
response['Content-Disposition'] ='attachment; filename=%s' % smart_str(fname) #/
##########################################
wb.save(response)
return response
xlwt , django_excel_templates , django-excel-response .
2 xlwt
xlwt**************************************************************************************************
http://pypi.python.org/pypi/xlwt/
packageexamples
http://nullege.com/codes/search/xlwt.easyxf
example
#################################### book sheet
import xlwt
wb =xlwt.Workbook()
ws = wb.add_sheet('Sheetname')
########################################1
style_k=xlwt.easyxf('font: bold on,colour_index green,height 360;
align: wrap off;
borders:left 1,right 1,top 1,bottom 1;
pattern: pattern alt_bars, fore_colour gray25, back_colour gray25')
#font: bold on,colour_index green,height 360,family:Arial; ,
#align: wrap on;
#pattern:fore_colour yellow, back_colour yellow2
########################################2
#font pattern class,class style
fnt =xlwt.Font()
fnt.name = 'Arial'
fnt.colour_index = 4
fnt.bold = True
pattern=xlwt.Pattern() ###
pattern.pattern = xlwt.Pattern.SOLID_PATTERN
pattern.pattern_back_colour=0x3A
pattern.pattern_fore_colour=0x3A
borders = xlwt.Borders()
borders.left = 1
borders.right = 1
borders.top = 1
borders.bottom = 1
borders.bottom_colour=0x3A
style = xlwt.XFStyle()
style.font = fnt
style.borders = borders
style.pattern = pattern
##########################################i cell
for i in range(2,8):
ws.col(i).width = 0x0d00 + 2000
##########################################i cell
#
##########################################sheet
#ws.write(row, col, data [,style])
ws.write(0, 0, 'Firstname',style)
ws.write(0, 0, 'Firstname')
##########################################
ws.write_merge(0,1,0,1,'Firstname',style. )
##########################################
style.num_format_str='YYYY-MM-DD'
##########################################
n = "HYPERLINK"
attach_report=xlwt.Formula(n +'("http://www.baidu.com";"fame.pdf" )')
#
##########################################Content-Disposition
fname = 'testfile.xls'
agent=request.META.get('HTTP_USER_AGENT')
if agent and re.search('MSIE',agent):
response =HttpResponse(mimetype="application/vnd.ms-excel") #ie
response['Content-Disposition'] ='attachment; filename=%s' % urlquote(fname) #/
else:
response =HttpResponse(mimetype="application/ms-excel")#ie
response['Content-Disposition'] ='attachment; filename=%s' % smart_str(fname) #/
##########################################
wb.save(response)
return response