import xlwt
import xlwings as xw
def set_style(name, height, bold=False):
style = xlwt.XFStyle()
font = xlwt.Font()
font.bold = bold
font.colour_index = 4
font.height = height
font.name = name
style.font = font
return style
def write_excel():
f = xlwt.Workbook()
sheet1 = f.add_sheet(u"total", cell_overwrite_ok=True)
row0 = [u"区域", u"项目", u"2019年5月当月实际", u"2019年5月当月预算", u"2019年5月当月预算完成率", u"2019年5月累计实际", u"2019年5月累计预算"
, u"2019年5月累计预算完成率", u"项目小计", u"合计"]
columns0 = [u"北京", u"天津", u"海南", u"杭州", u"武汉", u"重庆",]
status = [u"营业收入", u"营业成本", u"费用合计", u"营业外收支", u"税金合计", u"利润总额"]
for i in range(0, len(row0)):
sheet1.write(0, i, row0[i], set_style("微软雅黑", 220, True))
i,j = 1,0
while i < 6*len(columns0) and j<len(columns0):
sheet1.write_merge(i,i+5,0,0,columns0[j],set_style("微软雅黑", 220, True))
sheet1.write_merge(i,i+5,9,9)
i +=6
j +=1
sheet1.write_merge(37,37,0,1,u"合计",set_style("微软雅黑", 220, True))
i=0
while i < 6*len(columns0):
for j in range(0,len(status)):
sheet1.write(i+j+1,1,status[j])
i +=6
f.save("D:/PY/data_1217.xls")
if __name__ == '__main__':
write_excel()
结果:
来源:CSDN
作者:sara686
链接:https://blog.csdn.net/sara686/article/details/103578803