Exemplo n.º 1
0
    private void ExportDataGrid(string FileType, string FileName) //从DataGrid导出
    {
        Response.Charset = "GB2312";

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



        Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, Encoding.UTF8).ToString());

        Response.ContentType = FileType;

        this.EnableViewState = false;

        StringWriter tw = new StringWriter();

        HtmlTextWriter hw = new HtmlTextWriter(tw);

        GridView11.RenderControl(hw);
        GridView2.RenderControl(hw);
        GridView3.RenderControl(hw);
        GridView4.RenderControl(hw);
        GridView5.RenderControl(hw);
        Response.Write(tw.ToString());

        Response.End();
    }
Exemplo n.º 2
0
        protected void btnDownloadExcelDQIBE4BVNReport_Click(object sender, EventArgs e)
        {
            hidTAB.Value = "#tab3";
            Response.Clear();
            Response.Buffer = true;
            Response.AddHeader("content-disposition", "attachment;filename=DQIBE4BVNReportExport.xls");
            Response.Charset     = "";
            Response.ContentType = "application/vnd.ms-excel";
            using (StringWriter sw = new StringWriter())
            {
                HtmlTextWriter hw = new HtmlTextWriter(sw);

                //To Export all pages
                GridView5.AllowPaging = false;
                DQIBE4BVNPageDataBind();//.BindGrid();

                GridView5.HeaderRow.BackColor = Color.White;
                foreach (TableCell cell in GridView5.HeaderRow.Cells)
                {
                    cell.BackColor = GridView5.HeaderStyle.BackColor;
                }
                foreach (GridViewRow row in GridView5.Rows)
                {
                    row.BackColor = Color.White;
                    foreach (TableCell cell in row.Cells)
                    {
                        if (row.RowIndex % 2 == 0)
                        {
                            cell.BackColor = GridView5.AlternatingRowStyle.BackColor;
                        }
                        else
                        {
                            cell.BackColor = GridView5.RowStyle.BackColor;
                        }
                        cell.CssClass = "textmode";
                    }
                }

                GridView5.RenderControl(hw);

                //style to format numbers to string
                string style = @"<style> .textmode { } </style>";
                Response.Write(style);
                Response.Output.Write(sw.ToString());
                Response.Flush();
                Response.End();
            }
        }
Exemplo n.º 3
0
        private void Export_OE(string FileType, string FileName)
        {
            Response.Charset         = "GB2312";                  //避免文件名为乱码
            Response.ContentEncoding = System.Text.Encoding.UTF8; //不知道干啥的,修改这行UTF8到7就出现乱码,最好别加了。
            Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, Encoding.UTF8).ToString());
            Response.ContentType = FileType;
            this.EnableViewState = false;
            StringWriter   tw1 = new StringWriter();      //实例化StringWriter;
            HtmlTextWriter hw1 = new HtmlTextWriter(tw1); //实例化HtmlTextWriter;

            //GridView1.Columns[7].Visible = false; //**!!!!**将第7列,也就是按钮列隐藏,否则无法导出来;
            GridView4.RenderControl(hw1);
            GridView5.RenderControl(hw1);
            Response.Write(tw1.ToString());
            Response.End();
        }
Exemplo n.º 4
0
    protected void btn4_Click(object sender, EventArgs e)
    {
        // Clear all content output from the buffer stream
        Response.ClearContent();
        // Specify the default file name using "content-disposition" RESPONSE header
        Response.AppendHeader("content-disposition", "attachment; filename=homework.xls");
        // Set excel as the HTTP MIME type
        Response.ContentType = "application/excel";
        // Create an instance of stringWriter for writing information to a string
        System.IO.StringWriter stringWriter4 = new System.IO.StringWriter();
        // Create an instance of HtmlTextWriter class for writing markup
        // characters and text to an ASP.NET server control output stream
        HtmlTextWriter htw4 = new HtmlTextWriter(stringWriter4);

        GridView5.RenderControl(htw4);
        Response.Write(stringWriter4.ToString());
        Response.End();
    }
        public void ExcelExportSpecimenPending()
        {
            try
            {
                Response.Clear();
                Response.AddHeader("content-disposition", "attachment;filename=Specimen Pending Report (" + DateTime.Today.ToString("dd-MM-yyyy") + ").xls");
                Response.Charset = "";

                Response.ContentType = "application/vnd.xls";
                System.IO.StringWriter       stringWrite = new System.IO.StringWriter();
                System.Web.UI.HtmlTextWriter htmlWrite   =
                    new HtmlTextWriter(stringWrite);
                GridView5.AllowPaging  = false;
                GridView5.CaptionAlign = TableCaptionAlign.Top;
                SpecimenPendingSample();
                for (int i = 0; i < GridView5.HeaderRow.Cells.Count; i++)
                {
                    GridView5.HeaderRow.Cells[i].Style.Add("font-size", "16px");
                    GridView5.HeaderRow.Cells[i].Style.Add("height", "80px");
                    GridView5.HeaderRow.Cells[i].Style.Add("background-color", "#00B894");
                    GridView5.HeaderRow.Cells[i].Style.Add("Color", "white");
                }
                //// Footer Style:
                //GridView5.Rows[GridView5.Rows.Count - 1].Style.Add("font-size", "15px");
                //GridView5.Rows[GridView5.Rows.Count - 1].Font.Bold = true;

                GridView5.RenderControl(htmlWrite);

                Response.Write(stringWrite.ToString());
                Response.End();
            }
            catch (Exception ex)
            {
                Response.Write("<script type=\"text/javascript\">alert(" + ex.Message + ")</script>");
            }
        }