當前位置:編程學習大全網 - 源碼下載 - 用VB中的控件顯示Excel中的圖表

用VB中的控件顯示Excel中的圖表

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

  • 上一篇:綠蘿為什麽會滴水
  • 下一篇:求壹個好用的PS下載地址
  • copyright 2024編程學習大全網