Hello Great Minds !
I am new here. I need to help to create a notepad which has data from data table.
I Filled a Data Table dt from data Adapter and Export using string builder.
I set Every Column Position Using Padding to fix column width.
I am unable to set header on top and column repeat after eatch 70 lines.
my code are under. i will very obliged to you
What I have tried:
Dim Dt As New DataTable
Private ColumnPadding() As Integer = {5, 25, 15, 10, 10, 20, 20, 15, 15, 35, 10, 20}
Private OutPutFile As String = IO.Path.Combine(Application.StartupPath, "Local.txt")
Private Function HeaderText() As String
Return "Id".PadRight(5) & _
"UserName".PadRight(25) & _
"Indent No".PadRight(15) & _
"Village".PadRight(10) & _
"Code".PadRight(10) & _
"Grower Name".PadRight(20) & _
"Father Name".PadRight(20) & _
"Mobile".PadRight(15) & _
"Item Code".PadRight(15) & _
"Item Name".PadRight(35) & _
"Qty.".PadRight(10) & _
"Amount".PadRight(10)
End Function
Private Sub ExportDataForGenericPrinter()
Dim Total As Integer = Dt.Compute("Sum(Amt)", String.Empty)
Dim TotalUser As Integer = Dt.AsDataView.ToTable(True, "Userid").Rows.Count
Dim TotalIndent As Integer = Dt.Compute("Count(IndNo)", String.Empty)
Dim sb As New System.Text.StringBuilder
Dim Line As New String("="c, HeaderText.Length)
sb.AppendLine(Line)
sb.AppendLine(HeaderText)
Dim ColLine As New String("--", HeaderText.Length)
sb.AppendLine(Line)
Dim ColumValues As String = ""
For Each row As DataRow In Dt.Rows
For col As Integer = 0 To Dt.Columns.Count - 1
ColumValues &= row(col).ToString.PadRight(ColumnPadding(col))
Next
sb.AppendLine(ColumValues)
sb.AppendLine(ColLine)
ColumValues = ""
Next
sb.AppendLine(Line)
sb.AppendLine("Total Indent :- " & TotalUser & vbTab & "Total Indent :- " & TotalIndent & vbTab & "Total Amount :- " & Total)
sb.AppendLine(Line)
IO.File.WriteAllText(OutPutFile, sb.ToString)
Application.DoEvents()
Process.Start(OutPutFile)
End Sub
Private Sub BtnOk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnOk.Click
Try
GetDataIndent()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub