示例#1
0
        public void ExportUser()
        {
            var isValidate = string.Empty;
            var keys       = Request.Form.AllKeys;

            foreach (var key in keys)
            {
                isValidate = Request.Form[key];
            }
            List <UserModel> list = SysService.GetUsers("", Boolean.Parse(isValidate), "", "");
            StringBuilder    sb   = new StringBuilder();

            sb.Append("<style type=\"text/css\">");
            sb.Append("<!--");
            sb.Append(".text");
            sb.Append("{mso-style-parent:style0;");
            sb.Append("font-size:10.0pt;");
            sb.Append("font-family:\"Arial Unicode MS\", sans-serif;");
            sb.Append("mso-font-charset:0;");
            sb.Append(@"mso-number-format:\@;");
            sb.Append("text-align:center;");
            sb.Append("border:.5pt solid black;");
            sb.Append("white-space:normal;}");
            sb.Append("-->");
            sb.Append("</style>");
            sb.Append("<table cellspacing=\"0\" rules=\"all\" border=\"1\" style=\"border-collapse:collapse;\">");
            sb.Append("<tr align=\"Center\" style=\"font-weight:bold;\">");
            sb.Append("<td>用户ID</td><td>用户名</td><td>全名</td><td>邮箱</td><td>是否有效</td>");
            sb.Append("</tr>");
            foreach (var user in list)
            {
                string value = user.IsValid ? "是" : "否";
                sb.Append("<tr align=\"Center\"><td>" + user.UserID + "</td><td>" + user.UserName + "</td><td>" + user.FullName + "</td><td>" + user.Email + "</td><td>" + value + "</td></tr>");
            }
            sb.Append("</table>");
            HttpResponseBase response = HttpContext.Response;

            response.Clear();
            response.ContentType = "application/ms-excel";
            if (HttpContext.Request.Browser.Type.StartsWith("Inter"))
            {
                response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode("用户清单.xls", Encoding.GetEncoding("UTF-8")));
            }
            response.AppendHeader("Content-Disposition", "attachment;filename=" + "用户清单.xls");
            response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8");
            response.AddHeader("Pragma", "public");
            response.Write(sb.ToString());
            response.End();
            HttpContext.ApplicationInstance.CompleteRequest();
        }
        public void ExportPanDian()
        {
            DataTable dt         = PanDianData;
            var       isValidate = string.Empty;
            var       keys       = Request.Form.AllKeys;

            foreach (var key in keys)
            {
                isValidate = Request.Form[key];
            }
            List <UserModel> list = SysService.GetUsers("", Boolean.Parse(isValidate), "", "");
            StringBuilder    sb   = new StringBuilder();

            sb.Append("<style type=\"text/css\">");
            sb.Append("<!--");
            sb.Append(".text");
            sb.Append("{mso-style-parent:style0;");
            sb.Append("font-size:10.0pt;");
            sb.Append("font-family:\"Arial Unicode MS\", sans-serif;");
            sb.Append("mso-font-charset:0;");
            sb.Append(@"mso-number-format:\@;");
            sb.Append("text-align:center;");
            sb.Append("border:.5pt solid black;");
            sb.Append("white-space:normal;}");
            sb.Append("-->");
            sb.Append("</style>");
            sb.Append("<table cellspacing=\"0\" rules=\"all\" border=\"1\" style=\"border-collapse:collapse;\">");
            sb.Append("<tr align=\"Center\" style=\"font-weight:bold;\">");
            sb.Append("<td>编号</td>");
            sb.Append("<td>资产名称</td>");
            sb.Append("<td>资产类别</td>");
            sb.Append("<td>条码编号</td>");
            sb.Append("<td>规格型号</td>");
            sb.Append("<td>单位</td>");
            sb.Append("<td>增加方式</td>");
            sb.Append("<td>所属公司</td>");
            sb.Append("<td>所属部门</td>");
            sb.Append("<td>使用员工</td>");
            sb.Append("<td>仓库名称</td>");
            sb.Append("<td>购入价格</td>");
            sb.Append("<td>购置时间</td>");
            sb.Append("<td>供应商</td>");
            sb.Append("<td>质保说明</td>");
            sb.Append("<td>使用年限</td>");
            sb.Append("<td>使用情况</td>");
            sb.Append("<td>备注</td>");
            sb.Append("</tr>");
            foreach (DataRow dr in dt.Rows)
            {
                //string value = user.IsValid ? "是" : "否";
                sb.Append("<tr align=\"Center\"><td>" + dr["AssetID"] + "</td>");
                sb.Append("<td>" + dr["AssetName"] + "</td>");
                sb.Append("<td>" + dr["Category"] + "</td>");
                sb.Append("<td>" + dr["BarCard"] + "</td>");
                sb.Append("<td>" + dr["SpecificationsModel"] + "</td>");
                sb.Append("<td>" + dr["UnitName"] + "</td>");
                sb.Append("<td>" + dr["AddType"] + "</td>");
                sb.Append("<td>" + dr["CName"] + "</td>");
                sb.Append("<td>" + dr["DName"] + "</td>");
                sb.Append("<td>" + dr["EName"] + "</td>");
                sb.Append("<td>" + dr["WHName"] + "</td>");
                sb.Append("<td>" + dr["Price"] + "</td>");
                sb.Append("<td>" + dr["BuyDate"] + "</td>");
                sb.Append("<td>" + dr["SupplierName"] + "</td>");
                sb.Append("<td>" + dr["QualityDescription"] + "</td>");
                sb.Append("<td>" + dr["UseYear"] + "</td>");
                sb.Append("<td>" + dr["UseCondition"] + "</td>");
                sb.Append("<td>" + dr["Remark"] + "</td></tr>");
            }
            sb.Append("</table>");
            HttpResponseBase response = HttpContext.Response;

            response.Clear();
            response.ContentType = "application/ms-excel";
            if (HttpContext.Request.Browser.Type.StartsWith("Inter"))
            {
                response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode("固定资产盘点.xls", Encoding.GetEncoding("UTF-8")));
            }
            response.AppendHeader("Content-Disposition", "attachment;filename=" + "固定资产盘点.xls");
            response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8");
            response.AddHeader("Pragma", "public");
            response.Write(sb.ToString());
            response.End();
            HttpContext.ApplicationInstance.CompleteRequest();
        }