コード例 #1
1
        public ActionResult Index()
        {
            StringWriter stringWriter = new StringWriter();

            using (HtmlTextWriter writer = new HtmlTextWriter(stringWriter))
            {
                string classValue = "className";
                writer.RenderBeginTag(HtmlTextWriterTag.Html);

                writer.AddAttribute(HtmlTextWriterAttribute.Class, classValue);
                writer.AddStyleAttribute(HtmlTextWriterStyle.Color, "#db4141");
                writer.Write("Huy");
                writer.RenderBeginTag(HtmlTextWriterTag.Div);
                writer.RenderEndTag();

                writer.RenderEndTag();
                GridView grid = new GridView();
                grid.AllowPaging = false;
                grid.RenderControl(writer);
                //Change the Header Row back to white color
                DataTable[] dt = new DataTable[2];

                for (int i = 0; i <= 1; i++)
                {
                    dt[i] = new DataTable();
                    dt[i].Columns.Add("id");
                    dt[i].Columns.Add("name");
                }

                IHTMLBuilder htmlBuilder = new HTMLBuilder();
                htmlBuilder.Build();

                grid.DataSource = dt;
                grid.DataBind();
                //Apply style to Individual Cells
                grid.HeaderRow.Cells[0].Text = "harrison";
                grid.HeaderRow.Cells[0].Style.Add("background-color", "green");

                Response.Clear();
                Response.Buffer = true;
                Response.AddHeader("content-disposition",
                 "attachment;filename=GridViewExport.xls");
                Response.Charset = "";
                Response.ContentType = "application/vnd.ms-excel";
                Dictionary<string, IdentityModels> test = new Dictionary<string, IdentityModels>();
                test.Add("huy", new IdentityModels());
                var testModel =  test["huy"];

            }
            Response.Output.Write(stringWriter.ToString());
            Response.Flush();
            Response.End();
            return View();
        }
コード例 #2
0
        protected void btnExcel_Click(object sender, EventArgs e)
        {
            //Create a dummy GridView
            GridView GridView1 = new GridView();
            GridView1.AllowPaging = false;
            GridView1.DataSource = BindGridView();
            GridView1.DataBind();

            Response.Clear();
            Response.Buffer = true;
            Response.AddHeader("content-disposition",
             "attachment;filename=" + DateTime.Now.Year + "-Newly_Hired" + ".xls");
            Response.Charset = "";
            Response.ContentType = "application/vnd.ms-excel";
            StringWriter sw = new StringWriter();
            HtmlTextWriter hw = new HtmlTextWriter(sw);

            for (int i = 0; i < GridView1.Rows.Count; i++)
            {
                //Apply text style to each Row
                GridView1.Rows[i].Attributes.Add("class", "textmode");
            }
            GridView1.RenderControl(hw);

            //style to format numbers to string
            string style = @"<style> .textmode { mso-number-format:\@; } </style>";
            Response.Write(style);
            Response.Output.Write(sw.ToString());
            Response.Flush();
            Response.End();
        }
コード例 #3
0
        public ActionResult ExportProductData()
        {
            // string ss = "<table><td><td></table>";
               var products = Session["Product"];
               GridView gv = new GridView();
               gv.DataSource = products;
               gv.DataBind();
               Response.ClearContent();
               Response.Buffer = true;
               Response.AddHeader("content-disposition", "attachment; filename=Orderlist.xls");
               Response.ContentType = "application/ms-excel";
               Response.Charset = "";
               StringWriter sw = new StringWriter();
               HtmlTextWriter htw = new HtmlTextWriter(sw);
               gv.RenderControl(htw);
               Response.Output.Write(sw.ToString());
               Response.Flush();
               Response.End();

               //Response.ClearContent();
               //Response.AddHeader("content-disposition", "attachment; filename=Orderlist.xls");
               //Response.ContentType = "application/ms-excel";
               //Response.Write(ss);
               //Response.End();

               return RedirectToAction("Reports");
        }
コード例 #4
0
        /// <summary>
        /// 导出Excel
        /// </summary>
        /// <param name="obj"></param>
        public void ExportData(System.Web.UI.WebControls.GridView obj)
        {
            try
            {
                string style = "";
                if (obj.Rows.Count > 0)
                {
                    style = @"<style> .text { mso-number-format:\@; } </script> ";
                }
                else
                {
                    style = "no data.";
                }

                Response.ClearContent();
                DateTime dt       = DateTime.Now;
                string   filename = dt.Year.ToString() + dt.Month.ToString() + dt.Day.ToString() + dt.Hour.ToString() + dt.Minute.ToString() + dt.Second.ToString();
                Response.AddHeader("content-disposition", "attachment; filename=ExportData" + filename + ".xls");
                Response.ContentType     = "application/ms-excel";
                Response.Charset         = "GB2312";
                Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
                StringWriter   sw  = new StringWriter();
                HtmlTextWriter htw = new HtmlTextWriter(sw);
                obj.RenderControl(htw);
                Response.Write(style);
                Response.Write(sw.ToString());
                Response.End();
            }
            catch
            {
            }
        }
コード例 #5
0
ファイル: ReportUtil.cs プロジェクト: popotans/hjnlib
        public static void OutPutExcelByGridView(GridView grvExcel, string excelName, string encodingName, System.Globalization.CultureInfo ci)
        {
            //定义文档类型、字符编码
            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Buffer = true;
            HttpContext.Current.Response.Charset = encodingName;
            //下面这行很重要, attachment 参数表示作为附件下载,您可以改成 online在线打开
            //filename=FileFlow.xls 指定输出文件的名称,注意其扩展名和指定文件类型相符,可以为:.doc    .xls    .txt   .htm
            HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpContext.Current.Server.UrlEncode(excelName));
            HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding(encodingName);
            //Response.ContentType指定文件类型 可以为application/ms-excel、application/ms-word、application/ms-txt、application/ms-html 或其他浏览器可直接支持文档
            HttpContext.Current.Response.ContentType = "application/ms-excel";

            grvExcel.EnableViewState = false;
            if (ci == null) ci = new System.Globalization.CultureInfo("zh-CN", true);
            System.Globalization.CultureInfo myCultureInfo = ci;

            System.IO.StringWriter oStringWriter = new System.IO.StringWriter(myCultureInfo);
            System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);

            oHtmlTextWriter.Write("<html><head><meta http-equiv=\"content-type\" content=\"text/html;charset=gb2312\"></head>");

            grvExcel.Visible = true;
            grvExcel.RenderControl(oHtmlTextWriter);
            //this 表示输出本页,你也可以绑定datagrid,或其他支持obj.RenderControl()属性的控件
            HttpContext.Current.Response.Write(oStringWriter.ToString());
            HttpContext.Current.Response.End();
        }
コード例 #6
0
        private static void DisplayExcelDocument(System.Web.UI.WebControls.GridView grid, HttpResponse response)
        {
            var filename = string.Format("Отчет_{0}.xls", DateTime.Now.ToString());

            response.Clear();
            response.ContentType = "text/html";
            response.AddHeader("content-disposition", "attachment;filename=" + filename);

            response.ContentEncoding = Encoding.UTF8;

            var s      = new StringWriter();
            var writer = new ExcelHtmlTextWriter(s);

            var v = grid.AllowPaging;

            grid.AllowPaging = false;

            grid.RenderControl(writer);

            var hypertext = string.Format(
                @"<html><head><meta http-equiv=""Content-Type"" content=""text/html; charset=utf-8"" /></head><body>{0}</body></html>",
                s.ToString());

            response.Write(hypertext);
            response.Flush();
            response.End();

            grid.AllowPaging = v;
        }
コード例 #7
0
        public bool ToExcel(HttpResponseBase Response, DataTable listTable, string nomeArquivo = "ConsultaPedidos.xls", int columnsMerged = 0)
        {
            var grid = new System.Web.UI.WebControls.GridView();

            grid.DataSource = listTable;


            grid.DataBind();

            if (columnsMerged > 0)
            {
                MergeRows(grid, columnsMerged);
            }


            Response.ClearContent();
            Response.AddHeader("content-disposition", "attachment; filename=" + nomeArquivo);
            Response.ContentType = "application/excel";
            StringWriter   sw  = new StringWriter();
            HtmlTextWriter htw = new HtmlTextWriter(sw);

            grid.RenderControl(htw);
            Response.Write(sw.ToString());
            Response.End();

            return(true);
        }
コード例 #8
0
        protected void ExportToPDF(DataTable dt)
        {
            GridView gvExport = new GridView();
            gvExport.AllowPaging = false;
            gvExport.DataSource = dt;
            gvExport.DataBind();

            gvExport.HeaderRow.Style.Add("font-size", "10px");
            gvExport.HeaderRow.Style.Add("font-weight", "bold");
            gvExport.Style.Add("text-decoration", "none");
            gvExport.Style.Add("font-family", "Arial, Helvetica, sans-serif;");
            gvExport.Style.Add("font-size", "8px");

            Response.ContentType = "application/pdf";
            Response.AddHeader("content-disposition", "attachment;filename=LinkSpace.pdf");

            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            StringWriter sw = new StringWriter();
            HtmlTextWriter hw = new HtmlTextWriter(sw);

            gvExport.RenderControl(hw);

            StringReader sr = new StringReader(sw.ToString());
            Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
            HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
            PdfWriter.GetInstance(pdfDoc, Response.OutputStream);

            pdfDoc.Open();
            htmlparser.Parse(sr);
            pdfDoc.Close();
            Response.Write(pdfDoc);
            Response.End();
        }
コード例 #9
0
        public void ExportClientsListToExcel()
        {
            var grid = new System.Web.UI.WebControls.GridView();
            string[] ClientsList={"mike","jonh","vladimit"};
            grid.DataSource = /*from d in dbContext.diners
                              where d.user_diners.All(m => m.user_id == userID) && d.active == true */
                              from d in ClientsList
                              select new
                              {
                                  FirstName = d
                              };

            grid.DataBind();

            Response.ClearContent();
            Response.AddHeader("content-disposition", "attachment; filename=Exported_Diners.xls");
            Response.ContentType = "application/excel";
            StringWriter sw = new StringWriter();
            HtmlTextWriter htw = new HtmlTextWriter(sw);

            grid.RenderControl(htw);

            Response.Write(sw.ToString());

            Response.End();
        }
コード例 #10
0
ファイル: ShowReport.aspx.cs プロジェクト: tabtu/119CRT
    /// <summary>
    /// dtData是要导出为Excel的DataTable,FileName是要导出的Excel文件名(不加.xls)
    /// </summary>
    /// <param name="dtData"></param>
    /// <param name="FileName"></param>
    private void DataTable2Excel(DataTable dtData, String FileName)
    {
        System.Web.UI.WebControls.GridView dgExport = null;
        //当前对话
        System.Web.HttpContext curContext = System.Web.HttpContext.Current;
        //IO用于导出并返回excel文件
        System.IO.StringWriter       strWriter  = null;
        System.Web.UI.HtmlTextWriter htmlWriter = null;

        if (dtData != null)
        {
            //设置编码和附件格式
            //System.Web.HttpUtility.UrlEncode(FileName, System.Text.Encoding.UTF8)作用是方式中文文件名乱码
            curContext.Response.AddHeader("content-disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(FileName, System.Text.Encoding.UTF8) + ".xls");
            curContext.Response.ContentType     = "application nd.ms-excel";
            curContext.Response.ContentEncoding = System.Text.Encoding.UTF8;
            curContext.Response.Charset         = "GB2312";

            //导出Excel文件
            strWriter  = new System.IO.StringWriter();
            htmlWriter = new System.Web.UI.HtmlTextWriter(strWriter);

            //为了解决dgData中可能进行了分页的情况,需要重新定义一个无分页的GridView
            dgExport             = new System.Web.UI.WebControls.GridView();
            dgExport.DataSource  = dtData.DefaultView;
            dgExport.AllowPaging = false;
            dgExport.DataBind();

            //下载到客户端
            dgExport.RenderControl(htmlWriter);
            curContext.Response.Write(strWriter.ToString());
            curContext.Response.End();
        }
    }
コード例 #11
0
ファイル: WebCommon.cs プロジェクト: radtek/datacenter
        /// <summary>
        /// 将DataTable数据导出到EXCEL,调用该方法后自动返回可下载的文件流
        /// </summary>
        /// <param name="dtData">要导出的数据源</param>
        public static void DataTable1Excel(System.Data.DataTable dtData, string name)
        {
            System.Web.UI.WebControls.GridView gvExport = null;
            // 当前对话
            System.Web.HttpContext curContext = System.Web.HttpContext.Current;
            // IO用于导出并返回excel文件
            System.IO.StringWriter       strWriter  = null;
            System.Web.UI.HtmlTextWriter htmlWriter = null;

            if (dtData != null)
            {
                // 设置编码和附件格式
                curContext.Response.ContentType = "application/vnd.ms-excel";
                curContext.Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(name, Encoding.UTF8).ToString());
                curContext.Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
                curContext.Response.Charset         = "utf-8";

                // 导出excel文件
                strWriter  = new System.IO.StringWriter();
                htmlWriter = new System.Web.UI.HtmlTextWriter(strWriter);
                // 为了解决gvData中可能进行了分页的情况,需要重新定义一个无分页的GridView
                gvExport             = new System.Web.UI.WebControls.GridView();
                gvExport.DataSource  = dtData.DefaultView;
                gvExport.AllowPaging = false;

                gvExport.DataBind();

                // 返回客户端
                gvExport.RenderControl(htmlWriter);
                curContext.Response.Write("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=gb2312\" />" + strWriter.ToString());
                curContext.Response.End();
            }
        }
