导出到Excel对齐不正确,不显示颜色

时间:2016-05-11 04:01:36

标签: c# excel

我不知道为什么在excel中查看时对齐不正确并且某些颜色也没有显示。

以下是我的代码。

      protected void Page_Load(object sender, EventArgs e)
    {
        //check if session is valid
       // WebUtility.WebUtility.CheckValidSession(Context, ResponseSession);

        tdOnTime2.BackColor = Color.FromName(Valuelist.FirstOrDefault().Color == "Amber" ? "Orange" : Valuelist.FirstOrDefault().Color);
        tdAceeptableDelay2.BackColor = Color.FromName(Valuelist.Skip(1).FirstOrDefault().Color == "Amber" ? "Orange" : Valuelist.Skip(1).FirstOrDefault().Color);
        tdDelayed2.BackColor = Color.FromName(Valuelist.LastOrDefault().Color == "Amber" ? "Orange" : Valuelist.LastOrDefault().Color);

        tdOnTime.BackColor = Color.FromName(Valuelist.FirstOrDefault().Color == "Amber" ? "Orange" : Valuelist.FirstOrDefault().Color);
        tdAceeptableDelay.BackColor = Color.FromName(Valuelist.Skip(1).FirstOrDefault().Color == "Amber" ? "Orange" : Valuelist.Skip(1).FirstOrDefault().Color);
        tdDelayed.BackColor = Color.FromName(Valuelist.LastOrDefault().Color == "Amber" ? "Orange" : Valuelist.LastOrDefault().Color);
        //get CP from querystring
        int CPID ;
        int.TryParse(Request.QueryString.Get("CPID"), out CPID);
        this.ucComplianceReportForCP.CPID = CPID;
        this.ucComplianceReportForCP.DisplayComplianceForCP();
    }
    protected void btnExportToExcel_Click(object sender, EventArgs e)
    {
        Response.Clear();
        Response.Buffer = true;
        Response.AddHeader("content-disposition", "attachment;filename=ComplianceReport.xls");
        Response.Charset = "";
        Response.ContentType = "application/vnd.ms-excel";
        StringWriter sw = new StringWriter();
        HtmlTextWriter hw = new HtmlTextWriter(sw);
      //  rptCustomers.RenderControl(hw);

       // this.ltExcelCPtitle.Visible = true;
        pnlComplianceData.RenderControl(hw);
        Response.Output.Write(sw.ToString());
        Response.Flush();
        Response.End();
       // ltExcelCPtitle.Visible = false;
    }

下面是图片。

OP supplied image  http://i.stack.imgur.com/6EiAY.png

0 个答案:

没有答案