Python writes Excel weekly statistics chart

Source: Internet
Author: User

650) this.width=650; "Width=" 805 "height=" 456 "src=" https://wuguiyunwei.com/wp-content/uploads/2017/04/ Py-execl.png "class=" Attachment-full size-full wp-post-image "style=" Border:none;vertical-align:middle;height:auto ; width:770px; "/>

    1. Installation module: Pip Install Xlsxwriter
    2. Directly copy the following code to save the file named wuguiyunwei.py
    3. Execution: Python wuguiyunwei.py

Note: You can modify the required parameters according to your business requirements.

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21st

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

#!/usr/bin/env python

#coding: Utf-8

Import Xlsxwriter

Workbook = Xlsxwriter. Workbook (' wugui.xlsx ') #创建一个Excel文件

Worksheet = Workbook.add_worksheet () #创建一个工作表对象

chart = Workbook.add_chart ({' type ':' column '}) #创建一个图表对象

#定义数据表开头列表

title = [u ' Business name ', U ' Monday ', U ' Tuesday ', U ' Wednesday ', U ' Thursday ', U ' Friday ', U ' Saturday ', U ' Sunday ', U ' average flow ']

Buname = [u ' Turtle Ops official website ', U ' turtle 1 ', U ' turtle 2 ', U ' turtle 3 ', U ' Turtle 4 '] #定义频道名称

#定义5频道一周七天数据列表

data = [

[134,432,348,349,565,435,158],

[176,168,94,53,68,700,91],

[251,265,154,165,540,154,135],

[77,76,75,74,73,73],

[81,82,83,84,91,83,82],

]

Format=workbook.add_format () #定义format格式对象

Format.set_border (1) format #定义format对象单元格边框加粗 (1 pixels)

Format_title=workbook.add_format () #定义format_title格式对象

Format_title.set_border (1) format #定义format_title对象单元格边框加粗 (1 pixels)

Format_title.set_bg_color (' #cccccc ') #定义format_title对象单元格背景颜色为 format of ' CCCCCC '

Format_title.set_align (' center ') #定义format_title对象单元格剧中对齐的格式

Format_title.set_bold () #定义format_title对象单元格内容加粗的格式

Format_ave=workbook.add_format () #定义format_ave格式对象

Format_ave.set_border (1) format #定义format_ave对象单元格边框加粗 (1 pixels)

Format_ave.set_num_format (' 0.00 ') #定义format_ave对象单元格数字类别显示格式

#下面分别以行或列写入方式将标题, business name, traffic data written to the original cell, referencing different format objects

Worksheet.write_row (' A1 ', title,format_title)

Worksheet.write_column (' A2 ', Buname,format)

Worksheet.write_row (' B2 ', Data[0],format)

Worksheet.write_row (' B3 ', Data[1],format)

Worksheet.write_row (' B4 ', Data[2],format)

Worksheet.write_row (' B5 ', Data[3],format)

Worksheet.write_row (' B6 ', Data[4],format)

#定义图表数据系列函数

def chart_series (Cur_row):

Worksheet.write_formula (' I ' +cur_row, ' =average (B ' +cur_row+ ': H ' +cur_row+ ') ', Format_ave) #计算 (AVERAGE function)

#频道周平均流量

chart.add_series ({

' categories ': ' =sheet1! $B $: $H ', #将 ' Monday to Sunday ' as an icon data label (x-axis)

' Values ': ' =sheet1! $B $ ' +cur_row+ ': $H $ ' +cur_row, #频道一周所有数据操作 for the data region

' line ':{' Color ':' Black '}, #线条颜色定义为black(Black)

' name ' : ' sheet1! $A $ ' +cur_row,

   })

For row in range (2,7): #数据域以第2 Line chart data series function call

Chart_series (str (ROW))

#chart. Set_table () #设置X轴表格格式, this example does not enable

#chart. Set_style (#设置图表样式), this example does not enable

chart.set_size ( ' width ' : 577, ' height ' : 287 } ) #设置图表大小

Chart.set_title ({' name ': u ' Business Traffic Weekly Report '}) #设置图表 ( Top) Big title

Chart.set_y_axis ({' name ': ' MB/s '}) #设置Y轴(left)Small Icons

( ' A8 ' Span class= "crayon-i" style= "Font-family:inherit;height:inherit;" >, chart Span class= "crayon-h" style= "Font-family:inherit;height:inherit;color:rgb (0,111,224);" > #在A8单元格插入图表

Workbook.close () #关闭Excel文档

Our public number

From Turtle Ops wuguiyunwei.com

650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M00/99/09/wKioL1lDSq_z5BdSAACeGDQ6kF0764.jpg "title=" Wg2weima.jpg "alt=" Wkiol1ldsq_z5bdsaacegdq6kf0764.jpg "/>

Python writes Excel weekly statistics chart

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.