ASP.NET C#导出到excel时设置标题/标题的样式?
我正在尝试将我的asp.net excel导出样式设置得更好一些,但我不知道如何设置 我有以下代码ASP.NET C#导出到excel时设置标题/标题的样式?,c#,asp.net,C#,Asp.net,我正在尝试将我的asp.net excel导出样式设置得更好一些,但我不知道如何设置 我有以下代码 string filename = Constants.Fullname +"_CommissionSheet_"+DateTime.Now.ToString("MM/dd/yyyy")+".xls"; Response.AddHeader("content-disposition", "attachment; filename="+filename); Response.Cha
string filename = Constants.Fullname +"_CommissionSheet_"+DateTime.Now.ToString("MM/dd/yyyy")+".xls";
Response.AddHeader("content-disposition", "attachment; filename="+filename);
Response.Charset = "";
// If you want the option to open the Excel file without saving than
// comment out the line below
// Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application/vnd.xls";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite =
new HtmlTextWriter(stringWrite);
//Styling the gridView header for Excel.
GridView1.HeaderRow.Style.Add("background-color", "#95c556");
GridView2.HeaderRow.Style.Add("background-color", "#FF9900");
GridView3.HeaderRow.Style.Add("background-color", "#db7464");
int j = 1;
//Set alternate row color
foreach (GridViewRow gvrow in GridView1.Rows)
{
gvrow.BackColor = System.Drawing.Color.White;
if (j <= GridView1.Rows.Count)
{
if (j % 2 != 0)
{
for (int k = 0; k < gvrow.Cells.Count; k++)
{
gvrow.Cells[k].Style.Add("background-color", "#EFF3FB");
}
}
}
j++;
}
int jk= 1;
//Set alternate row color
foreach (GridViewRow gvrow in GridView2.Rows)
{
gvrow.BackColor = System.Drawing.Color.White;
if (jk <= GridView2.Rows.Count)
{
if (jk % 2 != 0)
{
for (int k = 0; k < gvrow.Cells.Count; k++)
{
gvrow.Cells[k].Style.Add("background-color", "#EFF3FB");
}
}
}
jk++;
}
int jkj = 1;
//Set alternate row color
foreach (GridViewRow gvrow in GridView3.Rows)
{
gvrow.BackColor = System.Drawing.Color.White;
if (jkj <= GridView3.Rows.Count)
{
if (jkj % 2 != 0)
{
for (int k = 0; k < gvrow.Cells.Count; k++)
{
gvrow.Cells[k].Style.Add("background-color", "#EFF3FB");
}
}
}
jk++;
}
//Add Header
GridView1.Caption = "Paid:";
GridView1.CaptionAlign = TableCaptionAlign.Left;
GridView2.Caption = "Expected:";
GridView2.CaptionAlign = TableCaptionAlign.Left;
GridView3.Caption = "Unpaid:";
GridView3.CaptionAlign = TableCaptionAlign.Left;
GridView1.RenderControl(htmlWrite);
GridView2.RenderControl(htmlWrite);
GridView3.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();
}
string filename=Constants.Fullname+“_CommissionSheet”+DateTime.Now.ToString(“MM/dd/yyyy”)+“.xls”;
Response.AddHeader(“内容处置”、“附件;文件名=“+filename”);
响应。Charset=“”;
//如果希望在不保存的情况下打开Excel文件,则
//注释掉下面的行
//Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType=“application/vnd.xls”;
System.IO.StringWriter stringWrite=新的System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite=
新的HtmlTextWriter(stringWrite);
//为Excel设置gridView标题的样式。
GridView1.HeaderRow.Style.Add(“背景色”,“#95c556”);
GridView2.HeaderRow.Style.Add(“背景色”,“FF9900”);
GridView3.HeaderRow.Style.Add(“背景色”、“db7464”);
int j=1;
//设置备用行颜色
foreach(GridViewRow gvrow在GridView1.Rows中)
{
gvrow.BackColor=System.Drawing.Color.White;
如果(j)你查过这个问题了吗?@Niklas,我没发现那个问题,我会查出来的。谢谢。