예제 #1
0
        public void ExportToFileExcel()
        {
            Response.Clear();

            var query = eqService.GetQuery();

            if (!query.IsEmpty)
            {
                var sql = eqService.BuildQuery(query);
                eqService.Paging.Enabled = false;
                DataSet dataset = eqService.GetDataSetBySql(sql);
                if (dataset != null)
                {
                    Response.ContentType = "application/vnd.ms-excel";
                    Response.AddHeader("Content-Disposition",
                                       string.Format("attachment; filename=\"{0}\"", HttpUtility.UrlEncode("report.xls")));
                    DbExport.ExportToExcelHtml(dataset, Response.Output, ExcelFormats.Default);
                }
                else
                {
                    ErrorResponse("Empty dataset");
                }
            }
            else
            {
                ErrorResponse("Empty query");
            }
        }
    protected void ExportResultToExcel(string fileName)
    {
        ResultDS.SelectCommand = SqlTextBox.Text;
        DataView view = (DataView)ResultDS.Select(DataSourceSelectArguments.Empty);

        if (view == null)
        {
            return;
        }
        this.EnableViewState = false;
        Response.Clear();
        Response.ContentType = "application/vnd.ms-excel";
        Response.AddHeader("Content-Disposition",
                           string.Format("attachment; filename=\"{0}\"", HttpUtility.UrlEncodeUnicode(fileName)));
        DbExport.ExportToExcelHtml(view.Table, Response.Output, ExcelFormats.Default);
        Response.End();
    }
예제 #3
0
        /// <summary>
        /// Writes information to Excel.Html file.
        /// </summary>
        /// <returns></returns>
        private void ExportToFileExcel(string sql)
        {
            HttpContext.Response.Clear();

            if (!string.IsNullOrEmpty(sql))
            {
                using (var connection = eqService.ConnectionResolver()){
                    connection.Open();
                    var command = connection.CreateCommand();

                    command.CommandText = sql;
                    command.CommandType = CommandType.Text;

                    var dataset = command.ExecuteReader();

                    if (dataset != null)
                    {
                        HttpContext.Response.ContentType = "application/vnd.ms-excel";
                        HttpContext.Response.Headers.Add("Content-Disposition",
                                                         string.Format("attachment; filename=\"{0}\"", UrlEncoder.Default.Encode("report.xls")));
                        StreamWriter dataStream = new StreamWriter(HttpContext.Response.Body);
                        DbExport.ExportToExcelHtml(dataset, dataStream, HtmlFormats.Default);
                    }
                    else
                    {
                        ErrorResponse("Empty dataset");
                    }

                    eqService.ConnectionResolver().Close();
                }
            }
            else
            {
                ErrorResponse("Empty query");
            }
        }