csv是以逗号分隔列、每一行行尾回车换行的文本文件,以文本文件格式处理就行了。'例子: Private Sub Command1_Click() Adodc1.ConnectionString = _ "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\wgbc.mdb;Persist Security Info=False" Adodc1.CommandType = adCmdText Adodc1.RecordSource = "select top 10 * from [wgbc]" Adodc1.Refresh Open "c:\1.csv" For Output As #1
Dim tmp As String, i As Long While Not Adodc1.Recordset.EOF For i = 0 To Adodc1.Recordset.Fields.Count - 1 tmp = tmp & Adodc1.Recordset.Fields(i) & "," Next tmp = Left(tmp, Len(tmp) - 1) Print #1, tmp tmp = "" Adodc1.Recordset.MoveNext Wend Close #1 MsgBox "OK", , "OK"
End Sub
csv就是用逗号分隔的文本文件。没什么特别的
也就是txt文件而已,楼主想多了。
其实我觉得楼主想得还不够多,在2楼的基础上至少还应加上对双引号的处理 Option ExplicitPrivate Sub Command1_Click() Text1.Text = "H""ow""?" Text2.Text = AddDQuotes(Text1.Text) End Sub'========================================================== ' 函数: AddDQuotes ' ' 功能: 为一个字符串转换为CSV的一部分做引号处理,""""即是双引号" ' ' 返回: String ' ' 入口: strSrc 源字符串 ' Public Function AddDQuotes(ByVal strSrc As String) As String Const CDQuote = """"
AddDQuotes = CDQuote & Replace(strSrc, CDQuote, CDQuote & CDQuote) & CDQuote End Function
Private Sub Command1_Click()
Adodc1.ConnectionString = _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\wgbc.mdb;Persist Security Info=False"
Adodc1.CommandType = adCmdText
Adodc1.RecordSource = "select top 10 * from [wgbc]"
Adodc1.Refresh
Open "c:\1.csv" For Output As #1
Dim tmp As String, i As Long
While Not Adodc1.Recordset.EOF
For i = 0 To Adodc1.Recordset.Fields.Count - 1
tmp = tmp & Adodc1.Recordset.Fields(i) & ","
Next
tmp = Left(tmp, Len(tmp) - 1)
Print #1, tmp
tmp = ""
Adodc1.Recordset.MoveNext
Wend
Close #1
MsgBox "OK", , "OK"
End Sub
Option ExplicitPrivate Sub Command1_Click()
Text1.Text = "H""ow""?"
Text2.Text = AddDQuotes(Text1.Text)
End Sub'==========================================================
' 函数: AddDQuotes
'
' 功能: 为一个字符串转换为CSV的一部分做引号处理,""""即是双引号"
'
' 返回: String
'
' 入口: strSrc 源字符串
'
Public Function AddDQuotes(ByVal strSrc As String) As String
Const CDQuote = """"
AddDQuotes = CDQuote & Replace(strSrc, CDQuote, CDQuote & CDQuote) & CDQuote
End Function