导出为 CSV - headers 为 TEXT 而不是 GENERAL
export to CSV - headers to be TEXT not GENERAL
我有一个 CSV 创建器,它是 'working'。
它按照需要的顺序获取 table 中的正确字段,并在桌面上导出为 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, ""
问题是 header 在 CSV 中是通用的,但是如果我上传它就不起作用。
我联系了澳大利亚 Post 支持,他们说 header 必须是 TEXT 而不是 GENERAl 格式...
我怎样才能做到这一点?
要将结果导出到 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
查看下面的 link。
https://access-excel.tips/access-vba-docmd-transfertext-method/
我有一个 CSV 创建器,它是 'working'。
它按照需要的顺序获取 table 中的正确字段,并在桌面上导出为 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, ""
问题是 header 在 CSV 中是通用的,但是如果我上传它就不起作用。
我联系了澳大利亚 Post 支持,他们说 header 必须是 TEXT 而不是 GENERAl 格式...
我怎样才能做到这一点?
要将结果导出到 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
查看下面的 link。
https://access-excel.tips/access-vba-docmd-transfertext-method/