我可以使用没有BOM的UTF-8导出excel数据吗? [英] Can I export excel data with UTF-8 without BOM?
问题描述
我通过Excel宏导出Microsoft Excel数据(VBScript)。
因为文件是lua脚本,我将其导出为UTF-8。
我可以在Excel中使用UTF-8的唯一方法是使用像这样的adodb.stream
I export Microsoft Excel data by Excel Macro(VBScript). Because file is lua script, I export it as UTF-8. The only way I can make UTF-8 in Excel is using adodb.stream like this
set fileLua = CreateObject("adodb.stream")
fileLua.Type = 2
fileLua.Mode = 3
fileLua.Charset = "UTF-8"
fileLua.Open
fileLua.WriteText("test")
fileLua.SaveToFile("Test.lua")
fileLua.flush
fileLua.Close
我想从Test.lua中删除BOM,但我不知道如何。
(因为Test.lua有一些unicode文本,我必须使用UTF-8格式。)
I want to make eliminate BOM from Test.lua but I don't know how. (Because Test.lua has some unicode text, I have to use UTF-8 format.)
你知道如何使UTF-8文件没有BOM在excel文件中?
提前感谢
Do you know how to make UTF-8 file without BOM in excel file? Thanks in advance.
推荐答案
我也有同样的问题:必须从Excel导出数据(Office 2003, VBA6.5)到UTF-8编码文件。找到你的问题的答案!在我的示例下面,我也从boost的(谢谢!)答案中使用诡计#2剥离BOM。我没有得到#1工作,从未尝试过#3。
I have also the same issue: have to export data from Excel (Office 2003, VBA6.5) to UTF-8 encoded file. Found the answer from your question ! Below my example where I also strip the BOM using trick #2 from boost's (thanks!) answer. I didn't get #1 working and never tried #3.
Sub WriteUTF8WithoutBOM()
Dim UTFStream As Object
Set UTFStream = CreateObject("adodb.stream")
UTFStream.Type = adTypeText
UTFStream.Mode = adModeReadWrite
UTFStream.Charset = "UTF-8"
UTFStream.LineSeparator = adLF
UTFStream.Open
UTFStream.WriteText "This is an unicode/UTF-8 test.", adWriteLine
UTFStream.WriteText "First set of special characters: öäåñüûú€", adWriteLine
UTFStream.WriteText "Second set of special characters: qwertzuiopõúasdfghjkléáûyxcvbnm\|Ä€Í÷×äðÐ[]í³£;?¤>#&@{}<;>*~¡^¢°²`ÿ´½¨¸0", adWriteLine
UTFStream.Position = 3 'skip BOM
Dim BinaryStream As Object
Set BinaryStream = CreateObject("adodb.stream")
BinaryStream.Type = adTypeBinary
BinaryStream.Mode = adModeReadWrite
BinaryStream.Open
'Strips BOM (first 3 bytes)
UTFStream.CopyTo BinaryStream
'UTFStream.SaveToFile "d:\adodb-stream1.txt", adSaveCreateOverWrite
UTFStream.Flush
UTFStream.Close
BinaryStream.SaveToFile "d:\adodb-stream2.txt", adSaveCreateOverWrite
BinaryStream.Flush
BinaryStream.Close
End Sub
我使用的ADO Stream Object reference 。
这篇关于我可以使用没有BOM的UTF-8导出excel数据吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!