我正在将gridview数据导出到Excel文件。 excel文件只有两个列。 我已将标题颜色设置为PINK。但是,此PINK 颜色设置为该标头的整个行,而不是仅设置为两列。
这是我的代码...
Response.Clear();
Response.Buffer = true;
Response.AddHeader("content-disposition", "attachment;filename=User_Log.xls");
Response.Charset = "";
Response.ContentType = "application/excel ";
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
GridView1.AllowPaging = false;
myConn.Open();
SqlCommand cmd = new SqlCommand(@"select User_id , LoginDate from LoginLog where LoginDate between
('" + TextBox1.Text + "') and ('" + ToDate + "')", myConn);
DataTable dt = new DataTable();
SqlDataAdapter sda = new SqlDataAdapter(cmd);
sda.Fill(dt);
GridView1.DataSource = dt;
GridView1.HeaderStyle.BackColor = Color.Red;
GridView1.DataBind();
GridView1.RenderControl(hw);
Response.Output.Write(sw.ToString());
Response.Flush();
Response.End();
myConn.Close();