所以我是一名数据分析师,IT 部门似乎从来没有时间为我的一些项目编写代码,所以我决定自己做!我制作了一个非常基本的程序,它采用源文件 (.csv) 并按照我需要的顺序在列中移动。它工作得很好,但我需要一些帮助。
我很清楚可能有更好的方法来完成这一切。我不是 100% 设置好我的代码,特别是如果它不能在下面做我想要的。
我想在作者完成后弹出某种消息框,但我不知道该怎么做。
I figured out a way to do this. I just added the revised code below.
我想使用“-”作为分隔符来解析邮政编码,并将“-”之后的所有内容移动到下一列(这样我就可以将 zip 和 zip+4 作为不同的列)。如您所见,我试图做类似的事情,但没有奏效。(邮编在第 8 列)
我需要插入带有某些信息的标题行。我不知道该怎么做!
I figured this out too! Edited the code below again.
我还想更改日期格式。源文件是 MM/DD/YYYY,但我想以 YYYYMMDD 的形式提供。(这将是第 10 列和第 11 列)
所以,这是我到目前为止的代码。它工作得很好,但并没有做我想做的所有事情。
Public Sub ParseButton_Click(sender As Object, e As EventArgs) Handles ParseButton.Click
' Create the IEnumerable data source.
Dim lines As String() = System.IO.File.ReadAllLines(FileInLocation).Skip(1).ToArray()
Dim Date1 As Date = Date.Now
Dim lineQuery = From line In lines
Let x = line.Split(New Char() {","})
Select "10010" & "," & (Date1.ToString("yyyyMMdd")) & "," &
(Date1.ToString("yyyyMMdd")) & "," &
"WY Mental Health Professions Licensing Board" & "," &
"WY" & "," & x(4) & " " & "," & "," & x(1) & "," & x(2) & "," & x(0) & "," &
x(5) & "," & "" & "," & x(6) & "," & x(7) & " " & "," & "," & x(8) & "," & " " & "," &
x(3) & "," & x(9) & " " & "," & "," & x(10) & "," & x(11) & "," & x(12)
' Execute the query and write out the new file. Note that WriteAllLines
' takes a string array, so ToArray is called on the query.
Dim inputString As String = "DartID,DateAdded,DateUpdated,Website,State,BusinessName,DBA,NameFirst,NameMiddle,NameLast,NameSuffix,Address,AddressLine2,AddressCity,AddressState,AddressZipCode,Zip4,Email,LicenseNo,LicenseType,LicenseDateFrom,LicenseDateTo,LicenseStatus,"
System.IO.File.WriteAllText(FileOutLocation & "\Output.csv", inputString)
System.IO.File.AppendAllText(FileOutLocation & "\Output.csv", Environment.NewLine)
System.IO.File.AppendAllLines(FileOutLocation & "\Output.csv", lineQuery.ToArray())
'Show message box on completion of file write
If My.Computer.FileSystem.FileExists(FileOutLocation & "\Output.csv") Then
MsgBox("Parse Complete!")
Else
MsgBox("Error, Parse Failed!")
End If
End Sub
感谢您的任何帮助!