|
发表于 2024-8-21 19:29
来自手机
|
显示全部楼层
想飞的鱼888 发表于 2024-8-21 18:28
标题打错,是如何,不是如果
' utf8无BOM头编码写入文件
Function WriteUtf8WithoutBom( _
ByVal f As String, ByVal st As String)
Set stream = CreateObject("ADODB.stream")
Set BStream = CreateObject("ADODB.stream")
stream.Open
stream.Type = 2
stream.Charset = "utf-8"
stream.WriteText st
stream.Position = 3
BStream.Type = 1
BStream.Mode = 3
BStream.Open
stream.CopyTo BStream
stream.Flush
stream.Close
BStream.SaveToFile f, 2
BStream.Flush
BStream.Close
End Function
Sub utf8WBom()
Dim stxt$, af$, bf$, fso As Object
af = ThisWorkbook.Path & "\a.txt"
bf = ThisWorkbook.Path & "\b.txt"
Set fso = CreateObject("Scripting.FileSystemObject")
Set tf = fso.OpenTextFile(af, 1)
stxt = tf.readall '读取全部
Call WriteUtf8WithoutBom(bf, stxt)
Set tf = Nothing
Set fso = Nothing
End Sub |
|