Created
November 11, 2020 15:49
-
-
Save maokwen/6f4d575273b7452cd450ee58cf32c027 to your computer and use it in GitHub Desktop.
语言表 Excel 导出 Lua 脚本
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Sub MakeXml(iCaptionRow As Integer, iDataStartRow As Integer, sOutputFileName As String) | |
| ' | |
| ' 导出为xml 宏 | |
| ' | |
| Dim Q As String | |
| Q = Chr$(34) | |
| Dim NL As String | |
| NL = Chr$(13) | |
| Dim TT As String | |
| TT = Chr$(9) | |
| ''--determine count of columns | |
| Dim iColCount As Integer | |
| iColCount = 1 | |
| While Trim$(Cells(iCaptionRow, iColCount)) > "" | |
| iColCount = iColCount + 1 | |
| Wend | |
| Dim nDestFile As Integer | |
| ''Close any open text files | |
| Close | |
| Dim fsT As Object | |
| Set fsT = CreateObject("ADODB.Stream") | |
| fsT.Type = 2 'Specify stream type - we want To save text/string data. | |
| fsT.Charset = "utf-8" 'Specify charset For the source text data. | |
| fsT.Open 'Open the stream And write binary data To the object | |
| fsT.WriteText "<?xml version=" & Q & "1.0" & Q & " encoding=" & Q & "UTF-8" & Q & "?>" | |
| fsT.WriteText NL | |
| fsT.WriteText "<Config>" | |
| fsT.WriteText NL | |
| Dim iRow As Integer | |
| iRow = iDataStartRow | |
| Dim attrName As String | |
| While Cells(iRow, 1) > "" | |
| fsT.WriteText TT | |
| fsT.WriteText "<item" | |
| attrName = Cells(iCaptionRow, icol).Text | |
| '跳过多余语言 | |
| If StrComp(attrName, "Key") <> 0 And StrComp(attrName, "Chinese") <> 0 And StrComp(attrName, "English") <> 0 Then | |
| Exit Do | |
| End If | |
| For icol = 1 To iColCount - 1 | |
| fsT.WriteText " " | |
| fsT.WriteText Trim$(Cells(iCaptionRow, icol)) | |
| fsT.WriteText "=" | |
| fsT.WriteText Q | |
| fsT.WriteText Trim$(Cells(iRow, icol).Text) | |
| fsT.WriteText Q | |
| Loop While False: Next | |
| fsT.WriteText "/>" | |
| fsT.WriteText NL | |
| iRow = iRow + 1 | |
| Wend | |
| fsT.WriteText "</Config>" | |
| fsT.WriteText NL | |
| fsT.SaveToFile sOutputFileName, 2 'Save binary data To disk | |
| MsgBox "转换完成!" | |
| End Sub | |
| Sub ExportToXML() | |
| MakeXml 1, 2, "C:\Users\maokun\Desktop\config\LanguageConfig.xml" | |
| End Sub | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment