如何生成embeddedgraphics的Excel电子表格?

我想创buildembedded式图表的Excel电子表格。 理想情况下,我想在Mac上使用Python。 如果我不能这样做,我想用Mac上的某种Excel自动化来实现。 如果我不能这样做,我愿意在Windows上通过COM来操作Excel,但是我仍然希望从Python中完成。 有没有人有任何代码? 谢谢。

以下是Windows上的Python COM的一个基本示例:

import win32com.client from win32com.client import constants as c xl = win32com.client.gencache.EnsureDispatch('Excel.Application') xl.Visible = True wb = xl.Workbooks.Add() ws = xl.ActiveSheet ws.Range('A1').FormulaR1C1 = 'X' ws.Range('B1').FormulaR1C1 = 'Y' ws.Range('A2').FormulaR1C1 = 1 ws.Range('A3').FormulaR1C1 = 2 ws.Range('A4').FormulaR1C1 = 3 ws.Range('B2').FormulaR1C1 = 4 ws.Range('B3').FormulaR1C1 = 5 ws.Range('B4').FormulaR1C1 = 6 ws.Range('A1:B4').Select() ch = ws.Shapes.AddChart().Select() xl.ActiveChart.ChartType = c.xlXYScatterLines xl.ActiveChart.SetSourceData(Source=ws.Range("A1:B4")) 

它是通过在Excel中录制一个macros来翻译的。 这是macros,所以你可以看到它是多么相似。 在Excel中logging你想要做的事情,并将其翻译成Python语法:

 Sub Macro1() ' ' Macro1 Macro ' ' ActiveCell.FormulaR1C1 = "X" Range("B1").Select ActiveCell.FormulaR1C1 = "Y" Range("A2").Select ActiveCell.FormulaR1C1 = "1" Range("A3").Select ActiveCell.FormulaR1C1 = "2" Range("A4").Select ActiveCell.FormulaR1C1 = "3" Range("B2").Select ActiveCell.FormulaR1C1 = "4" Range("B3").Select ActiveCell.FormulaR1C1 = "5" Range("B4").Select ActiveCell.FormulaR1C1 = "6" Range("A1:B4").Select ActiveSheet.Shapes.AddChart.Select ActiveChart.ChartType = xlXYScatterLines ActiveChart.SetSourceData Source:=Range("Sheet1!$A$1:$B$4") End Sub 

我知道在Mac上处理Excel的主要工具是xlrd / xlwt和Excel 2004 XML格式。 AFAICT,这些都不支持embedded式graphics。

所以,我认为这只剩下了在Windows上通过COM来操作Excel的选项。