C# 在asp.net中导出到excel时,标签背面颜色无法正常工作

C# 在asp.net中导出到excel时,标签背面颜色无法正常工作,c#,asp.net,C#,Asp.net,有人能帮我解决这个问题吗 我为标签动态添加背景色,但在导出到excel时,背景色不会显示在excel工作表中 她是我的密码 DataSet ds = DST; ds.Tables.Remove(ds.Tables[0]); // string style = @"<style> .text { mso-number-format:\@Medium Date; } </style> "; lblTitle.Text = "<h3 border='0' align=

有人能帮我解决这个问题吗 我为标签动态添加背景色,但在导出到excel时,背景色不会显示在excel工作表中 她是我的密码

DataSet ds = DST;
ds.Tables.Remove(ds.Tables[0]);

// string style = @"<style> .text { mso-number-format:\@Medium Date; } </style> ";

lblTitle.Text = "<h3 border='0' align='center'><b>Sales Report </b></h3>";
HtmlForm form = new HtmlForm();
string attachment = "attachment; filename=BPOSalesReport.xls";
Response.ClearContent();
Response.AddHeader("content-disposition", attachment);
Response.ContentType = "application/ms-excel";

StringWriter stw = new StringWriter();
HtmlTextWriter htextw = new HtmlTextWriter(stw);
GridView gv;
Panel PNl = new Panel();
Label lbldate;
LiteralControl ltlbldate;

for (int k = 0; k < ds.Tables.Count; k++)
{
    gv = new GridView();
    lbldate = new Label();
    ltlbldate = new LiteralControl();
    //lbldate.CssClass = "required";
    gv.ID = ds.Tables[k].TableName;
    gv.DataSource = ds.Tables[k];
    gv.DataBind();
    gv.HeaderRow.Style.Add("background-color", "#6699FF");
    gv.HeaderStyle.ForeColor = System.Drawing.Color.Black;     

    lbldate.Text = datechecking(ds.Tables[k].TableName.ToString());
    lbldate.BackColor = System.Drawing.Color.Yellow;
    PNl.Controls.Add(lbldate);
    PNl.Controls.Add(gv);
    PNl.Controls.Add(new LiteralControl("<br />"));
    PNl.Controls.Add(new LiteralControl("<br />"));
    PNl.Controls.Add(new LiteralControl("<br />"));
}       

form.Attributes["runat"] = "server";
form.Controls.Add(PNl);
this.Controls.Add(form);
lblTitle.Visible = true;
lblTitle.RenderControl(htextw);
form.RenderControl(htextw);
// Response.Write(style);

Response.Write(stw.ToString());
Response.End();

也许这行代码会对你有所帮助

    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
    Response.ClearContent();
    Response.Buffer = true;
    Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", "Details.xls"));
    Response.ContentType = "application/ms-excel";
    StringWriter sw = new StringWriter();
    HtmlTextWriter htw = new HtmlTextWriter(sw);
    GridView1.AllowPaging = false;
    //Change the Header Row back to white color
    GridView1.HeaderRow.Style.Add("background-color", "#000000");
    //Applying stlye to gridview header cells
    for (int i = 0; i < GridView1.HeaderRow.Cells.Count; i++)
    {
        GridView1.HeaderRow.Cells[i].Style.Add("background-color", "#000000");
    }
    int j = 1;
    //This loop is used to apply stlye to cells based on particular row
    foreach (GridViewRow gvrow in GridView1.Rows)
    {

        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", "#FFFFFF");
                }
            }
        }
        j++;
    }
    GridView1.RenderControl(htw);
    Response.Write(sw.ToString());
    Response.End();
}

网格工作正常,但导出到excel时不显示“标签背面”