2016-02-04 99 views
0

我有一個測試機器,我在工作時使用大型txt文件輸出數據(數據已用逗號分隔),我試圖使一個vb.net應用程序打開作爲csv的txt。然後將數據放入我製作的Excel模板中。我已經有了使用組合框搜索指定文件夾進行測試的代碼,但我堅持下一步。以csv打開txt。打開txt文件作爲Microsoft Excel逗號分隔值文件(.csv)

代碼:

Public Class RF_Data_AutoFormat 
Private Sub cbo_FileList_Click(sender As Object, e As EventArgs) Handles cbo_FileList.Click 
    Dim dir = "C:\Users\aholiday\Desktop\Data Dump" 
    cbo_FileList.Items.Clear() 
    For Each file As String In System.IO.Directory.GetFiles(dir) 
     cbo_FileList.Items.Add(System.IO.Path.GetFileName(file)) 
    Next 
End Sub 

Private Sub btn_Do_Click(sender As Object, e As EventArgs) Handles btn_Do.Click 
    Dim FileTXT 
    cbo_FileList.Text = FileTXT 
    FileOpen()?????? 

End Sub 
End Class 
+2

CSV文件* *是文本文件。這是你如何處理不同的內容。 – Plutonix

+0

如果使用擴展名csv保存txt,它會將其保存爲Microsoft Excel逗號分隔值文件(.csv)。我試圖自動化的過程,而不是一個接一個做 – Duraholiday

+0

你想Excel打開它嗎? – Plutonix

回答

0

好吧,我想我得到了它。在我宣佈並指定了txtpathcsvpath之後,我使用File.Move(txtpath, csvpath)。感謝您的建議添

代碼:

Imports System 
Imports System.IO 
Imports System.Text 
Public Class Form1 
Private Sub cbo_FileList_Click(sender As Object, e As EventArgs) Handles cbo_FileList.Click 
    Dim folderpath = "C:\Users\aholiday\Desktop\Data Dump" 
    cbo_FileList.Items.Clear() 
    For Each file As String In System.IO.Directory.GetFiles(folderpath) 
     cbo_FileList.Items.Add(System.IO.Path.GetFileNameWithoutExtension(file)) 
    Next 
End Sub 

Private Sub btn_Do_Click(sender As Object, e As EventArgs) Handles btn_Do.Click 
    Dim txtpath As String 
    Dim csvpath As String = "C:\Temp" 
    Dim FileTXT As String 
    Dim folderpath As String 

    folderpath = "C:\Users\aholiday\Desktop\Data Dump" 
    FileTXT = cbo_FileList.Text 
    csvpath = "C:\Temp\" & FileTXT & ".csv" 
    txtpath = folderpath & "\" & FileTXT & ".txt" 

    File.Move(txtpath, csvpath) 

End Sub 
End Class 
相關問題