コード例 #12
0
        public ActionResult GetUserExcelList(string searchType, string searchText, int? page, int? rows)
        {
            var grid = new System.Web.UI.WebControls.GridView();
            List<UserT> model = new UserBiz().GetUserList(searchType, searchText, page.Value, rows.Value);

            grid.DataSource = from m in model
                              select new
                              {
                                  LoginId = m.LoginId,
                                  LastLoginDate = m.LastLoginDate,
                                  IsDeleted = m.IsDeleted,
                                  DeletedDate = m.DeletedDate,
                                  InsertUser = m.InsertUser,
                                  InsertDate = m.InsertDate,

                              };

            grid.DataBind();

            Response.ClearContent();

            Response.AddHeader("content-disposition", string.Format("attachment; filename=Excel_{0}.xls", DateTime.Now.ToString("yyyyMMddhhmmss")));
            Response.Write("<meta http-equiv='Content-Type' content='text/html; charset=" + Request.ContentEncoding.HeaderName + "'>");
            Response.Buffer = true;

            StringWriter sw = new StringWriter();
            HtmlTextWriter htw = new HtmlTextWriter(sw);

            grid.RenderControl(htw);
            Response.Write(sw.ToString());
            Response.End();

            return View("Index");
        }
コード例 #13
0
        public async Task<FileResult> CreateSendExcellFile()
        {
            List<Report> report = await db.FilesDownloadNotes.Include(f => f.ApplicationUser).Include(f => f.FilesUploadNote)
                                         .Select(x => new Report
                                         {
                                             FileName = x.FilesUploadNote.Name,
                                             FileFileSize = x.FilesUploadNote.Size,
                                             FileType = x.FilesUploadNote.Type,
                                             DataUploaded = x.FilesUploadNote.DataTimeUpload,
                                             WhoUploaded = x.FilesUploadNote.UserName,
                                             TypeOperations = x.FileOperations,
                                             DataOperations = x.DateTimeDownload,
                                             WhoOperations = x.ApplicationUser.UserName
                                         }).ToListAsync();
 
            GridView grid = new GridView();
            grid.DataSource = report;
            grid.DataBind();
            StringWriter sw = new StringWriter(); 
            HtmlTextWriter htw = new HtmlTextWriter(sw);
            grid.RenderControl(htw);
            string r_name = "Report_" + DateTime.Now.ToString() + "_.xls";

            return File(Encoding.UTF8.GetBytes(sw.ToString()), "application/ms-excel", r_name);
        }
コード例 #14
0
        /// <summary>
        /// 将GridView数据导出到Excel(保存为2003格式)
        /// </summary>
        /// <param name="obj"></param>
        public void GridViewExportToExcel(System.Web.UI.WebControls.GridView obj)
        {
            try
            {
                string style = "";
                if (obj.Rows.Count > 0)
                {
                    style = @"<style> .text { mso-number-format:\@; } </script> ";
                }
                else
                {
                    style = "no data.";
                }

                HttpContext.Current.Response.ClearContent();
                string fileName = DateTime.Now.ToString("yyyyMMddHHmmsslll");
                HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=ExportData" + fileName + ".xls");
                HttpContext.Current.Response.ContentType = "application/ms-excel";
                HttpContext.Current.Response.Charset = "GB2312";
                HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
                StringWriter sw = new StringWriter();
                HtmlTextWriter htw = new HtmlTextWriter(sw);
                obj.RenderControl(htw);
                HttpContext.Current.Response.Write(style);
                HttpContext.Current.Response.Write(sw.ToString());
                HttpContext.Current.Response.End();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #15
0
ファイル: GenReportes.cs プロジェクト: rudolfcruz/Reports
        public void ExportToExcel(DataTable dataTable, HttpResponse response)
        {
            // Create a dummy GridView
            GridView GridView1 = new GridView();
            GridView1.AllowPaging = false;
            GridView1.DataSource = dataTable;
            GridView1.DataBind();
            response.Clear();
            response.Buffer = true;
            response.AddHeader("content-disposition", "attachment;filename=DataTable.xls");
            response.Charset = "";
            response.ContentType = "application/vnd.ms-excel";
            StringWriter sw = new StringWriter();
            HtmlTextWriter hw = new HtmlTextWriter(sw);
            for (int i = 0; (i
                        <= (GridView1.Rows.Count - 1)); i++)
            {
                // Apply text style to each Row
                GridView1.Rows[i].Attributes.Add("class", "textmode");
            }

            GridView1.RenderControl(hw);
            // style to format numbers to string
            string style = "<style> .textmode{mso-number-format:\\@;}</style>";
            response.Write(style);
            response.Output.Write(sw.ToString());
            response.Flush();
            response.End();
        }
コード例 #16
0
        public void ExportClientsListToExcel()
        {
            var grid = new System.Web.UI.WebControls.GridView();

            string[] ClientsList = { "mike", "jonh", "vladimit" };
            grid.DataSource = /*from d in dbContext.diners
                               * where d.user_diners.All(m => m.user_id == userID) && d.active == true */
                              from d in ClientsList
                              select new
            {
                FirstName = d
            };

            grid.DataBind();

            Response.ClearContent();
            Response.AddHeader("content-disposition", "attachment; filename=Exported_Diners.xls");
            Response.ContentType = "application/excel";
            StringWriter   sw  = new StringWriter();
            HtmlTextWriter htw = new HtmlTextWriter(sw);

            grid.RenderControl(htw);

            Response.Write(sw.ToString());

            Response.End();
        }
コード例 #17
0
        public void ExportRiskTableToXLS()
        {
            var grid = new System.Web.UI.WebControls.GridView();

            grid.DataSource = /*from d in dbContext.diners
                               * where d.user_diners.All(m => m.user_id == userID) && d.active == true */
                              from line in GlobalVariables.glob_risk_list
                              select new
            {
                RiskName        = line.risk_name,
                RiskCategory    = line.risk_category,
                RiskProbability = line.risk_probability,
                RiskImpact      = line.risk_impact,
                RiskRMMM        = line.risk_RMMM
            };

            grid.DataBind();

            Response.ClearContent();
            Response.AddHeader("content-disposition", "attachment; filename=RiskTable.xls");
            Response.ContentType = "application/excel";
            StringWriter   sw  = new StringWriter();
            HtmlTextWriter htw = new HtmlTextWriter(sw);

            grid.RenderControl(htw);

            Response.Write(sw.ToString());

            Response.End();
        }
コード例 #18
0
        public ActionResult ExportToPdf()
        {
            var grid = new System.Web.UI.WebControls.GridView();

            grid.DataSource = GetAirtelDetails();
            grid.DataBind();

            Response.ClearContent();
            Response.Buffer = true;
            Response.AddHeader("content-disposition", "attachment; filename=MyPdf.pdf");
            Response.ContentType = "application/pdf";

            Response.Charset = "";
            StringWriter   sw  = new StringWriter();
            HtmlTextWriter htw = new HtmlTextWriter(sw);

            grid.RenderControl(htw);
            StringReader sr         = new StringReader(sw.ToString());
            Document     pdfDoc     = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
            HTMLWorker   htmlparser = new HTMLWorker(pdfDoc);

            PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
            pdfDoc.Open();
            htmlparser.Parse(sr);
            pdfDoc.Close();
            Response.Write(pdfDoc);

            Response.Output.Write(sw.ToString());
            Response.Flush();
            Response.End();

            return(View("Index"));
        }
コード例 #19
0
ファイル: frmGenRep.aspx.cs プロジェクト: rudolfcruz/Reports
        protected void generaXLS(string reporte, string campos, string sql)
        {
            GridView GridView2 = new GridView();
            GridView2.AllowPaging = false;
            GridView2.DataSource = obtienDatosTabla(campos, sql);
            GridView2.DataBind();
            Response.Clear();
            Response.Buffer = true;
            Response.AddHeader("content-disposition", "attachment;filename=" + reporte + ".xls");
            Response.Charset = "";
            Response.ContentType = "application/vnd.ms-excel";
            StringWriter sw = new StringWriter();
            HtmlTextWriter hw = new HtmlTextWriter(sw);
            for (int i = 0; (i
                        <= (GridView2.Rows.Count - 1)); i++)
            {
                // Apply text style to each Row
                GridView2.Rows[i].Attributes.Add("class", "textmode");
            }

            GridView2.RenderControl(hw);
            string style = "<style> .textmode{mso-number-format:\\@;}</style>";
            Response.Write(style);
            Response.Output.Write(sw.ToString());
            Response.Flush();
            Response.End();
        }
コード例 #20
0
ファイル: Right.ascx.cs プロジェクト: phamtuanchip/tmdt
        protected void btnDownload_Click(object sender, ImageClickEventArgs e)
        {
            Response.Clear();

            Response.AddHeader("content-disposition", "attachment; filename=Baogia.xls");

            Response.Charset = "";

            Response.ContentType = "application/vnd.xls";

            System.IO.StringWriter stringWrite = new System.IO.StringWriter();

            System.Web.UI.HtmlTextWriter htmlWrite =
            new HtmlTextWriter(stringWrite);

            DataSet dts = new DataSet();
            SqlDataAdapter adt = new SqlDataAdapter();
            SqlCommand comm = new SqlCommand("Export_to_Excel", objConn.SqlConn());
            comm.CommandType = CommandType.StoredProcedure;
            comm.Connection.Open();
            adt.SelectCommand = comm;
            adt.Fill(dts);

            GridView g = new GridView();
            g.DataSource = dts;
            g.DataBind();

            g.RenderControl(htmlWrite);

            Response.Write(stringWrite.ToString());

            Response.End();
        }
コード例 #21
0
        protected void generatePDFButton_Click(object sender, EventArgs e)
        {
            DataTable aDataTable = aPatientManager.GetData(Convert.ToInt64(voterIdTextBox.Text));

            GridView GridView1 = new GridView();
            GridView1.AllowPaging = false;
            GridView1.ShowHeaderWhenEmpty = true;
            GridView1.DataSource = aDataTable;
            GridView1.DataBind();

            Response.ContentType = "application/pdf";
            Response.AddHeader("content-disposition", "attachment;filename=AllHistoryOfAPatient.pdf");
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            StringWriter aStringWriter = new StringWriter();
            HtmlTextWriter aHtmlTextWriter = new HtmlTextWriter(aStringWriter);
            GridView1.RenderControl(aHtmlTextWriter);
            StringReader aStringReader = new StringReader(aStringWriter.ToString());
            Document pdfDocument = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
            HTMLWorker aHtmlWorker = new HTMLWorker(pdfDocument);
            PdfWriter.GetInstance(pdfDocument, Response.OutputStream);
            pdfDocument.Open();
            aHtmlWorker.Parse(aStringReader);
            pdfDocument.Close();
            Response.Write(pdfDocument);
            Response.End();
        }
        public ActionResult ExportToExcel()
        {
            try
            {
                list = (List<NhanVien>)TempData["list"];
                if (list != null)
                {
                    GridView gv = new GridView();
                    gv.DataSource = list;
                    gv.DataBind();
                    Response.ClearContent();
                    Response.Buffer = true;
                    Response.AddHeader("content-disposition", "attachment; filename=DanhSachNhanVienVeHuu.xls");
                    Response.ContentType = "application/ms-excel";
                    Response.Charset = "";
                    StringWriter sw = new StringWriter();
                    HtmlTextWriter htw = new HtmlTextWriter(sw);
                    gv.RenderControl(htw);
                    Response.Output.Write(sw.ToString());
                    Response.Flush();
                    Response.End();
                }
                else
                {
                    return Content("<script language='javascript' type='text/javascript'>alert('Không thể xuất file excel');");
                }

                return RedirectToAction("VeHuu");
            }
            catch (Exception)
            {

                throw;
            }
        }
コード例 #23
0
ファイル: Function.cs プロジェクト: hsjun/HNAS.Framework4.1
        /// <summary>
        /// GridView导出到Excel
        /// </summary>
        /// <param name="gvBindData"></param>
        /// <param name="strExcelName">文件名</param>
        /// <param name="strCharset">编码类型</param>
        /// <param name="page">默认当前页面</param>
        public static void GridViewToExcel(GridView gvBindData, string strExcelName = "GridView", string strCharset = "GB2312", Page page = null)
        {
            gvBindData.AllowPaging = false;
            gvBindData.DataBind();
            for (int i = 0; i < gvBindData.Columns.Count; i++)
            {
                if (gvBindData.Columns[i].FooterText.IndexOf("Delete") >= 0)
                {
                    gvBindData.Columns[i].Visible = false;
                }
            }
            if (page == null)
            {
                page = ((Page)HttpContext.Current.Handler);
            }

            page.Response.Clear();
            page.Response.Buffer = false;
            page.Response.Charset = strCharset;
            page.Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(strExcelName, Encoding.UTF8) + ".xls");
            page.Response.ContentEncoding = Encoding.GetEncoding(strCharset);
            page.Response.ContentType = "application/ms-excel";
            StringWriter oStringWriter = new StringWriter();
            HtmlTextWriter writer = new HtmlTextWriter(oStringWriter);
            gvBindData.RenderControl(writer);
            page.Response.Write(oStringWriter.ToString());
            page.Response.End();
            gvBindData.AllowPaging = true;
        }
コード例 #24
0
        /// <summary>
        /// 将GridView数据导出Excel
        /// </summary>
        /// <param name="obj"></param>
        public void ExportData(GridView obj)
        {
            try
            {
                string style = "";
                if (obj.Rows.Count > 0)
                {
                    style = @"<style> .text { mso-number-format:\@; } </script> ";
                }
                else
                {
                    style = "no data.";
                }

                HttpContext.Current.Response.ClearContent();
                DateTime dt = DateTime.Now;
                string filename = dt.Year.ToString() + dt.Month.ToString() + dt.Day.ToString() + dt.Hour.ToString() + dt.Minute.ToString() + dt.Second.ToString();
                HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=ExportData" + filename + ".xls");
                HttpContext.Current.Response.ContentType = "application/ms-excel";
                HttpContext.Current.Response.Charset = "GB2312";
                HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
                StringWriter sw = new StringWriter();
                HtmlTextWriter htw = new HtmlTextWriter(sw);
                obj.RenderControl(htw);
                HttpContext.Current.Response.Write(style);
                HttpContext.Current.Response.Write(sw.ToString());
                HttpContext.Current.Response.End();
            }
            catch
            {

            }
        }
コード例 #25
0
        /// <summary>
        /// 描述:把DataTable内容导出excel并返回客户端
        /// 作者:李伟波
        /// 时间:2012-10-18
        /// </summary>
        /// <param name="dtData"></param>
        /// <param name="header"></param>
        /// <param name="fileName"></param>
        /// <param name="mergeCellNums">要合并的列索引字典 格式:列索引-合并模式(合并模式 1 合并相同项、2 合并空项、3 合并相同项及空项)</param>
        /// <param name="mergeKey">作为合并项的标记列索引</param>
        public static void DataTable2Excel(System.Data.DataTable dtData, TableCell[] header, string fileName, Dictionary <int, int> mergeCellNums, int?mergeKey)
        {
            System.Web.UI.WebControls.GridView gvExport = null;
            // 当前对话
            System.Web.HttpContext curContext = System.Web.HttpContext.Current;
            // IO用于导出并返回excel文件
            System.IO.StringWriter       strWriter  = null;
            System.Web.UI.HtmlTextWriter htmlWriter = null;

            if (dtData != null)
            {
                // 设置编码和附件格式
                curContext.Response.ContentType     = "application/vnd.ms-excel";
                curContext.Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
                curContext.Response.Charset         = "gb2312";
                if (!string.IsNullOrEmpty(fileName))
                {
                    //处理中文名乱码问题
                    fileName = System.Web.HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8);
                    curContext.Response.AppendHeader("Content-Disposition", ("attachment;filename=" + (fileName.ToLower().EndsWith(".xls") ? fileName : fileName + ".xls")));
                }
                // 导出excel文件
                strWriter  = new System.IO.StringWriter();
                htmlWriter = new System.Web.UI.HtmlTextWriter(strWriter);

                // 重新定义一个无分页的GridView
                gvExport             = new System.Web.UI.WebControls.GridView();
                gvExport.DataSource  = dtData.DefaultView;
                gvExport.AllowPaging = false;
                //优化导出数据显示,如身份证、12-1等显示异常问题
                gvExport.RowDataBound += new System.Web.UI.WebControls.GridViewRowEventHandler(dgExport_RowDataBound);

                gvExport.DataBind();
                //处理表头
                if (header != null && header.Length > 0)
                {
                    if (gvExport.HeaderRow == null)
                    {
                        return;
                    }
                    gvExport.HeaderRow.Cells.Clear();
                    gvExport.HeaderRow.Cells.AddRange(header);
                }
                //合并单元格
                if (mergeCellNums != null && mergeCellNums.Count > 0)
                {
                    foreach (int cellNum in mergeCellNums.Keys)
                    {
                        MergeRows(gvExport, cellNum, mergeCellNums[cellNum], mergeKey);
                    }
                }

                // 返回客户端
                gvExport.RenderControl(htmlWriter);
                curContext.Response.Clear();
                curContext.Response.Write("<meta http-equiv=\"content-type\" content=\"application/ms-excel; charset=gb2312\"/>" + strWriter.ToString());
                curContext.Response.End();
            }
        }
