如何用VB6.0实现用对话框选择excel文件,并调用其中数据存成数组后进行拟合计算

用对话框选择数据文件,调入数据并进行多项式回归
2024年11月18日 08:52
有1个网友回答
网友(1):

Dim a() As String, tem As String
Dim i As Integer
'运行前请"工程-引用" "Microsoft Excel 12.0 Object Library" 打钩
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Dim j As Integer
Private Sub Command1_Click()
'xlApp.NewWorkbook.Add ("E:\1.xls")
Set xlApp = CreateObject("Excel.Application") '创建EXCEL象
Set xlBook = xlApp.Workbooks.Open("E:\1.xls") '假设目标ExcelE盘
xlBook.Sheets("sheet1").Range("A1") = "间"
xlBook.Sheets("sheet1").Range("B1") = "直流电压"
xlBook.Sheets("sheet1").Range("C1") = "直流电流"
xlBook.Sheets("sheet1").Range("D1") = "侧电压"
xlBook.Sheets("sheet1").Range("E1") = "侧电流 "
Open "E:\1.txt" For Input As #1 '假设源数据文本E盘
k = 2
Do While Not EOF(1)
Line Input #1, tem

a() = Split(tem, " ")
For i = 0 To UBound(a)
a(i) = Trim(a(i))
If a(i) <> "" Then

xlBook.Sheets("sheet1").Range(Chr(Asc("A") + j) & k) = "'" & a(i)
j = j + 1
If j = 5 Then j = 0
End If
Next
k = k + 1
Loop
Close #1
xlBook.Save
xlBook.Close '关闭excel工作簿
Set xlApp = Nothing '释放excel程序
End Sub