python 写入 excel(xlswriter)-- 生成图表
import xlsxwriter
path_excel = r"C:\Users\WY\Desktop\tuxing1.xlsx"
def create_Excel_shape(path_excel):
"""
创建 excel 插入数据 最重要的形式一个统计表 line: 线状图 ,area: 区域图,column:柱状图
:param path_excel:
:return:
"""
# 创建一个 excel
# 创建一个 excel
workbook = xlsxwriter.Workbook(r"C:\Users\WY\Desktop\tuxing.xlsx")
# 创建一个 sheet
worksheet = workbook.add_worksheet()
# worksheet = workbook.add_worksheet(“bug_analysis”)
# 自定义样式,加粗
bold = workbook.add_format({'bold': 2})
# --------1、准备数据并写入excel---------------
# 向excel中写入数据,建立图标时要用到
headings = ['Number', 'testA', 'testB']
data = [
['2017-9-1', '2017-9-2', '2017-9-3', '2017-9-4', '2017-9-5', '2017-9-6'],
[10, 40, 50, 20, 10, 50],
[30, 60, 70, 50, 40, 30],
]
# 写入表头
worksheet.write_row('A1', headings, bold)
# 写入数据
worksheet.write_column('A2', data[0])
worksheet.write_column('B2', data[1])
worksheet.write_column('C2', data[2])