Tech
Forums
Jobs
Books
Events
Interviews
Live
More
Learn
Training
Career
Members
Videos
News
Blogs
Login
Sign Up
Ask Question
3
Reply
Datatable to Excel (Excel formatting)
Dinesh Santhalingam
Mar 28 2017 5:44 AM
299
Reply
I have a data table .I want to Export it to a Excel file.I did it using the following code.
StreamWriter
wr
=
new
StreamWriter(@"E:\\Book1.xls");
// Write Columns to excel file
for (int
i
=
0
; i
<
dt.Columns.Count
; i++)
{
wr.Write(dt.Columns[i].ToString().ToUpper() + "\t");
}
wr.WriteLine();
//write rows to excel file
for (int
i
=
0
; i
<
(dt.Rows.Count); i++)
{
for (int
j
=
0
; j
<
dt.Columns.Count
; j++)
{
if (dt.Rows[i][j] != null)
{
wr.Write(Convert.ToString(dt.Rows[i][j]) + "\t");
}
else
{
wr.Write("\t");
}
}
wr.WriteLine();
}
wr.Close();
label1.Text
=
"Data Exported Successfully"
;
}
catch (Exception ex)
{
throw ex;
}
But I want Some Cell Formatting in Xls .Want to change the color of the entire cell like that something.Please help me to solve my problem.
Upload Source Code
Select only zip and rar file.
Post
Reset
Cancel
Answers (
3
)
Next Recommended Forum
how to avoid nested for looping for improved performance?
Disable zoom and drag from d3 line graph in WPF C#