打开txt文件作为Microsoft Excel逗号分隔值文件(.csv)

时间:2016-02-04 14:02:59

标签: vb.net

我有一台测试机,我在工作中使用输出大型txt文件中的数据(数据已经用逗号分隔),我试图制作一个vb.net应用程序来打开txt作为csv。然后将数据放在我制作的excel模板中的图形中。我已经有了使用组合框搜索指定文件夹进行测试的代码,但我仍然坚持下一步。打开txt作为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

1 个答案:

答案 0 :(得分:0)

好的,我想我明白了。在我声明并分配了File.Move(txtpath, csvpath)txtpath后,我使用了csvpath。谢谢Tim的建议

代码:

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