python编辑excel做报表给manager看
来源:互联网 发布:姚明球衣退役 知乎 编辑:程序博客网 时间:2024/06/11 05:41
import xlrdimport osimport refrom numpy import arangeimport zipfileimport matplotlib.pyplot as pltimport redef read_excel_make_picture(file): workbook = xlrd.open_workbook(file) mySheet = workbook.sheet_by_index(0) filename = os.path.basename(file) counter_dict_by_mo_id = dict() # 获取文件中的时间数据 times = workbook.sheet_by_index(0).row_values(0) times.pop(0) #画图取得不同颜色的数组 color_sequence = ['#1f77b4', '#aec7e8', '#ff7f0e', '#ffbb78', '#2ca02c', '#98df8a', '#d62728', '#ff9896', '#9467bd', '#c5b0d5', '#8c564b', '#c49c94', '#e377c2', '#f7b6d2', '#7f7f7f', '#c7c7c7', '#bcbd22', '#dbdb8d', '#17becf', '#9edae5'] i = 0 # 循环分析excel中的每个sheet for table in workbook.sheets(): # 获取此sheet的mo mo = table.cell_value(0, 0) counter_dict_by_mo_id[mo] = dict() # 获取此sheet中包含的kpi keys = table.col_values(0) keys.pop(0) i += 1 plt.figure(i) # 循环获取每个kpi的具体数值 for index, key in enumerate(keys): data = table.row_values(index + 1) data.pop(0) counter_dict_by_mo_id[mo][key] = data # 读取sheets名字 count1 = len(workbook.sheets()) # 这里需要加一个正则表达式一个是对时间正则 reobj = re.compile(r'LR\d+_D\d+_E\d+') count = counter_dict_by_mo_id[mo] # 获取时间信息 temp_times = [] for time in times: temp_times.append(time[20:26] + '+' + time[35:39]) #print(temp_times) #figures取得是excel的count值 figures = [] for figure in keys: figures.append(figure[:]) #获取几个count x_label = len(figures) # 此处应该加一个循环获取figures的长度,根据长度设置子图,已加 figures_xnumber = [] for figures_number in count.values(): # print(figures_number) figures_xnumber.append(figures_number[:]) # print(figures_xnumber[0]) y1 = temp_times[:] x1 = arange(len(temp_times)) #设置图片的大小 fig=plt.figure(figsize=(20,10)) #循环取数 for x_number in arange(x_label): # print(x_number) ax = plt.subplot(x_label, 1, x_number + 1) if x_number==0: ax.set_title('kpi' + mo) RGB_number=x_number%len(color_sequence) RGB_color=color_sequence[RGB_number] ax.plot(figures_xnumber[x_number],linewidth=1,color=RGB_color, label=figures[x_number], ls=':', marker='o') # print(len(figures)) # print(figures[0]) box = ax.get_position() ax.legend(loc='upper right') #判断x轴长度 if len(temp_times)%2==0: cut_picutre=len(temp_times)/2 elif len(temp_times)%2==1: cut_picutre=len(temp_times)/2 - 1/2 ax.axvline(cut_picutre, color='black') plt.xticks(arange(len(temp_times)), temp_times[:], color='black', rotation=40) #保存文件 file_name = ('kpi' + '_' + mo).replace('.', '_') + '.png' plt.savefig(r'E:\test\\'+file_name, format='png') print(file_name + ' saved.') plt.close() zipAllPngFiles("E:\\test",filename) # temp_times.pop(0) #plt.show()def zipAllPngFiles(inputFolder,filename):#打包项目文件 res_name = os.path.join(inputFolder, filename+'.zip') f = zipfile.ZipFile(res_name, 'w', zipfile.ZIP_DEFLATED) for file in os.listdir(inputFolder): if file.endswith('.png'): f.write(os.path.join(inputFolder, file), file) f.close() print('********** zip all png files done !! **********')excel = r'E:\kpi_LR16_Avg_UL_Noise_per_PRB_Grp_01_OTH_addNOK_001a_dBm.xls'print(read_excel_make_picture(excel))
阅读全文
0 0
- python编辑excel做报表给manager看
- python 操作excel用来做考勤报表。
- jxl做excel报表
- Excel二次开发----C#.NET下做报表
- 在C#中利用Excel做报表
- [转]Excel与OWC做报表总结
- Excel与OWC做报表总结
- Excel与OWC做报表总结
- 用Excel做报表的试验
- Excel与OWC做报表总结
- Excel与OWC做报表总结(转载)
- 用Excel做报表的试验
- Excel与OWC做报表总结
- ASP.Net中使用Excel做报表
- Excel与OWC做报表总结
- Excel与OWC做报表总结
- Excel与OWC做报表总结
- JS + Xml + Excel 做报表(客户端生成)
- 二叉树递归问题 leetcode 572. Subtree of Another Tree & leetcode 110. Balanced Binary Tree
- java使用poi来写入excel
- Ubiquitous Religions POJ
- sql参数绑定
- DTW(Dynamic Time Warping / 动态时间归整) python实现
- python编辑excel做报表给manager看
- Angularjs 获取checkbox所有选中的值
- Leecode-Valid Parentheses
- JavaScript中的数据类型
- UML系列图-- 用例图
- Java集合---HashMap源码剖析
- 【计算机视觉】 相机姿态估计之标记检测-ArUco钻石标记的检测4
- 实习随手记--破产版小病毒
- MATLAB实用函数