doutouman6245 2016-05-27 23:07
浏览 221
已采纳

使用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 23: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 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划