vb 如何将函数数据保存为excel文件,请高手赐教!
说明:比如函数y=x^2,x从1到10,希望点击command,然后将x和y的值保存为一个excel文件,...
说明:比如函数y=x^2, x从1到10,希望点击command,然后将x和y的值保存为一个excel文件,
展开
展开全部
Option Explicit
Private Sub Command1_Click()
Dim xlapp As Excel.Application
Dim xlbook As Excel.Workbook
Dim xlsheet As Excel.Worksheet
Set xlapp = CreateObject("excel.application")
Set xlbook = xlapp.Workbooks.Add
Set xlsheet = xlbook.Worksheets("Sheet1")
dim i as integer
for i=1 to 10
xlsheet.cells(i,1)=i
xlsheet.cells(i,2)=i^2
next i
xlbook.SaveAs App.Path & "\" & "adbc.xls"
xlbook.Close
Set xlbook = Nothing
xlapp.Quit
Set xlapp = Nothing
End Sub
注:需要引用Excel对象。
Private Sub Command1_Click()
Dim xlapp As Excel.Application
Dim xlbook As Excel.Workbook
Dim xlsheet As Excel.Worksheet
Set xlapp = CreateObject("excel.application")
Set xlbook = xlapp.Workbooks.Add
Set xlsheet = xlbook.Worksheets("Sheet1")
dim i as integer
for i=1 to 10
xlsheet.cells(i,1)=i
xlsheet.cells(i,2)=i^2
next i
xlbook.SaveAs App.Path & "\" & "adbc.xls"
xlbook.Close
Set xlbook = Nothing
xlapp.Quit
Set xlapp = Nothing
End Sub
注:需要引用Excel对象。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询