导入带有外来字符的文本 [英] Import text with foreign characters

查看:68
本文介绍了导入带有外来字符的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有将许多文本文件(包含外来/特殊字符)导入Excel工作簿的代码:

I have code which imports many text documents, containing foreign/special characters, into an Excel workbook:

Sub loadfiles()

    Dim fpath As String
    Dim fname As String
    Application.ScreenUpdating = False

    fpath = "...\data\"
    fname = Dir(fpath & "*.txt")
    For i = 1 To 10
    Application.StatusBar = True
    Application.StatusBar = "Progress: " & i & " of 10000"
        Sheet1.Select
        Range("A" & i).Value = fname
        With ActiveSheet.QueryTables.Add(Connection:="TEXT;" _
          & fpath & fname, Destination:=Range("B" & i))
            .Name = "a"
            .FieldNames = True
            .RowNumbers = False
            .FillAdjacentFormulas = False
            .PreserveFormatting = False
            .RefreshOnFileOpen = False
            .RefreshStyle = xlInsertDeleteCells
            .SaveData = True
            .AdjustColumnWidth = False
            .RefreshPeriod = 0
            .TextFilePromptOnRefresh = False
            .TextFilePlatform = 437
            .TextFileStartRow = 1
            .TextFileParseType = xlDelimited
            .TextFileTextQualifier = xlTextQualifierDoubleQuote
            .TextFileConsecutiveDelimiter = False
            .TextFileTabDelimiter = False
            .TextFileColumnDataTypes = _
             Array(xlTextFormat, xlSkipColumn, xlGeneralFormat)
            .Refresh BackgroundQuery:=False
            fname = Dir
        End With
    Next i
    Application.StatusBar = False
    Application.ScreenUpdating = True
    MsgBox "Done"
End Sub

有什么方法可以在不丢失原始字符的情况下导入文本?

Is there any way to import text without losing original characters?

推荐答案

尝试添加

.QueryType = xlTextImport

并更改

.TextFilePlatform = xlMSDOS

.PreserveFormatting = True

这篇关于导入带有外来字符的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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