コード例 #26
0
 public string GetGridViewData(GridView gv)
 {
     StringBuilder strbuild = new StringBuilder();
     StringWriter strwrite = new StringWriter(strbuild);
     HtmlTextWriter html = new HtmlTextWriter(strwrite);
     gv.RenderControl(html);
     return strbuild.ToString();
 }
コード例 #27
0
 private string GridViewToHtml(GridView gv)
 {
     StringBuilder sb = new StringBuilder();
     StringWriter sw = new StringWriter(sb);
     HtmlTextWriter hw = new HtmlTextWriter(sw);
     gv.RenderControl(hw);
     return sb.ToString();
 }
コード例 #28
0
ファイル: ExcelResult.cs プロジェクト: EnricoSaunders/h5forms
        private StringWriter GetDataFormated()
        {
            var stringWriter = new StringWriter();
            var htmlWrite = new HtmlTextWriter(stringWriter);
            var dataGrid = new GridView { DataSource = GetDataTable() };
            dataGrid.DataBind();
            dataGrid.RenderControl(htmlWrite);

            return stringWriter;
        }
コード例 #29
0
        public ActionResult Export()
        {
            DataTable dt = ToDataTable(db.EmployeeMsts.ToList());

            if (dt.Rows.Count > 0)
            {
                DataSet ds = new DataSet();
                ds.Tables.Add(dt);
                ds.Tables[0].Columns.Remove("EmployeeID");
                ds.Tables[0].Columns.Remove("Image");

                System.Web.UI.WebControls.GridView gv = new System.Web.UI.WebControls.GridView();
                gv.DataSource = ds;
                gv.DataBind();
                Response.ClearContent();
                Response.Buffer = true;
                Response.AddHeader("content-disposition", "attachment; filename=outage_manager.xls");
                Response.ContentType = "application/ms-excel";
                Response.Charset     = "";

                StringWriter   sw  = new StringWriter();
                HtmlTextWriter htw = new HtmlTextWriter(sw);

                gv.HeaderRow.Style.Add("background-color", "#92D050");

                Table table = new Table();

                TableRow title = new TableRow();
                title.BackColor = Color.Gray;

                TableCell titlecell = new TableCell();
                titlecell.ColumnSpan      = 9;//Should span across all columns
                titlecell.HorizontalAlign = HorizontalAlign.Left;
                titlecell.RowSpan         = 2;


                Label lbl = new Label();
                lbl.Text = "Employee Details";
                lbl.Style.Add("font-size", "medium");
                lbl.Style.Add("font-family", "Arial");
                lbl.Style.Add("font-weight", "bold");

                titlecell.Controls.Add(lbl);
                title.Cells.Add(titlecell);
                table.Rows.Add(title);
                table.RenderControl(htw);

                gv.RenderControl(htw);
                Response.Output.Write(sw.ToString());
                Response.Flush();
                Response.End();
            }
            return(RedirectToAction("Index"));
        }
コード例 #30
0
        public static void ExportGridView(GridView gridView, string fileName, ExportType exportType)
        {
            const string m_Http_Attachment = "attachment;filename=";
            const string m_Http_Content = "content-disposition";

            HttpResponse m_Response = HttpContext.Current.Response;

            m_Response.Clear();
            m_Response.ClearContent();
            m_Response.ClearHeaders();
            m_Response.Buffer = true;

            m_Response.AddHeader(m_Http_Content, m_Http_Attachment + fileName);
            m_Response.ContentEncoding = Encoding.UTF8;
            m_Response.Cache.SetCacheability(HttpCacheability.NoCache);

            StringWriter m_StringWriter = new StringWriter();
            HtmlTextWriter m_HtmlWriter = new HtmlTextWriter(m_StringWriter);

            gridView.AllowPaging = false;
            gridView.HeaderStyle.Font.Bold = true;
            gridView.DataBind();

            ClearControls(gridView);
            try
            {
                gridView.RenderControl(m_HtmlWriter);
            }
            catch (Exception ex) { ex.ToString(); }

            string m_gridViewText = m_StringWriter.ToString();

            switch (exportType)
            {
                case ExportType.Excel:
                    ExportHelper.ExportToExcelWord(m_gridViewText, "application/vnd.ms-excel", m_Response);
                    break;

                case ExportType.CSV:
                    ExportHelper.ExportToCsv(m_gridViewText, "application/csv", m_Response);
                    break;

                case ExportType.Word:
                    ExportHelper.ExportToExcelWord(m_gridViewText, "application/vnd.ms-word", m_Response);
                    break;

                default:
                    ExportHelper.ExportToExcelWord(m_gridViewText, "application/vnd.ms-excel", m_Response);
                    break;
            }
        }
コード例 #31
0
        public void Excel() {
            var grid = new GridView();
            grid.DataSource = adminOrchestrator.AllAppData();
            grid.DataBind();

            Response.ClearContent();
            Response.AddHeader("content-disposition", "attachment;filename=SlpApplications.xls");
            Response.ContentType = "text/excel";
            StringWriter sw = new StringWriter();
            HtmlTextWriter htmlTextWriter = new HtmlTextWriter(sw);
            grid.RenderControl(htmlTextWriter);
            Response.Write(sw.ToString());
            Response.End();
        }
