I am exporting my DataTable values to .txt file using code and its working fine.
i want to wrap text data of Rows value so that it can will look good.
means i want to display it in proper manner.
below is my ouput
ID | Name | Address
1 | VenkVenkVenkVenkVenkVenkVe | chennai
2 | Hanu | London
3 | john | Swiss
i want to wrap data of name Column
i want to output like this :
ID | Name | Address
1 | VenkVenkVenk
1 | VenkVenkVenk
VenkVenkVenkVe | chennai
2 | Hanu | London
3 | john | Swiss
Below is my code
private void CreateDT()
{
DataTable dt = new DataTable();
//Adding data To DataTable
dt.Columns.Add("ID");
dt.Columns.Add("Name");
dt.Columns.Add("Address");
dt.Rows.Add(1, "VenkVenkVenkVenkVenkVenkVenkVenkVenkVenkVenkVenkVenkVenkVenkVenkVenkVenkVenkVenk", "chennai");
dt.Rows.Add(2, "Hanu", "London");
dt.Rows.Add(3, "john", "Swiss");
// DataGridView grid = new DataGridView();
int i = 0;
StreamWriter swExtLogFile = new StreamWriter("D:/DTlog2.txt", true);
//StreamWriter sw = null;
// sw = new StreamWriter(submittedFilePath, false);
for (i = 0; i < dt.Columns.Count - 1; i++)
{
swExtLogFile.Write(dt.Columns[i].ColumnName + "\t" +"\t" + " | ");
}
swExtLogFile.Write(dt.Columns[i].ColumnName);
swExtLogFile.WriteLine();
foreach (DataRow row in dt.Rows)
{
object[] array = row.ItemArray;
for (i = 0; i < array.Length - 1; i++)
{
swExtLogFile.Write(array[i].ToString() + "\t" + "\t" + " | ");
}
swExtLogFile.Write(array[i].ToString());
swExtLogFile.WriteLine();
}
swExtLogFile.Close();
}
Gokhul VarmanPosted Sep 29, 2017, 12:02 AM