Xlsxwriter Usage Example--Website Business Traffic Report
Mounting module
wget https://files.pythonhosted.org/packages/04/c9/d5a8b02561a32bfcbec767a7d094c1ce54874eba9bc6bbaa58dd9ad523e7 /xlsxwriter-1.0.4.tar.gz
Tar zxf xlsxwriter-1.0.4.tar.gz
CD XlsxWriter-1.0.4
Python setup.py Install
Official Website Reference Example http://xlsxwriter.readthedocs.io/chart_examples.html
#!/usr/bin/env python# -*- coding: utf-8 -*- import xlsxwriterworkbook= Xlsxwriter. Workbook (' chart.xlsx ') Worksheet=workbook.add_worksheet () Chart=workbook.add_chart ({' type ': ' column '}) chart1= Workbook.add_chart ({' type ': ' line '}) Chart2=workbook.add_chart ({' type ': ' column '}) Line_chart2=workbook.add_chart ( {' type ': ' Line '}) Chart3=workbook.add_chart ({' type ': ' line '}) Chart4=workbook.add_chart ({' type ': ' Pie '}) title=[u ' Business name ', U ' Monday ', U ' Tuesday ', U ' Wednesday ', U ' Thursday ', U ' Friday ', U ' Saturday ', U ' Sunday ', U ' average flow ']buname=[u ' Business official website ', U ' News Center ', u ' shopping channel ', U ' sports channel ', U ' parent channel ']data = [ [150,152,158,149,155,145,148], [89,88,95,93,98,100,99], [201,200,198,175,170,198,195], [75,77,78,78,74,70,79], [88,85,87,90,93,88,84]]format=workbook.add_format () Format.set_border (1) title_format=workbook.add_ Format () Title_format.set_border (1) title_format.set_bg_color (' #cccccc ') title_format.set_align (' center ') titlE_format.set_bold () Ave_format=workbook.add_format () Ave_format.set_border (1) Ave_format.set_num_format (' 0.00 ') Worksheet.write_row (' A1 ', Title,title_format) 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+ ') ', Ave_format) chart.add_series ({ ' categories ': ' =sheet1! $B $ $H ' , ' values ': ' = sheet1! $B $ ' +cur_row+ ': $H $ ' +cur_row, ' line ': {'Color ': ' Black '}, ' name ': ' =sheet1! $A $ ' +cur_row, }) for row in range (2,7): chart_series (str (ROW)) Chart1.add_series ({ ' categories ': ' =sheet1! $A: $A $6 ', ' values ': ' =sheet1! $I $ $I $6 ', ' marker ': {' type ': ' Diamond ', ' Size ': 7, ' color ': ' Green '}, ' data_labels ': {' value ': ' True '}, ' line ': {' color ': ' Blue '}, ' name ': U ' average flow distribution ' }) chart2.add_series ({ ' categories ': ' =sheet1! A2:a6 ', ' Values ': ' =sheet1! B2:b6 ', ' line ': {' Color ': ' Blue '}, ' name ': U ' Monday flow ' }) line_chart2.add_series ({ ' categories ': ' =sheet1! A2:a6 ', ' Values ': ' =sheet1! I2:i6 ',          &Nbsp; ' marker ': {' type ': ' Diamond ', ' Size ':7}, ' data_labels ': {' value ': ' True '}, ' line ': {' color ': ' Blue '}, ' name ': U ' average flow distribution ' }) Chart2.combine (Line_chart2) chart3.add_series ({ ' categories ': ' =sheet1! B1:h1 ', ' Values ': ' =sheet1! B2:h2 ', ' name ': U ' Business official website Traffic '}) chart3.add_series ({ ' categories ': ' =sheet1! B1:h1 ', ' Values ': ' =sheet1! B3:h3 ', ' name ': U ' News Center Traffic '}) chart3.add_series ({ ' categories ': ' =sheet1! B1:h1 ', ' Values ': ' =sheet1! B4:h4 ', ' name ': U ' Shopping Channel traffic '}) chart3.add_series ({ ' categories ': ' =sheet1! B1:h1 ', ' Values ': ' =sheet1! B5:h5 ', ' name ': U ' Sports Channel flow '}) chart3.add_series ({ ' categories ': ' =sheet1! B1:h1 ', ' Values ': ' =sheet1! B6:h6 ', ' name ': U ' Parent Channel flow '}) chart4.add_series ({ ' categories ': ' =sheet1! A2:a6 ', ' Values ': ' =sheet1! I2:i6 ', ' Data_ Labels ': {' value ': ' True '}, ' name ': U ' average flow distribution '}) chart.set_size ({' width ': 577, ' height ': 287}) Chart.set_title ({' Name ': U ' Business Traffic Report '}) Chart.set_y_axis ({' name ': ' MB/s} ') Chart1.set_size ({' width ': 577, ' height ': 287}) Chart1.set_title ({' Name ': U ' Business Traffic Report '}) Chart1.set_y_axis ({' name ': ' MB/s} ') Chart2.set_size ({' width ': 577, ' height ': 287}) Chart2.set_title ({' Name ': U ' business Traffic Report '}) Chart2.set_y_axis ({' name ': ' MB/s} ') Chart3.set_size ({' width ': 577, ' height ': 287}) Chart3.set_title ({' Name ': U ' Business Traffic Report '}) Chart3.set_y_axis ({' name ': ' MB/s '}) chart4.set_size ({' width ': 577, ' height ': 287}) Chart4.set_title ({' Name ': U ' Business Traffic Report '}) Chart4.set_y_axis ({' name ': ' MB/s '}) Worksheet.insert_chart (' A8 ', chart) Worksheet.insert_chart (' K8 ', Chart1) worksheet.insert_chart (' A24 ', Chart2) worksheet.insert_chart (' K24 ', chart3) Worksheet.insert_chart (' A40 ', Chart4) workbook.close ()
Python chart.py
Run Results production chart.xlsx file
Python uses the Xlsxwriter module to generate and process Excel documents