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.