How to convert a tab separated file to CSV format?

前端 未结 3 1691
梦如初夏
梦如初夏 2021-01-01 13:01

I have a text file in this format :

{

attribute1 attribute2 attribute3.... attributeN

value\"A\" value\"B\" value\"C\".... value\"Z\"

/* next line of val         


        
3条回答
  •  自闭症患者
    2021-01-01 13:44

    Here's some Excel-VBA code that will do this conversion. Paste this in Excel's visual basic editor (Alt-F11) and run it (after adjusting your filenames, of course).

    Sub TabToCsv()
    
        Const ForReading = 1, ForWriting = 2
        Dim fso, MyTabFile, MyCsvFile, FileName
        Dim strFileContent as String
        Set fso = CreateObject("Scripting.FileSystemObject")
    
        ' Open the file for input.
        Set MyTabFile = fso.OpenTextFile("c:\testfile.dat", ForReading)
    
        ' Read the entire file and close.
        strFileContent = MyTabFile.ReadAll
        MyTabFile.Close
    
        ' Replace tabs with commas.
        strFileContent = Replace(expression:=strFileContent, _
                                 Find:=vbTab, Replace:=",") 
        ' Can use Chr(9) instead of vbTab.
    
        ' Open a new file for output, write everything, and close.
        Set MyCsvFile = fso.OpenTextFile("c:\testfile.csv", ForWriting, True)
        MyCsvFile.Write strFileContent
        MyCsvFile.Close
    
    End Sub
    

提交回复
热议问题