python excel共通フォーマットのエクスポート
# encoding:utf-8
import xlwt
from xlwt import *
book = Workbook(encoding='utf-8')
sheet = book.add_sheet('Sheet1') # sheet
#----- ----------------
alignment = xlwt.Alignment() #
alignment.horz = xlwt.Alignment.HORZ_CENTER # : HORZ_GENERAL, HORZ_LEFT, HORZ_CENTER, HORZ_RIGHT, HORZ_FILLED, HORZ_JUSTIFIED, HORZ_CENTER_ACROSS_SEL, HORZ_DISTRIBUTED
alignment.vert = xlwt.Alignment.VERT_CENTER # : VERT_TOP, VERT_CENTER, VERT_BOTTOM, VERT_JUSTIFIED, VERT_DISTRIBUTED
style = xlwt.XFStyle() #
style.alignment = alignment #
style.font.height=430 #
#---------- --------------
col1=sheet.col(0) # 0
col1.width=380*20 # 0 380, 20
#---------- -----------
sheet.write_merge(4,6,0,1,' ',style) # 4 6 0 1 , , :excel 0
sheet.write(0, 0,' ',style) # 0 0 ,
sheet.write(0, 1,' ',style) # 0 1 ,
sheet.write(0, 2,' ',style) # 0 2 ,
#
stu_list=[{},{"name":" ","age":23,"gender":" "},{"name":" ","age":22,"gender":" "},{"name":" ","age":25,"gender":" "}]
#
for index,x in enumerate(stu_list):
if index!=0:
sheet.write(index, 0,x["name"],style)
sheet.write(index, 1,x["age"],style)
sheet.write(index, 2,x["gender"],style)
book.save('demo1.xls')