VB中如何用OLE显示excel的中的图表????

VB中如何用OLE显示excel的中的图表(有两个图),并且excel的路径不是固定的。谢谢大家了,急用!

第1个回答  2015-06-26
快晕了
这也是问题?
窗体里放个OLE对象,放完就有了
随便找一个xls文件就可以
用的时候,改变OLE的 ole1.SourceDoc
这个属性就行了。
第2个回答  2010-12-10
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
第3个回答  2010-12-10
快晕了
这也是问题?
窗体里放个OLE对象,放完就有了
随便找一个xls文件就可以
用的时候,改变OLE的 ole1.SourceDoc
这个属性就行了本回答被网友采纳
相似回答