コード例 #32
0
    /// <summary>
    /// 把DataTable内容导出Excel并返回客户端
    /// </summary>
    /// <param name="dtData">DataTable</param>
    /// <param name="strName">自定义DataTable列名数组(把数据库表字段名转换为用户实际需要的字段名)</param>
    /// <param name="strCaption">导出XLS文件头部标题(根据需要自定义)</param>
    /// <param name="strFileName">导出XLS文件名(不包含后缀名)</param>
    public static void DataToExcel(DataTable dtData, string[] strName, string strCaption, string strFileName)
    {
        System.Web.UI.WebControls.GridView dgExport = null;
        // 当前对话
        System.Web.HttpContext curContext = System.Web.HttpContext.Current;
        // IO用于导出并返回excel文件
        System.IO.StringWriter       strWriter  = null;
        System.Web.UI.HtmlTextWriter htmlWriter = null;

        if (dtData != null)
        {
            string attachment = "attachment; filename=" + System.Web.HttpUtility.UrlEncode(strFileName, System.Text.Encoding.UTF8) + ".xls";
            // 设置编码和附件格式
            HttpResponse Response = HttpContext.Current.Response;
            Response.ClearContent();
            Response.AddHeader("content-disposition", attachment);
            //Response.ContentType = "application/ms-excel";
            Response.ContentType     = "application/vnd.ms-excel";
            Response.ContentEncoding = System.Text.Encoding.UTF7;
            Response.Charset         = "";

            // 导出excel文件
            strWriter  = new System.IO.StringWriter();
            htmlWriter = new System.Web.UI.HtmlTextWriter(strWriter);

            // 为了解决dgData中可能进行了分页的情况,需要重新定义一个无分页的DataGrid
            dgExport         = new System.Web.UI.WebControls.GridView();
            dgExport.Caption = strCaption;
            dgExport.RowStyle.HorizontalAlign    = System.Web.UI.WebControls.HorizontalAlign.Left;
            dgExport.HeaderStyle.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Left;
            dgExport.HeaderStyle.Font.Bold       = false;
            dgExport.DataSource = dtData.DefaultView;

            if (strName.Length > 0)
            {
                int i;
                for (i = 0; i < strName.Length; i++)
                {
                    dtData.Columns[i].ColumnName = strName[i];
                }
            }
            dgExport.AllowPaging = false;
            dgExport.DataBind();

            // 返回客户端
            dgExport.RenderControl(htmlWriter);
            curContext.Response.Write(strWriter.ToString());
            curContext.Response.End();
        }
    }
コード例 #33
0
        public ActionResult ExportToExcel(DateTime? fromDate, DateTime? toDate)
        {
            var db = DAL.DbContext.Create();

            GridView gv = new GridView();

            ExportToExcelData exportToExcelData = new ExportToExcelData();

            var confromDate = Convert.ToDateTime(fromDate);
            var contoDate = Convert.ToDateTime(toDate);

            var addToDate = contoDate.AddDays(1);

            var taplogs = db.SelectStudentsDateTap(confromDate, addToDate);
            List<ExportToExcel> list = new List<ExportToExcel>();
            foreach (var taplog in taplogs)
            {
                taplog.Student = db.Students.Get(taplog.StudentID);
                taplog.Student.Course = db.Courses.Get(taplog.Student.CourseID);

                list.Add(new ExportToExcel
                {
                    DateTimeTap = taplog.DateTimeTap,
                    StudentID = taplog.Student.StudentID,
                    LastName = taplog.Student.LastName,
                    FirstName = taplog.Student.FirstName,
                    CourseAbbv = taplog.Student.Course.CourseAbbv
                });
            }

            gv.DataSource = list.ToList();
            gv.DataBind();
            Response.Clear();
            Response.Buffer = true;
            Response.ContentType = "application/ms-excel";
            Response.AddHeader("content-disposition", "attachment;filename=StudentTapLogList.xls");
            Response.Charset = "";

            StringWriter sw = new StringWriter();
            HtmlTextWriter htw = new HtmlTextWriter(sw);

            gv.RenderControl(htw);

            Response.Output.Write(sw.ToString());
            Response.Flush();
            Response.End();

            return RedirectToAction("Index");
            //return View(list.ToList());
        }
コード例 #34
0
    public static void ExportExcelFromGridView(System.Web.UI.WebControls.GridView gv)
    {
        string filename = HttpUtility.UrlEncode("IA" + DateTime.Now.ToString("yyyyMMddhhmmss") + ".xls", System.Text.Encoding.GetEncoding("utf-8"));

        HttpContext.Current.Response.Clear();
        HttpContext.Current.Response.Write("<meta http-equiv=\"content-type\" content=\"text/html;charset=utf-8\">");
        HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=" + filename);
        HttpContext.Current.Response.Charset     = "utf-8";
        HttpContext.Current.Response.ContentType = "application/vnd.xls";
        System.IO.StringWriter       stringWrite = new System.IO.StringWriter();
        System.Web.UI.HtmlTextWriter htmlWrite   = new System.Web.UI.HtmlTextWriter(stringWrite);

        gv.RenderControl(htmlWrite);
        HttpContext.Current.Response.Write(stringWrite.ToString());
        HttpContext.Current.Response.End();
    }
コード例 #35
0
        public void ToExcel(HttpResponseBase Response, object clientsList)
        {
            var grid = new System.Web.UI.WebControls.GridView();

            grid.DataSource = clientsList;
            grid.DataBind();
            Response.ClearContent();
            Response.AddHeader("content-disposition", "attachment; filename=FileName.xls");
            Response.ContentType = "application/excel";
            StringWriter   sw  = new StringWriter();
            HtmlTextWriter htw = new HtmlTextWriter(sw);

            grid.RenderControl(htw);
            Response.Write(sw.ToString());
            Response.End();
        }
コード例 #36
0
ファイル: StringEx.cs プロジェクト: daonidedie/-
        /// <summary>
        /// 返回传入的excel是不是正确的时刻表格式
        /// </summary>
        /// <param name="absFileName">绝对路径文件名</param>
        /// <param name="htmStr">返回的HTML字符串用于生成Excel</param>
        /// <param name="excelDt">返回的DataTable 用于处理数据源</param>
        public static bool IsExcelFormatRight(string absFileName, out string htmStr, out DataTable excelDt)
        {
            // 时刻表
            DataTable timedataTable = new DataTable();

            // 用于输出的控件
            System.Web.UI.WebControls.GridView GridView1 = new System.Web.UI.WebControls.GridView();
            bool returnvalue = true;

            //把excel转成DataTable
            timedataTable        = ExcelOperate.Import(absFileName);
            GridView1.DataSource = timedataTable;
            GridView1.DataBind();

            //开始创建用于输出的对像
            System.IO.StringWriter sW = new System.IO.StringWriter();
            Html32TextWriter       hW = new Html32TextWriter(sW);

            //看看是不是正确的格式
            foreach (GridViewRow row in GridView1.Rows)
            {
                if (row.RowType == DataControlRowType.DataRow)
                {
                    for (int i = 0; i < row.Cells.Count; i++)
                    {
                        if (i != 3 && i != 0)//3为地点
                        {
                            try
                            {
                                row.Cells[i].Text = DateTime.Parse(row.Cells[i].Text).ToString("HH:mm");
                            }
                            catch
                            {
                                row.Cells[i].Attributes.Add("style", "background:#ff0000;");
                                row.Attributes["title"] = "输入时间格式不正确";
                                returnvalue             = false;
                            }
                        }
                    }
                }
            }
            GridView1.RenderControl(hW);
            //输出参数
            htmStr  = sW.ToString();
            excelDt = timedataTable;
            return(returnvalue);
        }
コード例 #37
0
        public ActionResult _ExporttoExcel()
        {
            var       user = userDb.GetAllUser().ToList();
            DataTable dt   = new DataTable();

            dt.Columns.Add(new DataColumn("User Id"));
            dt.Columns.Add(new DataColumn("User Name"));
            dt.Columns.Add(new DataColumn("Email"));
            dt.Columns.Add(new DataColumn("Role Description"));
            dt.Columns.Add(new DataColumn("Is Active"));
            //dt.Columns.Add(new DataColumn(""));
            //dt.Columns.Add(new DataColumn(" "));
            //dt.Columns.Add(new DataColumn(""));
            //dt.Columns.Add(new DataColumn(""));

            foreach (var e in user)
            {
                DataRow dr_final1 = dt.NewRow();
                dr_final1["User Id"]          = e.Id;
                dr_final1["User Name"]        = e.UserName;
                dr_final1["Email"]            = e.Email;
                dr_final1["Role Description"] = e.Name;
                //dr_final1[""] = e.;
                //dr_final1[""] = e.;
                //dr_final1[" "] = e.;
                //dr_final1[""] = e.;
                dr_final1["Is Active"] = e.IsActive;
                dt.Rows.Add(dr_final1);
            }

            System.Web.UI.WebControls.GridView gridvw = new System.Web.UI.WebControls.GridView();
            gridvw.DataSource = dt; //bind the datatable to the gridview
            gridvw.DataBind();
            Response.ClearContent();
            Response.Buffer = true;
            Response.AddHeader("content-disposition", "attachment; filename=UserList.xls"); //Microsoft Office Excel Worksheet (.xlsx)
            Response.ContentType = "application/ms-excel";                                  //"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
            Response.Charset     = "";
            StringWriter   sw  = new StringWriter();
            HtmlTextWriter htw = new HtmlTextWriter(sw);

            gridvw.RenderControl(htw);
            Response.Output.Write(sw.ToString());
            Response.Flush();
            Response.End();
            return(RedirectToAction("Index", "User"));
        }
コード例 #38
0
ファイル: ImportHelper.aspx.cs プロジェクト: francis-star/NSP
 public void ExportDataToCSV(System.Data.DataTable dt, string FileName, int[] indexs)
 {
     if (dt == null)
     {
         return;
     }
     if (dt.Rows.Count == 0)
     {
         return;
     }
     try
     {
         System.Web.UI.WebControls.GridView dgExport = new System.Web.UI.WebControls.GridView();
         dgExport.AllowPaging = false;
         //dgExport.CellPadding = 2;
         //dgExport.RowDataBound += new GridViewRowEventHandler(dgExport_RowDataBound);
         dgExport.DataSource = dt;
         dgExport.DataMember = dt.TableName;
         dgExport.DataBind();
         System.Web.HttpContext.Current.Response.Clear();
         System.Web.HttpContext.Current.Response.Buffer          = true;
         System.Web.HttpContext.Current.Response.ContentEncoding = Encoding.GetEncoding("gb2312");
         System.Web.HttpContext.Current.Response.Charset         = "";
         //System.Web.HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + strFileName);
         System.Web.HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName + ".csv"));
         string strText     = "";
         string strRowDelim = System.Environment.NewLine;
         string strColDelim = ",";
         System.Web.HttpContext.Current.Response.ContentType = "text/txt";
         // System.Web.HttpContext.Current.Response.ContentType = "application/unkown";
         System.Web.HttpContext.Current.Response.ContentEncoding = Encoding.GetEncoding("gb2312");
         System.Globalization.CultureInfo myCItrad = new System.Globalization.CultureInfo("ZH-CN", true);
         //System.IO.StringWriter oStringWriter = new System.IO.StringWriter(myCItrad);
         System.IO.StringWriter       oStringWriter   = new System.IO.StringWriter();
         System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
         dgExport.RenderControl(oHtmlTextWriter);
         strText = oStringWriter.ToString();
         strText = ParseToDelim(strText, strRowDelim, strColDelim);
         System.Web.HttpContext.Current.Response.Write(strText);
         System.Web.HttpContext.Current.Response.End();
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
コード例 #39
0
ファイル: ExportDataController.cs プロジェクト: GDShop/GDShop
 // GET: ExportData
 public void ExportData()
 {
     var data = new GridView();
     data.DataSource = db.getListKhoHang();
     data.DataBind();
     Response.ClearContent();
     Response.Buffer = true;
     Response.AddHeader("content-disposition", "attachment; filename=Marklist.xls");
     Response.ContentType = "application/ms-excel";
     Response.Charset = "";
     StringWriter sw = new StringWriter();
     HtmlTextWriter htw = new HtmlTextWriter(sw);
     data.RenderControl(htw);
     Response.Output.Write(sw.ToString());
     Response.Flush();
     Response.End();
 }
