Convert pipe-delimited files to .xls

前端 未结 2 1067
隐瞒了意图╮
隐瞒了意图╮ 2021-01-27 18:16

I\'m trying to convert pipe-delimited files to xls (Excel) with batch file and vbscript. Unfortunately, my \"output.xls\" file is still showing the pipe delimiter in the table a

2条回答
  •  Happy的楠姐
    2021-01-27 18:40

    Excel is a little picky when it comes to reading CSV files. If you have a delimited file with the extension .csv Excel will only open it correctly via the Open method if the delimiter is the character configured in the system's regional settings.

    The Open method has optional parameters that allow you to specify a custom delimiter character (credit to @Jeeped for pointing this out):

    set objWorkbook = objExcel.Workbooks.Open(srccsvfile, , , 6, , , , , "|")
    

    You can also use the OpenText method (which will be used when recording the action as a macro):

    objExcel.Workbooks.OpenText srccsvfile, , , 1, , , , , , , True, "|"
    Set objWorkbook = objExcel.Workbooks(1)
    

    Note that the OpenText method does not return a workbook object, so you must assign the workbook to a variable yourself after opening the file.

    Important: either way your file must not have the extension .csv if your delimiter character differs from your system's regional settings, otherwise the delimiter will be ignored.

提交回复
热议问题