Esempio n. 1
0
        /// <summary>
        /// Exports the datagrid to an Word file with the name of the datasheet provided by the passed in parameter
        /// </summary>
        /// <param name="reportName">Name of the datasheet.
        /// </param>
        public virtual void ExportWord(string reportName)
        {
            MyDataGrid.AllowPaging = false;
            //MyDataGrid.AllowCustomPaging = false;
            //MyDataGrid.DataBind();
            ClearChildControls(MyDataGrid);
            AddSpaceControls(MyDataGrid);
            MyDataGrid.EnableViewState = false;
            //Gets rid of the viewstate of the control. The viewstate may make an excel file unreadable.

            CurrentPage.Response.Clear();
            CurrentPage.Response.Buffer = true;

            //This will make the browser interpret the output as an Excel file
            //CurrentPage.Response.AddHeader( "Content-Disposition", "filename="+reportName);
            CurrentPage.Response.AddHeader("Content-Disposition", "attachment; filename=export.doc");
            CurrentPage.Response.ContentType = "application/vnd.ms-word";


            //Prepares the html and write it into a StringWriter
            StringWriter   stringWriter = new StringWriter();
            HtmlTextWriter htmlWriter   = new HtmlTextWriter(stringWriter);

            FrontDecorator(htmlWriter);
            MyDataGrid.RenderControl(htmlWriter);
            RearDecorator(htmlWriter);

            //Write the content to the web browser
            CurrentPage.Response.Write(stringWriter.ToString());
            CurrentPage.Response.End();
        }
Esempio n. 2
0
        /// <summary>
        /// Exports the datagrid to an Excel file with the name of the datasheet provided by the passed in parameter
        /// </summary>
        /// <param name="reportName">Name of the datasheet.
        /// </param>
        public virtual void Export(string reportName)
        {
            if (MyDataGrid != null)
            {
                ClearChildControls(MyDataGrid);
                MyDataGrid.EnableViewState = false;                //Gets rid of the viewstate of the control. The viewstate may make an excel file unreadable.
            }
//            else if (MyRadGrid != null)
//            {
//                ClearChildControls(MyRadGrid);
//                MyRadGrid.EnableViewState = false;//Gets rid of the viewstate of the control. The viewstate may make an excel file unreadable.
//            }
            else if (MyHierarGrid != null)
            {
                ClearChildControls(MyHierarGrid);
                MyHierarGrid.EnableViewState     = false;
                MyHierarGrid.AutoGenerateColumns = true;
            }

            CurrentPage.Response.Clear();

            CurrentPage.Response.Buffer = true;

            //This will make the browser interpret the output as an Excel file
            CurrentPage.Response.AddHeader("Content-Disposition", "filename=" + reportName);
            CurrentPage.Response.ContentType     = "application/vnd.ms-excel";
            CurrentPage.Response.Charset         = "UTF-8";
            CurrentPage.Response.ContentEncoding = System.Text.Encoding.Default;


            CurrentPage.SmartNavigation = true;


            //Prepares the html and write it into a StringWriter
            StringWriter   stringWriter = new StringWriter();
            HtmlTextWriter htmlWriter   = new HtmlTextWriter(stringWriter);

            FrontDecorator(htmlWriter);

            if (MyDataGrid != null)
            {
                MyDataGrid.RenderControl(htmlWriter);
            }
            //            else if (MyRadGrid != null)
            //            {
            //                MyRadGrid.RenderControl(htmlWriter);
            //            }
            else if (MyHierarGrid != null)
            {
                MyHierarGrid.RenderControl(htmlWriter);
            }

            RearDecorator(htmlWriter);


            //Write the content to the web browser
            CurrentPage.Response.Write(stringWriter.ToString());
            CurrentPage.Response.End();
        }
Esempio n. 3
0
        /// <summary>
        /// Exports the datagrid to an Excel file with the name of the datasheet provided by the passed in parameter
        /// Exports all field visiable = true/false
        /// </summary>
        /// <param name="reportName">Name of the datasheet.
        /// </param>
        public void ExportAllField(string reportName)
        {
            MyDataGrid.AllowPaging = false;
            //MyDataGrid.AllowCustomPaging = false;
            //MyDataGrid.DataBind();
            ClearChildControls(MyDataGrid);
            AddSpaceControls(MyDataGrid);
            MyDataGrid.EnableViewState = false;
            //Gets rid of the viewstate of the control. The viewstate may make an excel file unreadable.

            CurrentPage.Response.Clear();
            CurrentPage.Response.Buffer = true;

            //This will make the browser interpret the output as an Excel file
            //CurrentPage.Response.AddHeader( "Content-Disposition", "filename="+reportName);
            CurrentPage.Response.AddHeader("Content-Disposition", "attachment; filename=\"" + reportName + ".xls\"");
            CurrentPage.Response.ContentType = "application/vnd.ms-excel";

            //Format
            //header
            MyDataGrid.HeaderStyle.Font.Bold = true;
            MyDataGrid.HeaderStyle.ForeColor = System.Drawing.Color.White;
            MyDataGrid.HeaderStyle.BackColor = System.Drawing.Color.DarkGreen;
            MyDataGrid.HeaderStyle.Height    = 26;

            //Prepares the html and write it into a StringWriter
            StringWriter   stringWriter = new StringWriter();
            HtmlTextWriter htmlWriter   = new HtmlTextWriter(stringWriter);

            FrontDecorator(htmlWriter);

            foreach (DataGridColumn column in MyDataGrid.Columns)
            {
                column.Visible = true;
            }

            MyDataGrid.RenderControl(htmlWriter);
            RearDecorator(htmlWriter);

            //Write the content to the web browser
            CurrentPage.Response.Write(stringWriter.ToString());
            CurrentPage.Response.End();
        }