• Access导出csv 内容添加双引号 vba


    要求:导出的csv文件,用文本工具打开时,文字内容需要有双引号,如下:"1","name1","name2",""

    我之前的处理方式是excel的方式导出,发现很难做到这个效果。所以我换了一种方案,直接将内容处理后写入文件

    首先选择保存文件的路径:

        Dim result As String
        With Application.FileDialog(msoFileDialogSaveAs)
            .Title = "Please select the target folder"
            .InitialFileName = "filename.csv"
                    
            If .Show = -1 Then
                result = .SelectedItems(1)
            Else
                Exit Function
            End If
        End With
      If Dir(result , vbNormal) <> "" Then
            Kill result
        End If

    然后处理内容

    Dim Obj_DataBase As DAO.Database
        Dim Obj_Recordset As DAO.Recordset
        Dim strLineConts As String
        Set Obj_DataBase = CurrentDb()
        Dim fileNo As Integer
        fileNo = FreeFile()
        
        strLineConts = ""
        strLineConts = strLineConts & Chr(34) & "列名1" & Chr(34) & ","
        strLineConts = strLineConts & Chr(34) & "列名2" & Chr(34)
        Print #fileNo, strLineConts
        strSQL = "Select * From 表名 Order By 字段1"
              
        Set Obj_Recordset = Obj_DataBase.OpenRecordset(strSQL)
        
        Do While Not Obj_Recordset.EOF
             strLineConts = ""
             strLineConts = strLineConts & Chr(34) & Obj_Recordset.Fields("值1") & Chr(34) & ","
             strLineConts = strLineConts & Chr(34) & Obj_Recordset.Fields("值2") & Chr(34)
             Print #fileNo, strLineConts
            Obj_Recordset.MoveNext
            i = i + 1
        Loop
        Close #fileNo
        Set Obj_DataBase = Nothing
        Set Obj_Recordset = Nothing
        Exit Function
  • 相关阅读:
    POJ 2513 (Trie树+欧拉通路+并查集判断连通)
    归并排序及序列逆序数
    POJ 2442 Sequence (堆+K路归并)
    POJ 2513 (Trie树+欧拉通路+并查集判断连通)
    J2EE概述
    J2EE概述
    J2EE概述
    学习视频资料下载论坛
    J2EE概述
    J2EE概述
  • 原文地址:https://www.cnblogs.com/fuge/p/6008683.html
Copyright © 2020-2023  润新知