用VB中的控件显示Excel中的图表

请问哪位大侠知道如何用VB中的image或picturebox控件显示excel中的图表(ChartObject),本人急用,不胜感谢!... 请问哪位大侠知道如何用VB中的image或picturebox控件显示excel中的图表(ChartObject),本人急用,不胜感谢! 展开
 我来答
夏虫不可语冰dP
2008-05-28 · TA获得超过490个赞
知道小有建树答主
回答量:227
采纳率:0%
帮助的人:0
展开全部
Function Save_Excel_Data() As Boolean
Save_Excel_Data = False

Dim Excel_File As String
Dim ExcelSave As Boolean

On Error GoTo err1
CommonDialog1.FileName = ""
CommonDialog1.Filter = "EXCEL (*.xls)|*.xls|"
CommonDialog1.FilterIndex = 1
CommonDialog1.ShowSave

If Err <> 32755 Then
Excel_File = CommonDialog1.FileName

If Dir(Excel_File) <> "" Then Kill Excel_File

Set sf1 = CreateObject("Excel.Application")

sf1.Workbooks.Add
Set sf2 = sf1.Workbooks(1)
Set sf3 = sf2.ActiveSheet

Dim x(1 To 3) As Integer, y(1 To 3) As Integer
x(1) = 1
x(2) = 2
x(3) = 9
y(1) = 12
y(2) = 5
y(3) = 19

sf3.Cells(1, 1).Value = x(1)
sf3.Cells(2, 1).Value = x(2)
sf3.Cells(3, 1).Value = x(3)
sf3.Cells(1, 2).Value = y(1)
sf3.Cells(2, 2).Value = y(2)
sf3.Cells(3, 2).Value = y(3)

sf2.Charts.Add
sf2.ActiveChart.Location 2, "Sheet1"
sf2.ActiveChart.ChartType = 72
sf2.ActiveChart.SeriesCollection(1).XValues = "=Sheet1!R1C1:R3C1"
sf2.ActiveChart.SeriesCollection(1).Values = "=Sheet1!R1C2:R3C2"

sf3.Shapes("图表 1").ScaleWidth 1.2, 0, 0
sf3.Shapes("图表 1").ScaleHeight 1.2, 0, 0

'picturebox控件显示excel中的图表
sf2.ActiveChart.ChartArea.Select
sf2.ActiveChart.ChartArea.Copy
form1.Picture1.Picture = Clipboard.GetData

sf3.SaveAs Excel_File

sf3.Application.Quit
Set sf3 = Nothing
Set sf2 = Nothing
Set sf1 = Nothing
End If

Save_Excel_Data = True

Exit Function
err1:
MsgBox Err.Number
End Function
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式