Access 正在用 .导出到 csv 时

问题描述

我有一个将数据导出到 csv 的小型访问程序。 csv 需要具有包含 # 的字段标题。但是,当我使用 VBA 导出时:

DoCmd.TransferText acExportDelim,"ThisExport","GeneralQuery","C:\ThisFile\data.csv",True

它将#'s 变成.'s:

enter image description here

enter image description here

解决方法

一种方法使用 UNION 查询:

SELECT 0 AS Cat,"Email #1" AS A,"Email #2" AS B,"Email #3" AS C FROM Table1
UNION SELECT 1,[Email #1],[Email #2],[Email #3] FROM Table1;

将 TransferText HasFieldNames 参数设置为 False 并导出查询。

但是,如果您的导入应用程序无法处理 Cat 字段的存在,请使用文本文件读/写方法。这是一个相当普遍的话题。使用 TransferText 导出数据,然后使用读/写方法进行修改。