通过访问创建逗号分隔文件(csv)-每天从Windows安排 [英] Create comma separated file (csv) from access - scheduled daily from windows

查看:79
本文介绍了通过访问创建逗号分隔文件(csv)-每天从Windows安排的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个vbs文件以将访问表导出为csv文件(以逗号分隔). 我从雷木那里看到了这个尾声.它可以工作,但是创建的制表符分隔开.谁能帮我? 谢谢!

I would like to create a vbs file to export an access table in a csv file (comma separated). I saw this coda from Remou. It works, but it create tab separated. Can anyone help me? Thank you!

db = "C:\Docs\LTD.mdb"
TextExportFile = "C:\Docs\Exp.txt"

Set cn = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.Recordset")

cn.Open _
   "Provider = Microsoft.Jet.OLEDB.4.0; " & _
   "Data Source =" & db

strSQL = "SELECT * FROM tblMembers"

rs.Open strSQL, cn, 3, 3

Set fs = CreateObject("Scripting.FileSystemObject")

Set f = fs.CreateTextFile(TextExportFile, True)

a = rs.GetString

f.WriteLine a

f.Close

推荐答案

创建标准CSV并不难

Set cn = CreateObject("ADODB.Connection")

cn.Open "Provider=Microsoft.Ace.OLEDB.12.0;Data Source=z:\Docs\test.accdb"

sSQL = "select * into " 
sSQL= sSQL & "[text;database=z:\docs\;FMT=Delimited;HDR=Yes].[csvfile.csv]"
sSQL= sSQL & " from table1"

cn.Execute sSQL

VBScript文件将在任务计划程序中很好地运行.

A VBScript file will run quite well from the Task Scheduler.

编辑评论

如果语言环境中的小数点分隔符是逗号,则可能会遇到问题.您可以使用schema.ini文件覆盖Windows区域设置,只需要包含文件名和要更改的项目即可.

If the decimal separator in your locale is a comma, you may run into problems. You can override the Windows locale settings with a schema.ini file, you need only include the name of the file and items you wish to change:

[csvfile.csv]
DecimalSymbol=.

Microsoft提供了完整列表:架构. ini

A full list is available form Microsoft: Schema.ini

没有理由在导出之前不应该在代码中编写schema.ini,除非确保不覆盖现有模式-您可以追加.

There is no reason why you should not write the schema.ini in your code prior to export, except be sure not to overwrite existing schemas -- you can append.

您将从Windows控制面板获取有关系统语言环境的信息:

You will get information on your system locale from the windows control panel: http://windows.microsoft.com/en-IE/windows7/Change-the-system-locale

这篇关于通过访问创建逗号分隔文件(csv)-每天从Windows安排的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