怎样通过调用excel画统计图

jeary 2002-11-05 03:34:33
怎样通过调用excel画统计图
最好有例子 我的EMAIL :hongming_007@hotmail.com
...全文
82 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
lihonggen0 2002-11-06
  • 打赏
  • 举报
回复
Private Sub Command2_Click()
Dim pType As Integer '图表类型1---柱形图,2---饼图
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Add
Set xlSheet = xlBook.Worksheets(1)
xlSheet.Cells(1, 1).Value = "安徽"
xlSheet.Cells(1, 2).Value = 1
xlSheet.Cells(2, 1).Value = "天津"
xlSheet.Cells(2, 2).Value = 2
xlSheet.Cells(3, 1).Value = "四川"
xlSheet.Cells(3, 2).Value = 3

Charts.Add '添加图表
pType = 2 '图表类型1---柱形图,2---饼图
Select Case pType
Case 1 '1---柱形图
ActiveChart.ChartType = xlColumnClustered
ActiveChart.SetSourceData Source:=Sheets("Sheet1").Range("A1:B3"), PlotBy:= _
xlColumns
ActiveChart.Location Where:=xlLocationAsObject, Name:="Sheet1"
With ActiveChart
.HasTitle = False
.Axes(xlCategory, xlPrimary).HasTitle = False
.Axes(xlValue, xlPrimary).HasTitle = False
End With
Case 2 '2---饼图
ActiveChart.ChartType = xlPie
ActiveChart.SetSourceData Source:=Sheets("Sheet1").Range("A1:B3"), PlotBy:= _
xlColumns
ActiveChart.Location Where:=xlLocationAsObject, Name:="Sheet1"
With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = "分布情况统计图"
End With
End Select
'显示表格
Dim ExclFileName As String
ExclFileName = App.Path & "\统计图" & ".xls"
If Dir(ExclFileName) <> "" Then
Kill ExclFileName
End If
xlApp.Application.Visible = True
'交还控制给Excel
' xlSheet.PrintPreview
' xlApp.Application.Quit
' xlApp.Quit
' End With
End Sub

online 2002-11-05
  • 打赏
  • 举报
回复
www.ourfly.com演示

809

社区成员

发帖
与我相关
我的任务
社区描述
VB 多媒体
社区管理员
  • 多媒体
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