使用openpyxl生成包含echarts柱形图的Excel文件
使用openpyxl生成包含echarts柱形图的Excel文件 效果图如下: 代码如下: from openpyxl import Workbook from openpyxl.chart import BarChart, Series, Reference wb = Workbook(write_only=True) ws = wb.create_sheet() rows = [ ('时间', '男', '女'), (2015, 70414, 67048), (2016, 70815, 67456), (2017, 71137, 67871), (2018, 71351, 68187), (2019, 71527, 68478) ] for row in rows: ws.append(row) chart1 = BarChart() chart1.type = "col" chart1.style = 1 chart1.title = "柱形图" chart1.y_axis.title = '数量(万人)' chart1.x_axis.title = '时间' data = Reference(ws, min_col=2, min_row=1, max_row=6, max_col=3) cats = Reference(ws, min_col=1, min_row=2,