Mac Excel生成UTF-8 [英] Mac Excel generate UTF-8

查看:672
本文介绍了Mac Excel生成UTF-8的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在Mac版Excel 2016中使用Visual Basic(VBA)生成UTF-8文件? 我需要生成一个经过编码的XML或TXT文件.

Is it possible to generate a UTF-8 file using Visual Basic (VBA) in Excel 2016 for Mac? I need to generate an XML or TXT file that is encoded.

谢谢

推荐答案

VBA内部使用的不是UTF-8,而是 UTF-16 ,因此您可以直接转储字符串数据:

Not UTF-8, but UTF-16 is what VBA uses internally, so you can dump string data directly:

Dim fnum As Integer
fnum = FreeFile()
Open "utf16.txt" For Binary Access Write As fnum

'write UTF-16 Byte Order Marker
'
Put #fnum, 1, &HFE
Put #fnum, 2, &HFF

printLineUtf16 fnum, "Olá Mundo!"

Close #fnum

Function printLineUtf16(fnum As Integer, str As String)

    str = str & ChrW(10)            'append newline

    Dim data() As Byte              'coerce string to bytes
    data = str

    Put #fnum, LOF(fnum) + 1, data  'append bytes to file

End Function

这应该在Excel Mac 2011和2016以及Windows版本中有效.请注意,您将无法在编辑器中键入Unicode字符串文字,只能使用简单的带有重音符号的拉丁字母(如上面的á"),但是从单元格的Value分配的字符串将保留在Unicode中.

This should work in Excel Mac 2011 and 2016, and in Windows versions. Note that you won't be able to type Unicode string literals in the editor, just simple accented Latin letters like the "á" above, but strings assigned from the Value of a cell will be preserved in Unicode.

这篇关于Mac Excel生成UTF-8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