コード例 #40
0
        public void ExportGridViewToExcel(GridView grid, string fileName, HttpResponse Hresponse)
        {
            Hresponse.Clear();
            Hresponse.Buffer = true;
            Hresponse.AddHeader("content-disposition", "attachment;fileName=" + fileName + ".xls");
            Hresponse.Charset = "";
            Hresponse.ContentType = "application/vnd.ms-excel";

            StringWriter sw = new StringWriter();
            HtmlTextWriter hw = new HtmlTextWriter(sw);
            grid.RenderControl(hw);
            Hresponse.Output.Write(sw.ToString());
            Hresponse.Flush();
            Hresponse.Close();
            //Hresponse.End();
            Hresponse.OutputStream.Close();
        }
コード例 #41
0
        /// <summary>
        /// 导出到Excel文件
        /// </summary>
        /// <param name="gv"></param>
        /// <param name="fileName"></param>
        public static void ExportToExcel(System.Web.UI.WebControls.GridView gv, string fileName)
        {
            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Buffer  = true;
            HttpContext.Current.Response.Charset = "GB2312";
            HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8) + ".xls");
            // 如果设置为 GetEncoding("GB2312");导出的文件将会出现乱码!!!
            HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.Default;
            HttpContext.Current.Response.ContentType     = "application/ms-excel";//设置输出文件类型为excel文件。

            System.IO.StringWriter       oStringWriter   = new System.IO.StringWriter();
            System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);

            gv.RenderControl(oHtmlTextWriter);
            HttpContext.Current.Response.Output.Write(oStringWriter.ToString());
            HttpContext.Current.Response.Flush();
            HttpContext.Current.Response.End();
        }
コード例 #42
0
 protected void ExportListFromGridView(object sender, EventArgs e)
 {
     Response.ClearContent();
     Response.AddHeader("content-disposition", "attachment;filename=Info Proyectos Grupos.xls");
     Response.AddHeader("Content-Type", "application/vnd.ms-excel");
     using (System.IO.StringWriter sw = new System.IO.StringWriter())
     {
         using (System.Web.UI.HtmlTextWriter htw = new System.Web.UI.HtmlTextWriter(sw))
         {
             System.Web.UI.WebControls.GridView grid = new System.Web.UI.WebControls.GridView();
             grid.DataSource = dt.consultarProyec();
             grid.DataBind();
             grid.RenderControl(htw);
             Response.Write(sw.ToString());
         }
     }
     Response.End();
 }
コード例 #43
0
        public void ProcessRequest(HttpContext context)
        {
            string tabData = context.Request["excelData"];

            DataTable dt = ConvertCsvData(tabData);
            if (dt == null)
            {
                //  Add some error-catching here...
                return;
            }

             //MS Word Code
            //Create a dummy GridView
            GridView GridView1 = new GridView();
            GridView1.AllowPaging = false;
            GridView1.DataSource = dt;
            GridView1.DataBind();

            System.Web.HttpContext.Current.Response.Clear();
            System.Web.HttpContext.Current.Response.Buffer = true;
            System.Web.HttpContext.Current.Response.AddHeader("content-disposition",
                "attachment;filename=DataTable.doc");
            System.Web.HttpContext.Current.Response.Charset = "";
            System.Web.HttpContext.Current.Response.ContentType = "application/vnd.ms-word ";
            StringWriter sw = new StringWriter();
            HtmlTextWriter hw = new HtmlTextWriter(sw);
            GridView1.RenderControl(hw);
            System.Web.HttpContext.Current.Response.Output.Write(sw.ToString());
            System.Web.HttpContext.Current.Response.Flush();
            System.Web.HttpContext.Current.Response.End();

            //End of Word Code

            // ************************************************ //

            /*

            string excelFilename = context.Request["filename"];

            if (File.Exists(excelFilename))
                File.Delete(excelFilename);

            CreateExcelFile.CreateExcelDocument(dt, excelFilename, context.Response);*/
        }
コード例 #44
0
        public void ProcessRequest(HttpContext context)
        {
            string file = context.Request.QueryString["file"];
            string[] filename = file.Split('.');
            int len = filename.Length;
            string name= string.Empty;
            for (int i = 0; i < len-1; i++)
            {
                name += filename[i];
                name += ".";
            }
            int id = Convert.ToInt32(context.Request.QueryString["id"]);
            obj.FileId = id;
            obj.UserId = Convert.ToInt32(context.Session["userId"]);
            //Get the data from database into datatable
            string strQuery = "select Name,City,Address,Designation from Excel where fileid= " + id + " ";
            SqlCommand cmd = new SqlCommand(strQuery);
            DataTable dt = GetData(cmd);

            //Create a dummy GridView
            GridView GridView1 = new GridView();
            GridView1.AllowPaging = false;
            GridView1.DataSource = dt;
            GridView1.DataBind();
            obj.Downlaod_File(obj);

            context.Response.ContentType = "application/pdf";
            context.Response.AddHeader("content-disposition", "attachment;filename=" + name + "pdf");
               // context.Response.TransmitFile(filePath);
            context.Response.Cache.SetCacheability(HttpCacheability.NoCache);
            StringWriter sw = new StringWriter();
            HtmlTextWriter hw = new HtmlTextWriter(sw);
            GridView1.RenderControl(hw);
            StringReader sr = new StringReader(sw.ToString());
            Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f);

            HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
            PdfWriter.GetInstance(pdfDoc, context.Response.OutputStream);
            pdfDoc.Open();
            htmlparser.Parse(sr);
            pdfDoc.Close();
            context.Response.Write(pdfDoc);
            context.Response.End();
        }
コード例 #45
0
        public ActionResult ExportData()
        {
            GridView gv = new GridView();
            gv.DataSource = db.tbl_LoginAudit.OrderByDescending(l => l.LoginTime).ToList();
            gv.DataBind();
            Response.ClearContent();
            Response.Buffer = true;
            Response.AddHeader("content-disposition", "attachment; filename=AdminLog-" + DateTime.Now.ToShortDateString() +".xls");
            Response.ContentType = "application/ms-excel";
            Response.Charset = "";
            StringWriter sw = new StringWriter();
            HtmlTextWriter htw = new HtmlTextWriter(sw);
            gv.RenderControl(htw);
            Response.Output.Write(sw.ToString());
            Response.Flush();
            Response.End();

            return RedirectToAction("Index");
        }
コード例 #46
0
        public void ExportContrat()
        {

            var grid = new GridView();
            var inv = BissInventaireEntities.Instance.Contrat.ToList();
            grid.DataSource = inv;
            grid.DataBind();
            Response.ClearContent();
            String DateExp = DateTime.Now.ToString();
            Response.AddHeader("content-disposition", "attachment;filename=InventaireListeContrat_" + DateExp + ".xls");
            Response.ContentType = "text/excel";
            StringWriter sw = new StringWriter();
            HtmlTextWriter htmltexxt = new HtmlTextWriter(sw);
            grid.RenderControl(htmltexxt);
            Response.Write(sw.ToString());
            Response.End();


        }
コード例 #47
0
        protected void btn_word_Click(object sender, ImageClickEventArgs e)
        {
            IGTMAIN.cmdtext = IGTMAIN.cmdtextlp;

            IGTMAIN.GetDataLP();
            Response.Clear();
            Response.AddHeader("content-disposition", "attachment;filename=" + IGTMAIN.filename + ".doc");
            Response.Charset = "";
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            Response.ContentType = "application/vnd.word";
            System.IO.StringWriter             stringWrite = new System.IO.StringWriter();
            System.Web.UI.HtmlTextWriter       htmlWrite   = new System.Web.UI.HtmlTextWriter(stringWrite);
            System.Web.UI.WebControls.GridView dg          = new System.Web.UI.WebControls.GridView();
            dg.Caption    = IGTMAIN.Title;
            dg.DataSource = IGTMAIN.dtlp;
            dg.DataBind();
            dg.RenderControl(htmlWrite);
            Response.Write(stringWrite.ToString());
            Response.End();
        }
コード例 #48
0
ファイル: WebForm1.aspx.cs プロジェクト: 50minutos/MOC-10264
        protected void Button1_Click(object sender, EventArgs e)
        {
            var stringWriter = new StringWriter();
            var htmlWriter = new HtmlTextWriter(stringWriter);

            var gv = new GridView();

            gv.HeaderStyle.ForeColor = Color.Black;
            gv.HeaderStyle.BackColor = Color.AntiqueWhite;
            gv.AlternatingRowStyle.BackColor = Color.GhostWhite;
            gv.RowStyle.BackColor = Color.White;

            CriarDados(gv);

            gv.RenderControl(htmlWriter);

            Session["DADOS"] = stringWriter.ToString();

            Response.Redirect("~/HandlerExcel.ashx");
        }
コード例 #49
0
        public void DownloadClawBackExcel(int acid)
        {
            string           exlFilename         = string.Empty;
            string           sConnectionString   = string.Empty;
            string           spName              = string.Empty;
            string           workSheetName       = string.Empty;
            LoginUserDetails objLoginUserDetails = (LoginUserDetails)InsiderTrading.Common.Common.GetSessionValue((string)ConstEnum.SessionValue.UserDetails);

            sConnectionString = objLoginUserDetails.CompanyDBConnectionString;
            SqlConnection con = new SqlConnection(sConnectionString);
            SqlCommand    cmd = new SqlCommand();

            con.Open();
            DataTable dt = new DataTable();

            spName          = "st_rpt_DownloadClawBackReportExcel";
            exlFilename     = "Claw Back Report.xls";
            workSheetName   = "Claw Back Report";
            cmd             = new SqlCommand(spName, con);
            cmd.CommandType = CommandType.StoredProcedure;
            SqlDataAdapter adp = new SqlDataAdapter(cmd);

            adp.Fill(dt);

            Response.Clear();
            Response.Buffer      = true;
            Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
            Response.Charset     = "";
            Response.AddHeader("content-disposition", "attachment;filename=" + exlFilename + "");
            StringWriter sWriter = new StringWriter();

            System.Web.UI.HtmlTextWriter       hWriter = new System.Web.UI.HtmlTextWriter(sWriter);
            System.Web.UI.WebControls.GridView dtGrid  = new System.Web.UI.WebControls.GridView();
            dtGrid.DataSource = dt;
            dtGrid.DataBind();
            dtGrid.RenderControl(hWriter);
            Response.Write(@"<style> TD { mso-number-format:\@; } </style>");
            Response.Output.Write(sWriter.ToString());
            Response.Flush();
            Response.End();
        }
コード例 #50
0
        public static void ExportToExcel(string Filename, GridView gv, HttpResponse response)
        {
            gv.AllowPaging = false;
            gv.DataBind();

            response.Clear();
            response.AddHeader("content-disposition", "attachment;filename=" + Filename + ".xls");
            response.Charset = "";
            response.Cache.SetCacheability(HttpCacheability.NoCache);
            response.ContentType = "application/vnd.ms-excel";
            foreach (GridViewRow row in gv.Rows)
            {
                PrepareControlForExport(row);
            }
            System.IO.StringWriter stringWrite = new System.IO.StringWriter();
            System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
            gv.RenderControl(htmlWrite);
            response.Write(stringWrite.ToString());
            //response.End();
            HttpContext.Current.ApplicationInstance.CompleteRequest();
        }
