将Excel文件另存为CSV,而不会丢失特殊字符β

时间:2019-01-22 14:04:55

标签: vbscript

我有一个带有β个字符的文件。将Excel转换为CSV时,它们将转换为?。我正在通过ADODB进行操作。

Dim CONNECTION1
Set CONNECTION1 = WScript.CreateObject("ADODB.Connection")
CONNECTION1.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\Test.xlsx;Extended Properties=""Excel 12.0;HDR=YES;"""

Dim RECORDSET1
Set RECORDSET1 = WScript.CreateObject("ADODB.Recordset")
RECORDSET1.Open "SELECT * FROM [Sheet1$]", CONNECTION1, 3, 1

Dim CONNECTION2
Set CONNECTION2 = WScript.CreateObject("ADODB.Connection")
CONNECTION2.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\Test.csv;Extended Properties=""Text;HDR=Yes;FMT=Delimited;CharacterSet=65001;"""
CONNECTION2.Execute "CREATE TABLE [Test.csv] ([aa] VARCHAR(200), [bb] VARCHAR(200))"

Dim RECORDSET2
Set RECORDSET2 = WScript.CreateObject("ADODB.Recordset")
RECORDSET2.Open "SELECT * FROM [Test.csv]", CONNECTION2, 2, 2

Do Until RECORDSET1.EOF
    RECORDSET2.AddNew
    Dim i
    For i = 0 To RECORDSET1.Fields.Count - 1
        WScript.Echo RECORDSET1.Fields(i).Value
        RECORDSET2.Fields(i).Value = RECORDSET1.Fields(i).Value
    Next
    RECORDSET2.Update
    RECORDSET1.MoveNext
Loop

1 个答案:

答案 0 :(得分:0)

找到解决方案,对我来说很好

ObjExcelFile_CSVSource.SaveAs CSVFile,42