下面的代码,问题出在Cht.ChartArea.Fill.Visible = True,它是用来显示图表区的填充颜色的。只要把这行去掉,代码运行正常:
Dim App As New MSExcel.Application
Dim Wb As MSExcel.WorkBook = App.WorkBooks.Open("D:\Report.xls")
Dim Ws As MSExcel.WorkSheet = Wb.WorkSheets(1)
Dim Rg As MSExcel.Range = Ws.Range("A2:C7")
Dim Co As MSExcel.ChartObject = Ws.ChartObjects.Add(100,30,400,250)
Dim Cht As MSExcel.Chart = Co.Chart
Cht.ChartType = MSExcel.XlChartType.xlColumnClustered
Cht.SetSourceData(Rg,MSExcel.XlRowCol.xlColumns)
With Cht.ChartArea.Border
.Weight = 2
.LineStyle = -1
End With
Ws.DrawingObjects(1).RoundedCorners = True
Ws.DrawingObjects(1).Shadow = True
'Cht.ChartArea.Fill.Visible = True
App.Visible = True
如果加上这行代码,就会提示以下错误:
此主题相关图片如下:11.jpg
是不是还要再引用其它文件?