当前位置: 代码迷 >> ASP.NET >> 高分分提问,excel 导出,提示CSS丢失有关问题
  详细解决方案

高分分提问,excel 导出,提示CSS丢失有关问题

热度:4409   发布时间:2013-02-25 00:00:00.0
高分分提问,excel 导出,提示CSS丢失问题
C# code
DataTable ds = GetDataTable();            StringBuilder sbContent = new StringBuilder();            if (ds.Rows.Count > 0)            {                for (int i = 0; i < ds.Rows.Count; i++)                {                    sbContent.Append("<tr style=\"height:30px\">");                    sbContent.Append("<td style='text-align:left;vnd.ms-excel.numberformat: @'>" + Convert.ToString(i + 1) + "</td>");                    sbContent.Append("<td style='text-align:left;vnd.ms-excel.numberformat: @'>" + ds.Rows[i]["LR_NAME"].ToString() + "</td>");                    sbContent.Append("<td style='text-align:left;vnd.ms-excel.numberformat: @'>" + ds.Rows[i]["LR_SEX"].ToString() + "</td>");                    sbContent.Append("<td style='text-align:left;vnd.ms-excel.numberformat: @'>" + ds.Rows[i]["LR_SFZ"].ToString() + "</td>");                    sbContent.Append("<td style='text-align:left;vnd.ms-excel.numberformat: @'>" + ds.Rows[i]["LR_ZZ"].ToString() + "</td>");                    sbContent.Append("<td style='text-align:left;vnd.ms-excel.numberformat: @'>" + ds.Rows[i]["LR_TEL"].ToString() + "</td>");                    sbContent.Append("<td style='text-align:left;vnd.ms-excel.numberformat: @'>" + ds.Rows[i]["LR_TEL2"].ToString() + "</td>");                    sbContent.Append("<td style='text-align:left;vnd.ms-excel.numberformat: @'>" + ds.Rows[i]["LR_SJ"].ToString() + "</td>");                    sbContent.Append("<td style='text-align:left;vnd.ms-excel.numberformat: @'>" + ds.Rows[i]["LR_RY"].ToString() + "</td>");                    sbContent.Append("<td style='text-align:left;vnd.ms-excel.numberformat: @'>" + ds.Rows[i]["LR_BZ"].ToString() + "</td>");                    sbContent.Append("</tr>");                }            }            StringBuilder sbHtml = new StringBuilder();            sbHtml.Append("<table border=\"1\"  cellpadding=\"0\" cellspacing=\"0\" > ");            sbHtml.Append("<tr>");            sbHtml.Append("<th width=50 >序号</th>");            sbHtml.Append("<th width=100>姓名</th>");            sbHtml.Append("<th width=70 >性别</th>");            sbHtml.Append("<th width=200 >身份证号码</th>");            sbHtml.Append("<th width=200 >家庭住址</th>");            sbHtml.Append("<th width=200 >手机号码</th>");            sbHtml.Append("<th width=200 >固定电话</th>");            sbHtml.Append("<th width=200 >录入时间</th>");            sbHtml.Append("<th width=110 >录入人员</th>");            sbHtml.Append("<th width=200 >备注</th>");            sbHtml.Append("</tr>");            sbHtml.Append(sbContent);            sbContent.Append(" </table>");            sbHtml.Append("</table>");            Response.Clear();            Response.ContentType = "application nd.ms-excel";            Response.Charset = "gb2312";            Page.EnableViewState = false;            Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode("客户录入名单") + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls");            Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");//设置输出流为简体中文            Response.Write("<html><head><meta http-equiv=Content-Type content=\"text/html; charset=UTF-8\"><title>   </title></head><body><center>");            Response.Write(sbHtml.ToString());            Response.Write("</center></body></html>");            Response.End();        }
  相关解决方案