我正在为作业编写一些代码,我需要在 Excel 中创建一个简单的柱形图。今天下午我找到了win32com(顺便说一句很棒的工具),但是我一直在为缺乏关于它的文档而苦恼,或者我没有运气找到它^^
我正在玩图表,我想我已经设法做我想做的事,但有一点例外:我编写的函数总是创建 2 个系列的列。
这就是我所拥有的:
xlBook = xlApp.Workbooks.Add()
xlSheet = xlBook.Sheets(1)
xlSheet.Name = "Algoritmos de Busqueda"
xlSheet.Cells(1,1).Value="Secuencial"
xlSheet.Cells(2,1).Value="Binaria"
xlSheet.Cells(1,2).Value="32"
xlSheet.Cells(2,2).Value="32"
chart = xlApp.Charts.Add()
chart.Name= "Grafico "+xlSheet.Name
series = chart.SeriesCollection().NewSeries()
valoresx=xlSheet.Range("A1:A2")
valoresy=xlSheet.Range("B1:B2")
series.XValues= valoresx
series.Values= valoresy
series.Name= "Algoritmos"
xAxis= chart.Axes()[0]
yAxis= chart.Axes()[1]
xAxis.HasMajorGridlines = True
yAxis.HasMajorGridlines = True
我在图表中创建了一个新系列,其中包含我需要的所有信息。但是,当我运行脚本时,我最终得到一个包含 4 列的 Excel 图表,具有相同的信息(成对)。我已尽我所能,但我只是找不到在 X 轴上创建第二系列值的原因......
我非常感谢任何帮助^^谢谢!