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 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示