コード例 #51
0
 public static void Export(GridView gv, string filename)
 {
     Prepare(gv);
     string attachment = "attachment; filename=" + filename + ".xls";
     HttpContext.Current.Response.ClearContent();
     HttpContext.Current.Response.AddHeader("content-disposition", attachment);
     HttpContext.Current.Response.ContentType = "application/ms-excel";
     HttpContext.Current.Response.Charset = "utf-8";
     HttpContext.Current.Response.Write("<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/></head><body>");
     StringWriter sw = new StringWriter();
     HtmlTextWriter htw = new HtmlTextWriter(sw);
     //HtmlForm frm = new HtmlForm();
     //gv.Parent.Controls.Add(frm);
     //frm.Attributes["runat"] = "server";
     //frm.Controls.Add(gv);
     //frm.RenderControl(htw);
     gv.RenderControl(htw);
     HttpContext.Current.Response.Write(sw.ToString());
     HttpContext.Current.Response.Write("</body></html>");
     HttpContext.Current.Response.End();
 }
コード例 #52
0
ファイル: Location Report.aspx.cs プロジェクト: zyhzx123e/TA
    protected void exportBtn_Click(object sender, EventArgs e)
    {
        try
        {
            int    locationID = int.Parse(locationsList.SelectedValue);
            string month      = MonthsList.SelectedValue;
            string year       = yearList.SelectedValue;

            if (locationsList.SelectedIndex != 0 && yearList.SelectedIndex != 0)
            {
                System.Web.UI.WebControls.GridView reportGrid = new System.Web.UI.WebControls.GridView();
                reportGrid.DataSource = pdfReportData(locationID, month, year);
                reportGrid.DataBind();

                Response.ContentType = "application/pdf";
                Response.AddHeader("content-disposition", "attachment;filename=DataTable.pdf");
                Response.Cache.SetCacheability(HttpCacheability.NoCache);
                StringWriter   sw = new StringWriter();
                HtmlTextWriter hw = new HtmlTextWriter(sw);
                reportGrid.RenderControl(hw);
                StringReader sr         = new StringReader(sw.ToString());
                Document     pdfDoc     = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
                HTMLWorker   htmlparser = new HTMLWorker(pdfDoc);
                PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
                pdfDoc.Open();
                htmlparser.Parse(sr);
                pdfDoc.Close();
                Response.Write(pdfDoc);
                Response.End();
            }
            else
            {
                msg.Text = "Please specify all the required report's details.";
            }
        }
        catch (Exception ex)
        {
            msg.Text = "There was something wrong." + ex.Message;
        }
    }
コード例 #53
0
    public void ToExcel(HttpResponseBase Response, object clientsList, string fileName)
    {
        try
        {
            var grid = new System.Web.UI.WebControls.GridView();
            grid.DataSource = clientsList;
            grid.DataBind();
            Response.ClearContent();
            //var filename = "MatHang_" + DateTime.Now.ToString("yyyyMMdd")+".xls";
            Response.AddHeader("content-disposition", "attachment; filename=" + fileName);
            Response.ContentType = "application/vnd.ms-excel";
            StringWriter   sw  = new StringWriter();
            HtmlTextWriter htw = new HtmlTextWriter(sw);

            grid.RenderControl(htw);
            Response.Write(sw.ToString());
            Response.End();
        }
        catch (Exception ex)
        {
            Helpers.Config.SaveToLog(ex.ToString());
        }
    }
コード例 #54
0
        /// <summary>
        /// 匯出 Excel File
        /// http://www.dotnet-tutorial.com/articles/mvc/export-data-in-excel-file-with-asp-net-mvc
        /// </summary>
        /// <returns></returns>
        public ActionResult ExportToExcel()
        {
            var gv = new System.Web.UI.WebControls.GridView();

            gv.DataSource = repo.Get列表所有客戶資料().ToList();
            gv.DataBind();

            Response.ClearContent();
            Response.Buffer = true;
            Response.AddHeader("content-disposition", "attachment; filename=DemoExcel.xls");
            Response.ContentType = "application/ms-excel";

            Response.Charset = "";
            StringWriter   objStringWriter   = new StringWriter();
            HtmlTextWriter objHtmlTextWriter = new HtmlTextWriter(objStringWriter);

            gv.RenderControl(objHtmlTextWriter);

            Response.Output.Write(objStringWriter.ToString());
            Response.Flush();
            Response.End();

            return(View("Index"));
        }
コード例 #55
0
        public ActionResult ExportToExcel()
        {
            var grid = new System.Web.UI.WebControls.GridView();

            grid.DataSource = ViewDetails();
            grid.DataBind();

            Response.ClearContent();
            Response.Buffer = true;
            Response.AddHeader("content-disposition", "attachment; filename=MyExcelFile.xls");
            Response.ContentType = "application/ms-excel";

            Response.Charset = "";
            StringWriter   sw  = new StringWriter();
            HtmlTextWriter htw = new HtmlTextWriter(sw);

            grid.RenderControl(htw);

            Response.Output.Write(sw.ToString());
            Response.Flush();
            Response.End();

            return(View("Index"));
        }
コード例 #56
0
        protected void btn_excel_Click(object sender, ImageClickEventArgs e)
        {
            IGTMAIN.cmdtext = IGTMAIN.cmdtextlp;

            IGTMAIN.GetDataLP();

            Response.ClearContent();
            Response.AddHeader("content-disposition", "attachment;filename=" + IGTMAIN.filename + ".xls");
            Response.ContentType = "application/ms-excel";
            StringWriter   sw  = new StringWriter();
            HtmlTextWriter htw = new HtmlTextWriter(sw);
            HtmlForm       frm = new HtmlForm();

            System.Web.UI.WebControls.GridView dg = new System.Web.UI.WebControls.GridView();
            dg.Caption = IGTMAIN.Title;


            dg.DataSource = IGTMAIN.dtlp;
            dg.DataBind();

            dg.RenderControl(htw);
            Response.Write(sw.ToString());
            Response.End();
        }
コード例 #57
0
ファイル: Utility.cs プロジェクト: xyAndroid/PhoneServer
        /// <summary>
        /// 将GridView数据导出到Excel表格中。
        /// </summary>
        /// <param name="gvCtrl">要导出数据的GridView控件。</param>
        /// <param name="needToHideColumnIndexes">需要隐藏的GridView的列索引数组</param>
        /// <param name="exportTitle">导出标题</param>
        /// <param name="fileName">导出文件名</param>
        static public void ExportToExcel(System.Web.UI.WebControls.GridView gvCtrl,
                                         int[] needToHideColumnIndexes, string exportTitle, string fileName)
        {
            if (string.IsNullOrEmpty(exportTitle))
            {
                exportTitle = Properties.Resources.ExportTitle;
            }

            if (string.IsNullOrEmpty(fileName))
            {
                fileName = Properties.Resources.ExportFile;
            }

            //  记录GridView原始信息。
            bool isSorting = gvCtrl.AllowSorting;
            int  pageIndex = gvCtrl.PageIndex;
            int  pageSize  = gvCtrl.PageSize;

            //  设置GridView状态信息。
            Dictionary <int, bool> visibleStates = new Dictionary <int, bool>();

            for (int i = 0; i < gvCtrl.Columns.Count; i++)
            {
                DataControlField aCol = gvCtrl.Columns[i];
                visibleStates[i] = aCol.Visible;

                bool bContains = false;
                foreach (int x in needToHideColumnIndexes)
                {
                    if (x == i)
                    {
                        bContains = true;
                        break;
                    }
                }

                aCol.Visible = (needToHideColumnIndexes == null || !bContains);
            }

            //gvCtrl.AllowPaging = false;
            gvCtrl.AllowSorting = false;

            gvCtrl.PageSize  = (gvCtrl.PageSize * gvCtrl.PageCount <= 0 ? 1 : gvCtrl.PageSize * gvCtrl.PageCount);
            gvCtrl.PageIndex = 0;

            //  绑定GridView。
            gvCtrl.DataBind();

            //  处理输出流。
            System.Web.HttpContext context = System.Web.HttpContext.Current;

            context.Response.Clear();

            context.Response.AddHeader("content-disposition", "attachment; filename=" + fileName);
            context.Response.ContentType = "application/vnd.ms-excel";

            context.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
            context.Response.Charset         = "GB2312";

            System.IO.StringWriter       sw  = new System.IO.StringWriter();
            System.Web.UI.HtmlTextWriter htw = new System.Web.UI.HtmlTextWriter(sw);

            gvCtrl.RenderControl(htw);

            context.Response.Write(exportTitle);
            context.Response.Write(sw.ToString());
            context.Response.End();

            //  还原GridView状态信息。
            for (int i = 0; i < gvCtrl.Columns.Count; i++)
            {
                DataControlField aCol = gvCtrl.Columns[i];
                aCol.Visible = visibleStates[i];
            }

            gvCtrl.AllowSorting = isSorting;

            gvCtrl.PageSize  = pageSize;
            gvCtrl.PageIndex = pageIndex;
        }
