本文介绍了导出到Excel对齐不正确,不显示颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 this is the code that i m using , can anyone explain why the table is not aligned properly when viewed in excel and some colors are also not displayed

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

            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;
        }





我尝试了什么:



i不是没有导致此问题的原因..



What I have tried:

i don't no what is causing this issue..

推荐答案

@"<style> .textmode { } </style>";



见以下链接获取更多帮助

]


这篇关于导出到Excel对齐不正确,不显示颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 05:07