【发布时间】:2019-05-20 16:15:13
【问题描述】:
我正在尝试将大型 txt 文件拆分为多个 txt 文件(编码 UTF-8)。我使用的语言是亚洲语言。
我尝试了一些 VBA 和 Python 代码,但无法完成。
Sub ExportTextFiles()
Dim i As Long
Dim LastDataRow As Long
Dim MyFile As String
Dim fnum
LastDataRow = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row
For i = 1 To LastDataRow
'The next line uses the contents of column A on the same row to name it
MyFile = "C:\Users\grego\Downloads\" & ActiveSheet.Range("A" & i).Value & ".txt"
'Use the following line instead to just create a series of numbered files
'MyFileName = "C:\Users\grego\Downloads\" & i & ".txt"
fnum = FreeFile()
Open MyFile For Output As fnum
Print #fnum, Format(Range("B" & i))
Close fnum
Next i
End Sub
这个宏运行良好,但输出是 ANSI,而不是 Unicode,我得到的是问号字符串。任何帮助将非常感激!我也可以使用一些 python。
【问题讨论】: