1个回答
2015-07-30
展开全部
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
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
追问
这个并没有实现对话框选取数据啊
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询