기타 [vb.net] DataTable to CSV
페이지 정보
본문
Private Function CSVBuilder(dt As DataTable, headers As List(Of String), columns As List(Of String)) As String
Dim sCSV = New StringBuilder(String.Join(",", headers))
sCSV.Append(Environment.NewLine)
Dim view As New DataView(dt)
Dim tDt As DataTable = view.ToTable(True, columns.ToArray)
For Each row As DataRow In tDt.Rows
'-- Handle comma
sCSV.Append(String.Join(",", (From rw In row.ItemArray Select If(rw.ToString.Trim.Contains(","), String.Format("""{0}""", rw.ToString.Trim), rw.ToString.Trim))))
sCSV.Append(Environment.NewLine)
Next
Return sCSV.ToString
End Function
Example:
T = CSVBuilder(D, "상품코드,상품명,바코드,제조년월,제조원,원산지,주의사항,신고번호,제형,용량(매수)".Split(","c).ToList, "상품코드,상품명,바코드,제조년월,제조원,원산지,주의사항,신고번호,제형,용량(매수)".Split(","c).ToList) |
- 이전글[vb.net] FileStream 21.06.04
- 다음글[vb.net] 프로그램 중복 실행 방지 하기 21.05.06
댓글목록
등록된 댓글이 없습니다.