我写了个模块函数,用来把sql数据库导出成txt文件,出来效果是每一列之间都会有一个空格间隔,例如:0052135199011 赵燕梅                                       
0052423253011 赵同晃                                       
0065310602011 吴伟庭                                        
0063829765011 陈文利  我不想要这个空格如:0052135199011赵燕梅                                       
0052423253011赵同晃                                       
0065310602011吴伟庭                                        
0063829765011陈文利  以下是函数内容,请各位大大指教,应该怎么改才能达到要求,谢谢。Public Function TabintoTxt(objConn As Object, TableName As String, Optional TextFileName As String)
        Dim rs As New ADODB.Recordset
        Set rs = New ADODB.Recordset
        Dim i As Long
        Dim s As String
        Dim imax As Integer
        Dim WritStr As String
        Dim writstry() As String
        Dim Fid As Long
        Dim lngCount As Long              ' 计数。        If TextFileName = "" Then
          If Month(Date) < 10 Then
              TextFileName = "e:\data\" & "sf" & Year(Date) & "0" & Month(Date) - 1 & ".txt"
            Else
                TextFileName = "e:\data\" & "sf" & Year(Date) & Month(Date) - 1 & ".txt"
          End If
        End If
        If objConn.State = 0 Then objConn.Open
        rs.Open "select * from " + TableName, objConn        Fid = FreeFile
        rs.MoveFirst
        Open TextFileName For Output As #Fid
           ReDim writstry(rs.Fields.Count - 1)
           While Not rs.EOF
                 'writstry(0) = Format(Trim(rs(0)), "!@@@@@@@@@@@@@")
                 writstry(0) = Trim(rs.Fields(0))
                 writstry(1) = LTrim(rs.Fields(1))
                 writstry(2) = Format(Trim(rs(2)), String(8, "@"))
                 writstry(3) = Format(Trim(rs(3)), "@@@@@@@     ")
                 writstry(4) = Format(Trim(rs(4)), "@")
                 Print #Fid, Join(writstry)
                 rs.MoveNext
                 lngCount = lngCount + 1
           Wend
        Close #Fid
        rs.Close
        MsgBox "导出 " & Format(lngCount) & " 笔记录。"
        
End Function
                                      

解决方案 »

  1.   

    Print #Fid, trim(Join(writstry))
      

  2.   

    Print #Fid, Join(writstry,"")
      

  3.   

    Join函数 返回 描述返回一个字符串,该字符串是通过连接某个数组中的多个子字符串而创建的。语法Join(list[, delimiter])Join函数语法有如下几部分:部分 描述 
    list 必需的。包含被连接子字符串的一维数组。 
    delimiter 可选的。在返回字符串中用于分隔子字符串的字符。如果忽略该项,则使用空格(" ")来分隔子字符串。如果delimiter是零长度字符串(""),则列表中的所有项目都连接在一起,中间没有分隔符。