假设RecordSet中已经有内容,怎样根据里面的字段导出Excel图表?(我是新手)
引用Microsoft Excel x.0
宏代码:
Range("A1:B2").Select
Charts.Add
ActiveChart.ChartType = xlColumnClustered
ActiveChart.SetSourceData Source:=Sheets("Sheet1").Range("A1:B2"), PlotBy:= _
xlRows
ActiveChart.Location Where:=xlLocationAsObject, Name:="Sheet1"
With ActiveChart
.HasTitle = False
.Axes(xlCategory, xlPrimary).HasTitle = False
.Axes(xlValue, xlPrimary).HasTitle = False
End With
先把数据转化到Excel中,
有关生成图的代码:
Dim ex As excel.Application
Dim Ct As Object
Set ex = CreateObject("Excel.Application")
打开工作表
Set newbook = ex.Workbooks.Open(App.Path & "\a.xls")
增加工作表
ex.Workbooks.Add
Set Ct = ex.Worksheets("sheet1").ChartObjects.Add(0, 280, 350, 250)
Ct.Chart.ChartWizard Source:=ex.range("A1:C6"), _
gallery:=xlLine, HasLegend:=False, Title:="流程压力变化曲线"
With ex.Worksheets("sheet1").ChartObjects(1).Chart
.ChartArea.Font.Size = 8
.ChartArea.Font.ColorIndex = 7
.HasDataTable = True
.DataTable.HasBorderOutline = True
.DataTable.ShowLegendKey = True
With .ChartTitle.Font
.Size = 10
.Color = RGB(0, 255, 0)
.Bold = True
.Background = xlBackgroundTransparent
End With
End With