doutouman6245 2016-05-27 15:07
浏览 224
已采纳

使用VBA从CSV /导入到Access的CSV导出 - schema.ini CharacterSet问题

I am currently working on a thing where I want to export various tables from a MySQL Database to csv files and it should then be possible to import those csv files into an Access database with VBA.

I managed to produce a download of a zip file that contains csv files and a schema.ini. For importing the csv files, I use roughly (loop is omitted for the sake of brevity) this code:

Sub ImportTableOne()
    Dim db As DAO.Database
    Set db = CurrentDb()
    frompart = "[Text;FMT=CSVDelimited;HDR=Yes;DATABASE=" & CurrentProject.Path & "\csvfiles\" & ";].[fileone.csv];"
    db.Execute _
    "SELECT * INTO tableone FROM" & frompart, dbFailOnError
    db.TableDefs.Refresh
    RefreshDatabaseWindow
End Sub

My problem is that I can either have CharacterSet=ANSI in my schema.ini which of course produces a result where for example í turns into í-. Changing things in the schema.ini to CharacterSet=UTF-8 will produce a run-time error 3000: reserved error (-5402).

I already tried to get the csv file to behave more UTF-8ish in php by adding a UTF-8 bom right after fopen() like so:

fputs($csvfile, chr(0xEF) . chr(0xBB) . chr(0xBF) );

When I open the csv files in excel or notepad++, the charset seems to be ok. When having the UTF-8 bom in php and trying to import, the bom just ends up being part of the first column heading like so: columnheadingone. That might not be very surprising for all I know about how the schema.ini works.

I would appreciate any hints as to how to resolve this.

  • 写回答

1条回答 默认 最新

  • douzhou7124 2016-05-27 15:53
    关注

    The "Text ISAM" driver and its associated "schema.ini" file do not support UTF-8 files because they pre-date the Unicode era. The "Selecting a Character Set" section of the MSDN document

    Schema.ini File (Text File Driver)

    says

    You can select from two character sets: ANSI and OEM.

    So, you will probably need to devise another way to import your data. If you want to use UTF-8 then you may be interested in a related question here.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

悬赏问题

  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部