public ActionResult ExportExcelFile(FormCollection collection)
        {
            DataTable dt = new DataTable();

            dt.Columns.Add("ID", Type.GetType("System.Int32"));
            dt.Columns[0].AutoIncrement     = true;
            dt.Columns[0].AutoIncrementSeed = 1;
            dt.Columns[0].AutoIncrementStep = 1;
            dt.Columns.Add("样品登记号", Type.GetType("System.String"));
            dt.Columns.Add("采样日期", Type.GetType("System.DateTime"));
            dt.Columns.Add("样品状态", Type.GetType("System.String"));
            dt.Columns.Add("保存条件", Type.GetType("System.String"));
            dt.Columns.Add("备注", Type.GetType("System.String"));
            dt.Columns.Add("状态", Type.GetType("System.String"));
            dt.Columns.Add("审核人", Type.GetType("System.String"));
            dt.Columns.Add("样品结果", Type.GetType("System.String"));



            foreach (var m in Sample)
            {
                DataRow dtRow = dt.NewRow();

                dtRow["样品登记号"] = "" + m.SampleRegisterNumber;
                dtRow["采样日期"]  = "" + m.SamplingDay;
                dtRow["样品状态"]  = "" + m.SampleState;
                dtRow["保存条件"]  = "" + m.SaveCondition;
                dtRow["备注"]    = "" + m.Remark;
                dtRow["状态"]    = "" + HYZK.FrameWork.Utility.EnumHelper.GetEnumTitle((EnumSampleStates)@m.SampleStates);
                dtRow["审核人"]   = "" + m.AnalyzePeople;
                dtRow["样品结果"]  = "" + m.ArgumentPrice;
                dt.Rows.Add(dtRow);
            }


            string fileName = "d://DKLdownload" + Web.Demo.Common.AdminUserContext.Current.LoginInfo.LoginName + "(" + DateTime.Now.ToString().Replace("/", "").Replace(":", "").Replace(" ", "") + ").xls";
            string tabName  = "采样结果";
            string reMsg    = string.Empty;
            bool   result   = ExcelOP.DataTableExportToExcel(dt, fileName, tabName, ref reMsg);



            string strFileName = fileName;

            if (result && !string.IsNullOrEmpty(strFileName))
            {
                string fileNewName = strFileName.Substring(strFileName.LastIndexOf("\\") + 1);
                Response.Clear();
                Response.ContentType     = "application/octet-stream";
                Response.ContentEncoding = Encoding.UTF8;
                Response.AppendHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(fileNewName, Encoding.UTF8));
                Response.WriteFile(strFileName);
                Response.End();
                return(Back("成功"));
            }
            else
            {
                return(Back("导出失败"));
            }
        }
        public ActionResult ExportExcelFileByPerson(FormCollection collection)
        {
            DataTable dt = new DataTable();

            dt.Columns.Add("ID", Type.GetType("System.Int32"));
            dt.Columns[0].AutoIncrement     = true;
            dt.Columns[0].AutoIncrementSeed = 1;
            dt.Columns[0].AutoIncrementStep = 1;
            dt.Columns.Add("项目名称", Type.GetType("System.String"));
            dt.Columns.Add("项目编号", Type.GetType("System.String"));
            dt.Columns.Add("项目类别", Type.GetType("System.String"));
            dt.Columns.Add("公司名称", Type.GetType("System.String"));
            dt.Columns.Add("规定时间", Type.GetType("System.String"));
            dt.Columns.Add("实际时间", Type.GetType("System.String"));
            dt.Columns.Add("项目负责人", Type.GetType("System.String"));



            foreach (var m in ProjectSearch.projectList)
            {
                DataRow dtRow = dt.NewRow();

                dtRow["项目名称"]  = "" + m.ProjectName;
                dtRow["项目编号"]  = "" + m.ProjectNumber;
                dtRow["项目类别"]  = "" + EnumHelper.GetEnumTitle((EnumProjectCategory)m.ProjectCategory);
                dtRow["公司名称"]  = "" + m.CompaneName;
                dtRow["规定时间"]  = "" + m.ProjectClosingDate.ToString();
                dtRow["实际时间"]  = "" + m.ProjectRealClosingDate.ToString();
                dtRow["项目名称"]  = "" + m.ProjectName;
                dtRow["项目负责人"] = "" + ProjectSearch.People;
                dt.Rows.Add(dtRow);
            }


            string fileName = "d://DKLdownload" + Web.Demo.Common.AdminUserContext.Current.LoginInfo.LoginName + "(" + DateTime.Now.ToString().Replace("/", "").Replace(":", "").Replace(" ", "") + ").xls";
            string tabName  = "负责人统计信息";
            string reMsg    = string.Empty;
            bool   result   = ExcelOP.DataTableExportToExcel(dt, fileName, tabName, ref reMsg);



            string strFileName = fileName;

            if (result && !string.IsNullOrEmpty(strFileName))
            {
                string fileNewName = strFileName.Substring(strFileName.LastIndexOf("\\") + 1);
                Response.Clear();
                Response.ContentType     = "application/octet-stream";
                Response.ContentEncoding = Encoding.UTF8;
                Response.AppendHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(fileNewName, Encoding.UTF8));
                Response.WriteFile(strFileName);
                Response.End();
                return(Back("成功"));
            }
            else
            {
                return(Back("导出失败"));
            }
        }
示例#3
0
        public ActionResult ExportExcelFile(FormCollection collection)
        {
            DataTable dt = new DataTable();

            dt.Columns.Add("ID", Type.GetType("System.Int32"));
            dt.Columns[0].AutoIncrement     = true;
            dt.Columns[0].AutoIncrementSeed = 1;
            dt.Columns[0].AutoIncrementStep = 1;
            dt.Columns.Add("项目编号", Type.GetType("System.String"));
            dt.Columns.Add("预约个数", Type.GetType("System.String"));
            dt.Columns.Add("预约人", Type.GetType("System.String"));
            dt.Columns.Add("预约时间", Type.GetType("System.String"));
            int i = 0;

            foreach (var m in Info)
            {
                ++i;
                DataRow dtRow = dt.NewRow();
                dtRow["项目编号"] = "" + m.ProjectNumber;
                dtRow["预约个数"] = "" + m.RealityOrderNumber;
                dtRow["预约人"]  = "" + m.OrderPerson;
                dtRow["预约时间"] = "" + m.OrderDate;
                dt.Rows.Add(dtRow);
            }
            string fileName = "d://DKLdownload" + Web.Demo.Common.AdminUserContext.Current.LoginInfo.LoginName + "(" + DateTime.Now.ToString().Replace("/", "").Replace(":", "").Replace(" ", "") + ").xls";
            string tabName  = "市场统计信息";
            string reMsg    = string.Empty;
            bool   result   = ExcelOP.DataTableExportToExcel(dt, fileName, tabName, ref reMsg);



            string strFileName = fileName;

            if (result && !string.IsNullOrEmpty(strFileName))
            {
                string fileNewName = strFileName.Substring(strFileName.LastIndexOf("\\") + 1);
                Response.Clear();
                Response.ContentType     = "application/octet-stream";
                Response.ContentEncoding = Encoding.UTF8;
                Response.AppendHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(fileNewName, Encoding.UTF8));
                Response.WriteFile(strFileName);
                Response.End();
                return(Back("成功"));
            }
            else
            {
                return(Back("导出失败"));
            }
        }