我需要转换" ANSI" csv文件到" UTF-8" csv文件。 下面的代码可以工作,但第一个字符错过 请参阅随附的屏幕截图, 原始文件:客户 输出文件:﨏ustomer
Function Convert(myFileIn, myFileOut)
Dim stream ,strTextText
Set stream = CreateObject("ADODB.Stream")
stream.Open
stream.Type = 2 'text
stream.LoadFromFile myFileIn
stream.Position = 0
stream.Charset = "gb2312"
strText = stream.ReadText
stream.Close
stream.Open
stream.Type = 2
stream.Position = 0
stream.Charset = "utf-8"
stream.WriteText strText
stream.SaveToFile myFileOut, 2
stream.Close
Set stream = Nothing
End Function
答案 0 :(得分:6)
你必须设置
stream.Type
和
stream.Charset
在打开流之前。
默认情况下,stream.Position为0。
问候
阿克塞尔