openpyxl的作图功能也很强大。大家可以参考openpyxl的官方网站:openpyxl作图。里面有讲解也有例子。 这里把其他中一个例子拿出来,大家可以参考一下。的确非常的简单容易上手。 不过毕竟python是编程语音,不是动动手就可以得到结果的。简单的数据处理还是使用excel的自带函数与功能比较方便快捷。复杂的数据处理,我相信python比excel VBA更强大。不说别的,numpy,scipy是绝对强悍的数据处理程序包,甩excel VBA 360条街!大家熟悉的人工智能,很多矩阵计算与处理也是基于numpy的! 所以,要精通python处理excel,还是要学习numpy的。pandas 也可以学习学习。python上手很快,但是精通很难。不过你会用python+numpy处理excel数据,绝对可以领先同事一步!
from openpyxl import Workbook from openpyxl.chart import ( AreaChart, Reference, Series, ) file_name = "abc.xlsx" wb = Workbook() ws = wb.active rows = [ ['Number', 'Batch 1', 'Batch 2'], [2, 40, 30], [3, 40, 25], [4, 50, 30], [5, 30, 10], [6, 25, 5], [7, 50, 10], ] for row in rows: ws.append(row) chart = AreaChart() chart.title = "Area Chart" chart.style = 13 chart.x_axis.title = 'Test' chart.y_axis.title = 'Percentage' cats = Reference(ws, min_col=1, min_row=1, max_row=7) data = Reference(ws, min_col=2, min_row=1, max_col=3, max_row=7) chart.add_data(data, titles_from_data=True) chart.set_categories(cats) ws.add_chart(chart, "A10") wb.save(file_name)