本文介绍了Excel数据转换为XML会用法语单词输入错误的字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有测试脚本(采用XML),并且需要翻译(来自Excel工作表).我正在从该Excel工作表中搜索英语单词,然后将其翻译为德语,法语和意大利语.我的法语单词有问题.

I have test script (in XML) and I need translation (from Excel sheet). I am searching for words in English from that Excel sheet and then translating them to German, French and Italian. I have problem with French words.

我正在 VBA 中使用宏.当我找到对应于法语的法语单词时,我使用的是查找功能.当我在Excel工作表中找到法语单词时,我只是将int保存到 String .

I am using Macro in VBA. When I am finding the corresponding word in French for English one, I am using function Find. When I find French word in Excel sheet, I am just saving int into String.

代码

If intChoice <> 0 Then

strPath = Application.FileDialog( _
msoFileDialogOpen).SelectedItems(1)

Dim strFolderPath As String
strFolderPath = Left(strPath, Len(strPath) - 4)
Set fGermanOutputFile = fso.CreateTextFile((strFolderPath & "_German.xml"))
Set fItalianOutputFile = fso.CreateTextFile((strFolderPath & "_Italian.xml"))
Set fFrenchOutputFile = fso.CreateTextFile((strFolderPath & "_French.xml"))

    Open strPath For Input As #1


Do Until EOF(1)
    Line Input #1, strLine

    intLastFoundChar = 0

    strGermanLine = ""
    strFrenchLine = ""
    strItalianLine = ""

    For intI = 0 To (UBound(ArrStrOpeningTags, 1) - 1)

        intFoundString = InStr(strLine, ArrStrOpeningTags(intI))
        If intFoundString <> 0 Then
            intI = 3
        End If

    Next intI

    If intFoundString <> 0 Then

        For intJ = 0 To (UBound(ArrStrParamsToReplace) - 1)


            strLine = Right(strLine, Len(strLine) - intLastFoundChar)

            strStringToLookFor = (ArrStrParamsToReplace(intJ) & "=""")

            intFoundString = InStr(1, strLine, strStringToLookFor, vbBinaryCompare)

            If intFoundString <> 0 Then
                intStringSplitIndex = (intFoundString + Len(strStringToLookFor))

                strStringToLookFor = Right(strLine, Len(strLine) - intStringSplitIndex + 1)


                strDummyString = Left(strLine, intStringSplitIndex - 1)
                strGermanLine = strGermanLine & strDummyString
                strFrenchLine = strFrenchLine & strDummyString
                strItalianLine = strItalianLine & strDummyString

                intLastFoundChar = intLastFoundChar + intStringSplitIndex


                intFoundString = InStr(strStringToLookFor, """")

                If intFoundString <> 0 Then

                    strStringToLookFor = Left(strStringToLookFor, intFoundString - 1)


                    Set rngFoundString = rngEnglishDictionary.Find(strStringToLookFor)


                    If (rngFoundString Is Nothing) Then
                        Debug.Print "String " & strStringToLookFor & " not found!"


                        strGermanLine = strGermanLine & strStringToLookFor & """"
                        strFrenchLine = strFrenchLine & strStringToLookFor & """"
                        strItalianLine = strItalianLine & strStringToLookFor & """"
                    Else

                        intWordToReplaceIndex = rngEnglishDictionary.Find(strStringToLookFor).Row - rngEnglishDictionary.Row + 1


                        strGermanLine = strGermanLine & rngGermanDictionary(intWordToReplaceIndex) & """"
                        strFrenchLine = strFrenchLine & rngFrenchDictionary(intWordToReplaceIndex) & """"
                        strItalianLine = strItalianLine & rngItalianDictionary(intWordToReplaceIndex) & """"
                    End If

                    intLastFoundChar = intLastFoundChar + Len(strStringToLookFor)
                End If
            End If

        Next intJ               

    Else

    strGermanLine = strLine
    strFrenchLine = strLine
    strItalianLine = strLine

    End If                       

    fGermanOutputFile.WriteLine (strGermanLine & vbCrLn)
    fFrenchOutputFile.WriteLine (strFrenchLine & vbCrLn)
    fItalianOutputFile.WriteLine (strItalianLine & vbCrLn)

    strGermanLine = ""
    strFrenchLine = ""
    strItalianLine = ""         
Loop
End If

推荐答案

默认情况下,CreateTextFile创建ASCII编码的文件.为了将其保存为UTF-8,我们必须在创建文本文件时进行设置,

By default, CreateTextFile creates the files in ASCII encoding. In order to have it save as UTF-8, we have to set this when creating the text files,

Set fGermanOutputFile = fso.CreateTextFile((strFolderPath & "_German.xml"), True, True)
Set fItalianOutputFile = fso.CreateTextFile((strFolderPath & "_Italian.xml"), True, True)
Set fFrenchOutputFile = fso.CreateTextFile((strFolderPath & "_French.xml"), True, True)

第一个是您的文件名,第二个参数是"overwrite"的True,第三个参数是"Unicode"和"ASCII"的True. 据此

1st is your file name, 2nd argument is True for "overwrite", and 3rd argument is True to use "Unicode" versus "ASCII". According to this

这篇关于Excel数据转换为XML会用法语单词输入错误的字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 00:17