コード例 #58
0
        public System.Web.Mvc.ActionResult ExportFullDumpReport(string ResponsibleEmail, string ChapterName, string Owner, string RoleName, string UserName, string TAT)
        {
            string    constr = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
            DataTable table  = new DataTable();

            using (SqlConnection con1 = new SqlConnection(constr))
            {
                using (SqlCommand cmd1 = new SqlCommand())
                {
                    cmd1.CommandText = "spIssueDetails";
                    cmd1.CommandType = CommandType.StoredProcedure;
                    cmd1.Parameters.AddWithValue("@Division", ResponsibleEmail);
                    cmd1.Parameters.AddWithValue("@ResponsibleEmail", ResponsibleEmail);
                    cmd1.Parameters.AddWithValue("@ChapterName", ChapterName);
                    cmd1.Parameters.AddWithValue("@Owner", Owner);
                    cmd1.Parameters.AddWithValue("@RoleName", RoleName);
                    cmd1.Parameters.AddWithValue("@UserName", UserName);
                    cmd1.CommandType = CommandType.StoredProcedure;
                    con1.Open();
                    cmd1.Connection = con1;
                    //  da.SelectCommand = cmd1;
                    //da.Fill(dt);
                    using (var da = new SqlDataAdapter(cmd1))
                    {
                        da.Fill(table);
                    }
                    // }

                    for (int c = 0; c < table.Rows.Count - 1; c++)
                    {
                        ListQuery <IssueManagementCommentLog> query = new ListQuery <IssueManagementCommentLog>();
                        query.Parameters = new List <QueryParameter>();
                        string RequestNo            = table.Rows[c]["ID_Request"].ToString();
                        string ChapterNameNew       = table.Rows[c]["ChapterNameFromSystem"].ToString();
                        string PendingWithEmail     = table.Rows[c]["ID_Pending_with_Email"].ToString();
                        string ResponsibleWithEmail = table.Rows[c]["ID_Responsible_Email"].ToString();

                        if (ChapterNameNew == "MyPidilite" || ChapterNameNew == "WSS Service Cell")
                        {
                            query.Parameters.Add(new QueryParameter()
                            {
                                Name = "RequestNo", Value = RequestNo
                            });
                            query.Parameters.Add(new QueryParameter()
                            {
                                Name = "ChapterName", Value = ChapterNameNew
                            });
                            query.Parameters.Add(new QueryParameter()
                            {
                                Name = "ID_Responsible_Email", Value = ResponsibleWithEmail
                            });
                        }
                        else
                        {
                            query.Parameters.Add(new QueryParameter()
                            {
                                Name = "RequestNo", Value = RequestNo
                            });
                            query.Parameters.Add(new QueryParameter()
                            {
                                Name = "ChapterName", Value = ChapterNameNew
                            });
                            query.Parameters.Add(new QueryParameter()
                            {
                                Name = "PendingWithEmail", Value = PendingWithEmail
                            });
                        }

                        var data = commentLogService.GetByQuery(query);
                        if (data.Items.Count > 0)
                        {
                            table.Rows[c]["ID_Comments"] = data.Items[0].ID_Comments.ToString();
                        }
                    }
                }

                DataRow[] DR = null;


                System.Web.UI.WebControls.GridView gd = new System.Web.UI.WebControls.GridView();

                if (ChapterName == "Market_Sudhar" || ChapterName == "Pilworld_WSS_feedback")
                {
                    gd.Columns.Add(new BoundField()
                    {
                        HeaderText = "Issue Details", DataField = "ID_Issue_Detail1"
                    });
                    //gd.Columns.Add(new BoundField() { HeaderText = "Location", DataField = "ID_Location" });
                    gd.Columns.Add(new BoundField()
                    {
                        HeaderText = "Collaborator Name", DataField = "ID_Pending_with_Email"
                    });
                    //gd.Columns.Add(new BoundField() { HeaderText = "PendingSince", DataField = "pendingSince" });
                    gd.Columns.Add(new BoundField()
                    {
                        HeaderText = "Collaborator Comment", DataField = "ID_Comments"
                    });
                    gd.Columns.Add(new BoundField()
                    {
                        HeaderText = "Anchor Comment", DataField = "AnchorSentBackComments"
                    });

                    if (TAT == "Beyond")
                    {
                        DR = table.Select("PendingSince>45");
                    }
                    else if (TAT == "Within")
                    {
                        DR = table.Select("PendingSince<=45");
                    }
                }
                else if (ChapterName == "Dealer Feedback")
                {
                    //gd.Columns.Add(new BoundField() { HeaderText = "Request No.", DataField = "ID_Request" });
                    gd.Columns.Add(new BoundField()
                    {
                        HeaderText = "Issue Details", DataField = "ID_Issue_Detail1"
                    });
                    gd.Columns.Add(new BoundField()
                    {
                        HeaderText = "Collaborator Name", DataField = "ID_Pending_with_Email"
                    });
                    gd.Columns.Add(new BoundField()
                    {
                        HeaderText = "Collaborator Comment", DataField = "ID_Comments"
                    });
                    gd.Columns.Add(new BoundField()
                    {
                        HeaderText = "Anchor Comment", DataField = "AnchorSentBackComments"
                    });

                    //gd.Columns.Add(new BoundField() { HeaderText = "Action With Timeline", DataField = "ID_Comments" });


                    if (TAT == "Beyond")
                    {
                        DR = table.Select("PendingSince>7");
                    }
                    else if (TAT == "Within")
                    {
                        DR = table.Select("PendingSince<=7");
                    }
                }
                else if (ChapterName == "Customer Service Cell")
                {
                    //gd.Columns.Add(new BoundField() { HeaderText = "Request No.", DataField = "ID_Request" });
                    //gd.Columns.Add(new BoundField() { HeaderText = "Issue Details", DataField = "ID_Issue_Detail1" });
                    //gd.Columns.Add(new BoundField() { HeaderText = "PendingWithEmail", DataField = "ID_Pending_with_Email" });
                    //gd.Columns.Add(new BoundField() { HeaderText = "Action With Timeline", DataField = "ID_Comments" });
                    gd.Columns.Add(new BoundField()
                    {
                        HeaderText = "Issue Details", DataField = "ID_Issue_Detail1"
                    });
                    gd.Columns.Add(new BoundField()
                    {
                        HeaderText = "Collaborator Name", DataField = "ID_Pending_with_Email"
                    });
                    gd.Columns.Add(new BoundField()
                    {
                        HeaderText = "Collaborator Comment", DataField = "ID_Comments"
                    });
                    gd.Columns.Add(new BoundField()
                    {
                        HeaderText = "Anchor Comment", DataField = "AnchorSentBackComments"
                    });

                    if (TAT == "Beyond")
                    {
                        DR = table.Select("PendingSince>7");
                    }
                    else if (TAT == "Within")
                    {
                        DR = table.Select("PendingSince<=7");
                    }
                }
                else if (ChapterName == "MyPidilite")
                {
                    gd.Columns.Add(new BoundField()
                    {
                        HeaderText = "Issue Details", DataField = "ID_Issue_Detail1"
                    });
                    //gd.Columns.Add(new BoundField() { HeaderText = "PendingWithEmail", DataField = "ID_Pending_with_Email" });
                    gd.Columns.Add(new BoundField()
                    {
                        HeaderText = "Collaborator Name", DataField = "ID_Responsible_Email"
                    });
                    gd.Columns.Add(new BoundField()
                    {
                        HeaderText = "Latest Comments", DataField = "ID_Comments"
                    });


                    if (TAT == "Beyond")
                    {
                        DR = table.Select("id_TAT_status='Beyond TAT'");
                    }
                    else if (TAT == "Within")
                    {
                        DR = table.Select("id_TAT_status='Within TAT'");
                    }
                }
                else if (ChapterName == "WSS Service Cell")
                {
                    //gd.Columns.Add(new BoundField() { HeaderText = "Request No.", DataField = "ID_Request" });
                    //gd.Columns.Add(new BoundField() { HeaderText = "Issue Details", DataField = "ID_Issue_Detail1" });
                    //gd.Columns.Add(new BoundField() { HeaderText = "Reported By Name", DataField = "ID_Reported_by_name" });
                    //gd.Columns.Add(new BoundField() { HeaderText = "Location", DataField = "ID_Location" });
                    //gd.Columns.Add(new BoundField() { HeaderText = "PendingWithEmail", DataField = "ID_Pending_with_Email" });
                    //gd.Columns.Add(new BoundField() { HeaderText = "ResponsibleWithEmail", DataField = "ID_Responsible_Email" });

                    gd.Columns.Add(new BoundField()
                    {
                        HeaderText = "Issue Details", DataField = "ID_Issue_Detail1"
                    });
                    gd.Columns.Add(new BoundField()
                    {
                        HeaderText = "Collaborator Name", DataField = "ID_Responsible_Email"
                    });
                    gd.Columns.Add(new BoundField()
                    {
                        HeaderText = "Collaborator Comment", DataField = "ID_Comments"
                    });
                    gd.Columns.Add(new BoundField()
                    {
                        HeaderText = "Anchor Comment", DataField = "AnchorSentBackComments"
                    });

                    if (TAT == "Beyond")
                    {
                        DR = table.Select("id_TAT_status='Beyond TAT'");
                    }
                    else if (TAT == "Within")
                    {
                        DR = table.Select("id_TAT_status='Within TAT'");
                    }
                }
                else if (ChapterName == "Risk_Management")
                {
                    //gd.Columns.Add(new BoundField() { HeaderText = "Request No.", DataField = "ID_Request" });
                    //gd.Columns.Add(new BoundField() { HeaderText = "Category", DataField = "ID_Category" });
                    gd.Columns.Add(new BoundField()
                    {
                        HeaderText = "Issue Details", DataField = "ID_Issue_Detail1"
                    });
                    gd.Columns.Add(new BoundField()
                    {
                        HeaderText = "Collaborator Name", DataField = "ID_Pending_with_Email"
                    });
                    gd.Columns.Add(new BoundField()
                    {
                        HeaderText = "Collaborator Comment", DataField = "ID_Comments"
                    });
                    //gd.Columns.Add(new BoundField() { HeaderText = "Target Date", DataField = "ID_Target_Date" });
                    gd.Columns.Add(new BoundField()
                    {
                        HeaderText = "Anchor Comment", DataField = "AnchorSentBackComments"
                    });

                    DR = table.Select("PendingSince>0");
                }
                else if (ChapterName == "BirthdayLunch" || ChapterName == "Sampark" || ChapterName == "Suggestion_at_Facebook" || ChapterName == "SimplifiedSuggestion")
                {
                    gd.Columns.Add(new BoundField()
                    {
                        HeaderText = "Issue Details", DataField = "ID_Issue_Detail1"
                    });
                    //gd.Columns.Add(new BoundField() { HeaderText = "Reported By Name", DataField = "ID_Reported_by_name" });
                    gd.Columns.Add(new BoundField()
                    {
                        HeaderText = "Collaborator Name", DataField = "ID_Pending_with_Email"
                    });
                    gd.Columns.Add(new BoundField()
                    {
                        HeaderText = "Collaborator Comment", DataField = "ID_Comments"
                    });
                    gd.Columns.Add(new BoundField()
                    {
                        HeaderText = "Anchor Comment", DataField = "AnchorSentBackComments"
                    });
                    //gd.Columns.Add(new BoundField() { HeaderText = "PendingSince", DataField = "pendingSince" });

                    DR = table.Select("PendingSince>0");
                }
                DataTable dtFinal = table.Clone();
                foreach (DataRow d in DR)
                {
                    dtFinal.ImportRow(d);
                }
                gd.DataSource          = dtFinal;//table;
                gd.AutoGenerateColumns = false;



                //gd.Columns.Add(new BoundField() { HeaderText = "Request No.", DataField = "ID_Request" });
                //gd.Columns.Add(new BoundField() { HeaderText = "Issue Details", DataField = "ID_Issue_Detail1" });
                //gd.Columns.Add(new BoundField() { HeaderText = "Comments", DataField = "ID_Comments" });
                ////gd.Columns.Add(new BoundField() { HeaderText = "Status", DataField = "ID_status" });
                //gd.Columns.Add(new BoundField() { HeaderText = "Reported By Name", DataField = "ID_Reported_by_name" });
                //gd.Columns.Add(new BoundField() { HeaderText = "Department", DataField = "ID_Dept" });
                //gd.Columns.Add(new BoundField() { HeaderText = "Location", DataField = "ID_Location" });
                //gd.Columns.Add(new BoundField() { HeaderText = "PendingWithEmail", DataField = "ID_Pending_with_Email" });
                //gd.Columns.Add(new BoundField() { HeaderText = "PendingSince", DataField = "pendingSince" });
                //gd.Columns.Add(new BoundField() { HeaderText = "LoggedDate", DataField = "ID_Logged_Date" });
                gd.DataBind();

                var sb = new System.Text.StringBuilder();
                var tw = new System.IO.StringWriter(sb);

                var htw = new System.Web.UI.HtmlTextWriter(tw);
                gd.RenderControl(htw);

                Response.ClearContent();
                Response.Buffer = true;
                Response.AddHeader("content-disposition", "attachment; filename=IssueDetails.xls");
                Response.ContentType = "application/ms-excel";
                Response.Charset     = "";
                Response.Output.Write(sb.ToString());
                Response.Flush();
                Response.End();

                return(RedirectToAction("Full Dump Report"));

                con1.Close();
            }
        }
