vb生成数据,用excel输出并自动画曲线
我用vb生成了两个数组,X(i),Y(i)想用vb直接调用excel输出数据x,y并以x为横坐标,y为纵坐标描点法作连成曲线请问大侠怎做?详细点,谢谢!...
我用vb生成了两个数组,X(i),Y(i)
想用vb直接调用excel输出数据x,y
并以x为横坐标,y为纵坐标描点法作连成曲线
请问大侠怎做?
详细点,谢谢! 展开
想用vb直接调用excel输出数据x,y
并以x为横坐标,y为纵坐标描点法作连成曲线
请问大侠怎做?
详细点,谢谢! 展开
2个回答
展开全部
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.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
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.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
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询