экспорт в CSV - заголовки должны быть TEXT, а не GENERAL - PullRequest
0 голосов
/ 16 апреля 2020

У меня есть создатель CSV, который «работает».

Он принимает правильные поля в таблице в необходимом порядке и экспортирует в CSV на рабочем столе:

strAusPost = "SELECT tblTempAusPost.[Additional Label Information 1], tblTempAusPost.[Send Tracking Notifications], tblTempAusPost.[Send From Name], tblTempAusPost.[Send From Business Name], " & _
"tblTempAusPost.[Send From Address Line 1], tblTempAusPost.[Send From Address Line 2], tblTempAusPost.[Send From Address Line 3], tblTempAusPost.[Send From Suburb], tblTempAusPost.[Send From State],  " & _
"tblTempAusPost.[Send From Postcode], tblTempAusPost.[Send From Phone Number], tblTempAusPost.[Send From Email Address], tblTempAusPost.[Deliver To Name], tblTempAusPost.[Deliver To MyPost Number],  " & _
"tblTempAusPost.[Deliver To Business Name], tblTempAusPost.[Deliver To Type Of Address], tblTempAusPost.[Deliver To Address Line 1], tblTempAusPost.[Deliver To Address Line 2], " & _
"tblTempAusPost.[Deliver To Address Line 3], tblTempAusPost.[Deliver To Suburb], tblTempAusPost.[Deliver To State], tblTempAusPost.[Deliver To Postcode], tblTempAusPost.[Deliver To Phone Number], " & _
"tblTempAusPost.[Deliver To Email Address], tblTempAusPost.[Item Packaging Type], tblTempAusPost.[Item Delivery Service] , tblTempAusPost.[Item Description], tblTempAusPost.[Item Length], " & _
"tblTempAusPost.[Item Width], tblTempAusPost.[Item Height], tblTempAusPost.[Item Weight], tblTempAusPost.[Item Dangerous Goods Flag], tblTempAusPost.[Signature On Delivery], tblTempAusPost.[Extra Cover Amount] " & _
"FROM tblTempAusPost " & _
"WHERE (((tblTempAusPost.Deliver)=True))"

Set qdf = CurrentDb.QueryDefs("QuAusPostList")

        With qdf
            '.ReturnsRecords = True
            '.Connect = oCon
            .SQL = strAusPost
            'Debug.Print strSQL
        End With
Dim desktopFolderPath As String
desktopFolderPath = CreateObject("WScript.Shell").specialfolders("Desktop")
DoCmd.TransferText acExportDelim, , "QuAusPostStandard", desktopFolderPath & "\AusPost.csv", True

MsgBox "Your CSV file is on your desktop named 'AusPost'", vbInformation, ""

Проблема в том, что в CSV заголовок ОБЩИЙ, однако, если я загружаю его, он не работает.

Я связался со службой поддержки Почты Австралии, и они сказали, что заголовок должен быть ТЕКСТОМ, а НЕ ОБЩИМ как формат ...

Как мне этого добиться?

1 Ответ

1 голос
/ 19 апреля 2020

Чтобы экспортировать результаты в файл CSV:

1-Click on the table or query to export from (in this example “Top Ten Orders by Sales Amount” on the left)
2-Click the “External Data” tab at the top of the window
3-In the “Export” section click “Text File” and a wizard will appear
4-Choose a location for the exported CSV and name your file (make sure the file ends with a .csv extension)
5-Click OK
6-On the next screen be sure the “Delimited” option is selected
7-Click the “Advanced…” button in the lower left of the window
8-SpatialKey stores its data as Unicode UTF-8, we need to ensure that the data is exported in this format
    8.1-Click the drop-down box next to Code-Page
    8.2-Choose Unicode (UTF-8) in the options list
    8.3-Click OK
9-Back at the Export Text window click “Next”
10-Be sure “Comma” is selected as the delimiter and Text Qualifier is a double quote: “
11-Click the checkbox “Include Field Names on First Row” (should be selected)
12-Click “Next”
13-Verify the file name and location and click “Finish”
14-The final screen of the wizard gives you the option to save the steps allowing for easy re-exporting of the data in the future. If you anticipate needing to update the data in SpatialKey go ahead and check the checkbox to save some time in the future. 
15-Close the window when finished.

Если вы хотите решение VBA, попробуйте сделать это следующим образом.

Public Sub export_query()
    DoCmd.TransferText transferType:=acExportDelim, SpecificationName:="Query1 Export Specification", TableName:="Query1", FileName:="C:\test\Query1.txt", hasfieldnames:=True
End Sub

Или ...

Public Sub export_query()
    DoCmd.TransferText transferType:=acExportDelim, SpecificationName:="CSV Specification", TableName:="Query1", FileName:="C:\test\Query1.csv", hasfieldnames:=True
End Sub

Или ... экспортировать ВСЕ запросы ...

Public Sub export_query()
  Dim db As DAO.Database
  Dim qdf As DAO.QueryDef

  Set db = CurrentDb()
  For Each qdf In db.QueryDefs
    DoCmd.TransferText transferType:=acExportDelim, SpecificationName:="Query1 Export Specification", TableName:=qdf.Name, FileName:="C:\test\" & qdf.Name & ".txt", hasfieldnames:=True
  Next qdf
  Set qdf = Nothing
  Set db = Nothing
End Sub

Проверить ссылку ниже.

https://access-excel.tips/access-vba-docmd-transfertext-method/

...