VB编的程序结果输出直接导入excel、txt。 100
有一个VB编的程序,但是他的计算结果不能直接导出进入txt、excel,使之实用性不强,网络高手众多,我想一定能破此难题,解决我的问题。如果你想试试1,加我qq:2219...
有一个VB编的程序,但是他的计算结果不能直接导出进入txt、excel,使之实用性不强,网络高手众多,我想一定能破此难题,解决我的问题。如果你想试试1,加我qq:2219968869,我将把程序发给你。
展开
2个回答
展开全部
提供一个过程方便你借鉴,示例是将数据集写入到表格,你可以将这个改成GRID到EXCEL,或者通用的。
'属性方法共有三个参数
'strcnn 连接对象
'strrs 数据集对象
'strpath EXCEL文件
Public Sub DbtoExcel(Strcnn As ADODB.Connection, Strrs As ADODB.Recordset, Strpath As String)
Dim i As Integer, j As Integer
On Error GoTo Err
Set Connquery = Strcnn '设置cnnquery属性
Set Rsquery = Strrs '设置rsquery属性
Set ObjExcel = New Excel.Application
Set ObjWorkBook = ObjExcel.Workbooks.Open(Strpath) '打开EXCEL文件
Set ObjSheet = ObjWorkBook.ActiveSheet
Set ObjRange = ObjSheet.UsedRange '用户使用过的工作表范围
For i = 1 To Rsquery.Fields.Count
ObjRange.Cells(1, i) = Rsquery.Fields(i - 1).Name
Next i
For j = 1 To Rsquery.RecordCount
For i = 0 To Rsquery.Fields.Count - 1
ObjRange.Cells(j + 1, i + 1) = Rsquery.Fields(i).Value
Next i
Rsquery.MoveNext
Next j
ObjExcel.Quit
Set ObjWorkBook = Nothing
Set ObjRange = Nothing
Set ObjSheet = Nothing
Set ObjExcel = Nothing
Exit Sub
Err:
MsgBox Err.Number & " " & Err.Description
Set ObjWorkBook = Nothing
Set ObjRange = Nothing
Set ObjSheet = Nothing
Set ObjExcel = Nothing
End Sub
'属性方法共有三个参数
'strcnn 连接对象
'strrs 数据集对象
'strpath EXCEL文件
Public Sub DbtoExcel(Strcnn As ADODB.Connection, Strrs As ADODB.Recordset, Strpath As String)
Dim i As Integer, j As Integer
On Error GoTo Err
Set Connquery = Strcnn '设置cnnquery属性
Set Rsquery = Strrs '设置rsquery属性
Set ObjExcel = New Excel.Application
Set ObjWorkBook = ObjExcel.Workbooks.Open(Strpath) '打开EXCEL文件
Set ObjSheet = ObjWorkBook.ActiveSheet
Set ObjRange = ObjSheet.UsedRange '用户使用过的工作表范围
For i = 1 To Rsquery.Fields.Count
ObjRange.Cells(1, i) = Rsquery.Fields(i - 1).Name
Next i
For j = 1 To Rsquery.RecordCount
For i = 0 To Rsquery.Fields.Count - 1
ObjRange.Cells(j + 1, i + 1) = Rsquery.Fields(i).Value
Next i
Rsquery.MoveNext
Next j
ObjExcel.Quit
Set ObjWorkBook = Nothing
Set ObjRange = Nothing
Set ObjSheet = Nothing
Set ObjExcel = Nothing
Exit Sub
Err:
MsgBox Err.Number & " " & Err.Description
Set ObjWorkBook = Nothing
Set ObjRange = Nothing
Set ObjSheet = Nothing
Set ObjExcel = Nothing
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
数据通过程序输出到文件很简单啊。
应该能很快输出啊?
Dim D_FILE As Integer
D_FILE = FreeFile
If Len(Trim(Dir(App.Path & "\Txt\"))) = 0 Then
MkDir "Txt"
End If
Open App.Path & "\Txt\Test.txt" For Input As #D_FILE
Do While Not EOF(D_FILE)
Line Input #D_FILE, Text1.text '这里根据你自己的逻辑写变量或者输出逻辑
Loop
Close #D_FILE
应该能很快输出啊?
Dim D_FILE As Integer
D_FILE = FreeFile
If Len(Trim(Dir(App.Path & "\Txt\"))) = 0 Then
MkDir "Txt"
End If
Open App.Path & "\Txt\Test.txt" For Input As #D_FILE
Do While Not EOF(D_FILE)
Line Input #D_FILE, Text1.text '这里根据你自己的逻辑写变量或者输出逻辑
Loop
Close #D_FILE
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |