使用 VBS 更新电子表格中的单元格 - 保存文件时更改输入格式

Update cells in spreadsheet using VBS - changing input format when saving file

我有以下 csv 文件输入:

s,asdaas, 123123.00,asdasd
 123123.00,bubu1,wqeqw,asd
asdasd,asdasd

我正在使用以下 vbs:

On Error Resume Next
    sheet_number = CInt(Wscript.Arguments.Item(1))
    row_index = CInt(Wscript.Arguments.Item(2))
    col_index = CInt(Wscript.Arguments.Item(3))

    value_insert = Wscript.Arguments.Item(4)
    if value_insert <> "" then
        c = Replace(value_insert, "#", Chr(10))
    end if

    Set objFSO = CreateObject("Scripting.FileSystemObject")

    src_file = objFSO.GetAbsolutePathName(Wscript.Arguments.Item(0))

    Dim oExcel
    Set oExcel = CreateObject("Excel.Application")
    Dim oBook
    Set oBook = oExcel.Workbooks.Open(src_file)

    if sheet_number = 0 Then
        sheet_number = 1
    end if
    oBook.Sheets(sheet_number).Select
    oExcel.Cells(row_index,col_index).NumberFormat = "@"
    oExcel.Cells(row_index,col_index).Select
    oExcel.Cells(row_index,col_index).Value2 = value_insert
    oBook.Save
    oBook.Close
    oExcel.Quit
If Err.Number <> 0 Then
    oBook.Close False
    oExcel.Quit
    Err.Clear             ' Clear the Error
End If

例如,如果我尝试将第 2 行第 2 列的值从 "bubu1" 更新为 "oi",则在保存文件时其他单元格将受到影响。例如,“123123.00”将变为“123123”,请注意,.00 和 space 已消失。

有什么办法可以避免这种情况吗? 修改后,csv 文件被发送到另一个无法处理具有这些 "auto" 更改的文件的进程。

当前输出:

s,asdaas,123123,asdasd
123123,oi,wqeqw,asd
asdasd,asdasd

期望的输出:

s,asdaas, 123123.00,asdasd
 123123.00,oi,wqeqw,asd
asdasd,asdasd

我最终没有使用 ExcelApplication 来处理 CSV。

相反,我使用了:http://www.chilkatsoft.com/downloads_ActiveX.asp

完全符合我的需要。