コード例 #59
0
        public System.Web.Mvc.ActionResult ExportFullDumpReportClose(string ChapterName)
        {
            string    constr = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
            DataTable table  = new DataTable();

            using (SqlConnection con1 = new SqlConnection(constr))
            {
                using (SqlCommand cmd1 = new SqlCommand())
                {
                    cmd1.CommandText = "SpissuedetailsClose";
                    cmd1.CommandType = CommandType.StoredProcedure;
                    cmd1.Parameters.AddWithValue("@ChapterName", ChapterName);
                    cmd1.CommandType = CommandType.StoredProcedure;
                    con1.Open();
                    cmd1.Connection = con1;
                    using (var da = new SqlDataAdapter(cmd1))
                    {
                        da.Fill(table);
                    }

                    //for (int c = 0; c < table.Rows.Count - 1; c++)
                    //{
                    //    ListQuery<IssueManagementCommentLog> query = new ListQuery<IssueManagementCommentLog>();
                    //    query.Parameters = new List<QueryParameter>();
                    //    string RequestNo = table.Rows[c]["ID_Request"].ToString();
                    //    string ChapterNameNew = table.Rows[c]["ChapterNameFromSystem"].ToString();
                    //    string PendingWithEmail = table.Rows[c]["ID_Pending_with_Email"].ToString();

                    //    query.Parameters.Add(new QueryParameter() { Name = "RequestNo", Value = RequestNo });
                    //    query.Parameters.Add(new QueryParameter() { Name = "ChapterName", Value = ChapterNameNew });
                    //    query.Parameters.Add(new QueryParameter() { Name = "PendingWithEmail", Value = PendingWithEmail });

                    //    var data = commentLogService.GetByQuery(query);
                    //    if (data.Items.Count > 0)
                    //    {
                    //        table.Rows[c]["ID_Comments"] = data.Items[0].ID_Comments.ToString();
                    //    }

                    //}
                }

                DataRow[] DR = null;


                System.Web.UI.WebControls.GridView gd = new System.Web.UI.WebControls.GridView();

                if (ChapterName == "Market_Sudhar" || ChapterName == "Pilworld_WSS_feedback")
                {
                    //gd.Columns.Add(new BoundField() { HeaderText = "Department", DataField = "ID_dept" });
                    //gd.Columns.Add(new BoundField() { HeaderText = "Location", DataField = "ID_Location" });
                    //gd.Columns.Add(new BoundField() { HeaderText = "PendingSince", DataField = "pendingSince" });
                    gd.Columns.Add(new BoundField()
                    {
                        HeaderText = "Issue Details", DataField = "ID_Issue_Detail1"
                    });
                    gd.Columns.Add(new BoundField()
                    {
                        HeaderText = "Collaborator Name", DataField = "ID_Pending_with_Email"
                    });
                    gd.Columns.Add(new BoundField()
                    {
                        HeaderText = "Collaborator Last Comments", DataField = "ID_Comments"
                    });
                }
                else if (ChapterName == "Dealer Feedback")
                {
                    //gd.Columns.Add(new BoundField() { HeaderText = "Request No.", DataField = "ID_Request" });
                    //gd.Columns.Add(new BoundField() { HeaderText = "Department", DataField = "ID_dept" });
                    gd.Columns.Add(new BoundField()
                    {
                        HeaderText = "Issue Details", DataField = "ID_Issue_Detail1"
                    });
                    gd.Columns.Add(new BoundField()
                    {
                        HeaderText = "Collaborator Name", DataField = "ID_Pending_with_Email"
                    });
                    gd.Columns.Add(new BoundField()
                    {
                        HeaderText = "Collaborator Last Comments", DataField = "ID_Comments"
                    });
                }
                else if (ChapterName == "Customer Service Cell")
                {
                    //gd.Columns.Add(new BoundField() { HeaderText = "Request No.", DataField = "ID_Request" });
                    //gd.Columns.Add(new BoundField() { HeaderText = "Department", DataField = "ID_dept" });
                    gd.Columns.Add(new BoundField()
                    {
                        HeaderText = "Issue Details", DataField = "ID_Issue_Detail1"
                    });
                    gd.Columns.Add(new BoundField()
                    {
                        HeaderText = "Collaborator Name", DataField = "ID_Pending_with_Email"
                    });
                    gd.Columns.Add(new BoundField()
                    {
                        HeaderText = "Collaborator Last Comments", DataField = "ID_Comments"
                    });
                }
                else if (ChapterName == "MyPidilite")
                {
                    //gd.Columns.Add(new BoundField() { HeaderText = "Department", DataField = "ID_dept" });
                    gd.Columns.Add(new BoundField()
                    {
                        HeaderText = "Issue Details", DataField = "ID_Issue_Detail1"
                    });
                    gd.Columns.Add(new BoundField()
                    {
                        HeaderText = "Collaborator Name", DataField = "ID_Responsible_Email"
                    });
                    gd.Columns.Add(new BoundField()
                    {
                        HeaderText = "Collaborator Last Comments", DataField = "ID_Comments"
                    });
                }
                else if (ChapterName == "WSS Service Cell")
                {
                    //gd.Columns.Add(new BoundField() { HeaderText = "Request No.", DataField = "ID_Request" });
                    //gd.Columns.Add(new BoundField() { HeaderText = "Department", DataField = "ID_dept" });
                    //gd.Columns.Add(new BoundField() { HeaderText = "Reported By Name", DataField = "ID_Reported_by_name" });
                    //gd.Columns.Add(new BoundField() { HeaderText = "Location", DataField = "ID_Location" });
                    gd.Columns.Add(new BoundField()
                    {
                        HeaderText = "Issue Details", DataField = "ID_Issue_Detail1"
                    });
                    gd.Columns.Add(new BoundField()
                    {
                        HeaderText = "Collaborator Name", DataField = "ID_Responsible_Email"
                    });
                    gd.Columns.Add(new BoundField()
                    {
                        HeaderText = "Collaborator Last Comments", DataField = "ID_Comments"
                    });
                }
                else if (ChapterName == "Birthday Lunch")
                {
                    gd.Columns.Add(new BoundField()
                    {
                        HeaderText = "Issue Details", DataField = "ID_Issue_Detail1"
                    });
                    gd.Columns.Add(new BoundField()
                    {
                        HeaderText = "Collaborator Name", DataField = "ID_Responsible_Email"
                    });
                    gd.Columns.Add(new BoundField()
                    {
                        HeaderText = "Collaborator Last Comments", DataField = "ID_Comments"
                    });
                }
                else if (ChapterName == "Simplified Suggestion")
                {
                    gd.Columns.Add(new BoundField()
                    {
                        HeaderText = "Issue Details", DataField = "ID_Issue_Detail1"
                    });
                    gd.Columns.Add(new BoundField()
                    {
                        HeaderText = "Collaborator Name", DataField = "ID_Responsible_Email"
                    });
                    gd.Columns.Add(new BoundField()
                    {
                        HeaderText = "Collaborator Last Comments", DataField = "ID_Comments"
                    });
                }
                else if (ChapterName == "Sampark")
                {
                    gd.Columns.Add(new BoundField()
                    {
                        HeaderText = "Issue Details", DataField = "ID_Issue_Detail1"
                    });
                    gd.Columns.Add(new BoundField()
                    {
                        HeaderText = "Collaborator Name", DataField = "ID_Responsible_Email"
                    });
                    gd.Columns.Add(new BoundField()
                    {
                        HeaderText = "Collaborator Last Comments", DataField = "ID_Comments"
                    });
                }
                else if (ChapterName == "Pidilite Ideas Initiatives")
                {
                    gd.Columns.Add(new BoundField()
                    {
                        HeaderText = "Issue Details", DataField = "ID_Issue_Detail1"
                    });
                    gd.Columns.Add(new BoundField()
                    {
                        HeaderText = "Collaborator Name", DataField = "ID_Responsible_Email"
                    });
                    gd.Columns.Add(new BoundField()
                    {
                        HeaderText = "Collaborator Last Comments", DataField = "ID_Comments"
                    });
                }
                else if (ChapterName == "Risk Management")
                {
                    gd.Columns.Add(new BoundField()
                    {
                        HeaderText = "Issue Details", DataField = "ID_Issue_Detail1"
                    });
                    gd.Columns.Add(new BoundField()
                    {
                        HeaderText = "Collaborator Name", DataField = "ID_Responsible_Email"
                    });
                    gd.Columns.Add(new BoundField()
                    {
                        HeaderText = "Collaborator Last Comments", DataField = "ID_Comments"
                    });
                }
                //DataTable dtFinal = table.Clone();
                //foreach (DataRow d in DR)
                //{
                //    dtFinal.ImportRow(d);
                //}
                var col = gd.Columns.Count;
                gd.DataSource          = table;
                gd.AutoGenerateColumns = false;
                //gd.Columns.Add(new BoundField() { HeaderText = "Request No.", DataField = "ID_Request" });
                //gd.Columns.Add(new BoundField() { HeaderText = "Issue Details", DataField = "ID_Issue_Detail1" });
                //gd.Columns.Add(new BoundField() { HeaderText = "Comments", DataField = "ID_Comments" });
                ////gd.Columns.Add(new BoundField() { HeaderText = "Status", DataField = "ID_status" });
                //gd.Columns.Add(new BoundField() { HeaderText = "Reported By Name", DataField = "ID_Reported_by_name" });
                //gd.Columns.Add(new BoundField() { HeaderText = "Department", DataField = "ID_Dept" });
                //gd.Columns.Add(new BoundField() { HeaderText = "Location", DataField = "ID_Location" });
                //gd.Columns.Add(new BoundField() { HeaderText = "PendingWithEmail", DataField = "ID_Pending_with_Email" });
                //gd.Columns.Add(new BoundField() { HeaderText = "PendingSince", DataField = "pendingSince" });
                //gd.Columns.Add(new BoundField() { HeaderText = "LoggedDate", DataField = "ID_Logged_Date" });
                gd.DataBind();

                var sb = new System.Text.StringBuilder();
                var tw = new System.IO.StringWriter(sb);

                var htw = new System.Web.UI.HtmlTextWriter(tw);
                gd.RenderControl(htw);

                Response.ClearContent();
                Response.Buffer = true;
                Response.AddHeader("content-disposition", "attachment; filename=IssueDetailsClose.xls");
                Response.ContentType = "application/ms-excel";
                Response.Charset     = "";
                Response.Output.Write(sb.ToString());
                Response.Flush();
                Response.End();

                return(RedirectToAction("Full Dump Report"));

                con1.Close();
            }
        }
コード例 #60
0
        protected void btn_Export_Click(object sender, EventArgs e)
        {
            System.Web.UI.WebControls.GridView dg = new System.Web.UI.WebControls.GridView();

/*
 *          BoundField field1 = new BoundField();
 *          field1.DataField = "sale_id";
 *          field1.HeaderText = "销售单号";
 *          dg.Columns.Add(field1);
 *
 *          BoundField field2 = new BoundField();
 *          field2.DataField = "good_id";
 *          field2.HeaderText = "商品编号";
 *          dg.Columns.Add(field2);
 *
 *          BoundField field3 = new BoundField();
 *          field3.DataField = "sale_price";
 *          field3.HeaderText = "销售单价";
 *          dg.Columns.Add(field3);
 *
 *          BoundField field4 = new BoundField();
 *          field4.DataField = "purchase_price";
 *          field4.HeaderText = "采购单价";
 *          dg.Columns.Add(field4);
 *
 *          BoundField field5 = new BoundField();
 *          field5.DataField = "purchase_total";
 *          field5.HeaderText = "成本总价";
 *          dg.Columns.Add(field5);
 *
 *          BoundField field6 = new BoundField();
 *          field6.DataField = "sale_num";
 *          field6.HeaderText = "销售数量";
 *          dg.Columns.Add(field6);
 *
 *
 *          BoundField field7 = new BoundField();
 *          field7.DataField = "sale_total";
 *          field7.HeaderText = "销售总价";
 *          dg.Columns.Add(field7);
 *
 *          BoundField field8 = new BoundField();
 *          field8.DataField = "sale_profit";
 *          field8.HeaderText = "利润";
 *          dg.Columns.Add(field8);
 *
 *          BoundField field9 = new BoundField();
 *          field9.DataField = "sale_datetime";
 *          field9.HeaderText = "销售时间";
 *          dg.Columns.Add(field9);
 *
 *          BoundField field10 = new BoundField();
 *          field10.DataField = "buyer_bh";
 *          field10.HeaderText = "采购商编号";
 *          dg.Columns.Add(field10);
 */
            Sale sale = new Sale();

            sale.Good_Id    = "";
            sale.Year_Month = 0;
            if (this.txt_Name.Text != "")
            {
                sale.Good_Id = this.txt_Name.Text;
            }
            if (this.txt_Yearmonth.Text != "")
            {
                sale.Year_Month = Convert.ToInt32(this.txt_Yearmonth.Text);
            }

            SaleProvider provider = new SaleProvider();
            DataTable    table    = provider.Select1(sale, 0, 0);

            dg.DataSource = table.DefaultView;
            dg.DataBind();

            Response.Clear();
            Response.Buffer      = true;
            Response.ContentType = "application/vnd.ms-excel";
            Response.AddHeader("content-disposition", "attachment;filename=Record.xls");
            Response.Charset     = "";
            this.EnableViewState = false;

            System.IO.StringWriter       sw  = new System.IO.StringWriter();
            System.Web.UI.HtmlTextWriter htw = new System.Web.UI.HtmlTextWriter(sw);

            dg.RenderControl(htw);

            Response.Write(sw.ToString());
            Response.End();
        }