Exemple #1
0
        private static DS2XL _xportToolsDemo = null; //Excel xPorter needs this

        /// <summary>
        /// Export data from source DataSet to browser's response.
        /// </summary>
        /// <param name="datasetToExport">Source DataSet to export data from.</param>
        /// <param name="tablesToExport">List of DataTables inside of DataSet to export data from.</param>
        /// <param name="outputFormat">Output export format.</param>
        /// <param name="exportHeaders">Specifies if we need to export column names.</param>
        /// <param name="exportIntoStream">Specifies if we want to export data into some stream first.</param>
        /// <param name="xportToolsDemo">Exporter class instance.</param>
        /// <remarks></remarks>
        private static void ExportDataSetIntoResponse(DataSet datasetToExport, ExportTable[] tablesToExport,
                                                      xpOutputFormat outputFormat, bool exportHeaders, bool exportIntoStream, DS2XL xportToolsDemo, string strFileName)
        {
            //string tempExportFileName;
            //System.IO.FileInfo outputFile = null;
            //MemoryStream exportStream = null;

            /*
             * //Generate temporary file name.
             * tempExportFileName = xPortDemoHelper.GenerateTempFileName(outputFormat);
             *
             * if (outputFormat == xpOutputFormat.HTML)
             * {
             *  Response.ContentType = @"text/html";
             * }
             * else
             * {
             *  Response.ContentType = @"application/vnd.ms-excel";
             * }
             *
             * Response.AddHeader("Content-Disposition", "attachment; filename=" + tempExportFileName);
             */

            //If you need to export data from all DataTables then use overloaded Export/ExportToStream
            //method that does not require tablesToExport parameter. For example,
            //xportTools.Export(products, "Products", outputFormat, True, chkHeaders.Checked)

            /*
             * if (exportIntoStream)
             * {
             *
             *  //For the demo purposes we export into memory stream, but it could be any type of stream.
             *  //When Export method executed, make sure that DataTable's TableName property is not blank
             *  //and set to any valid DataTable name. If DataTable does not have name, 'Incorrect table name'
             *  //exception will be thrown
             *  exportStream = (MemoryStream)xportToolsDemo.ExportToStream(datasetToExport,
             *      tablesToExport, outputFormat, exportHeaders);
             *
             *  //Do something with stream here. For the demo purposes we store stream content into the response output
             *  Response.OutputStream.Write(exportStream.ToArray(), 0, (int)exportStream.Length);
             *  exportStream.Close();
             *  exportStream = null;
             * }
             * else
             * {
             */
            //Export data into temporary file
            xportToolsDemo.Export(datasetToExport, tablesToExport, strFileName, outputFormat, true, exportHeaders);
            //Output file into client's response
            //outputFile = new System.IO.FileInfo(strFileName);

            /*
             *  if (outputFile.Exists && Response.IsClientConnected)
             *  {
             *      Response.WriteFile(tempExportFileName);
             *  }
             */
            //outputFile = null;
            //}

            //Response.Flush();
            //We need to close response to make sure that generated HTML markup from our
            //aspx page does not attach to output Excel file.
            //Response.Close();
        }
Exemple #2
0
        /// <summary>
        /// Export data from source DataSet to browser's response.
        /// </summary>
        /// <param name="datasetToExport">Source DataSet to export data from.</param>
        /// <param name="tablesToExport">List of DataTables inside of DataSet to export data from.</param>
        /// <param name="outputFormat">Output export format.</param>
        /// <param name="exportHeaders">Specifies if we need to export column names.</param>
        /// <param name="exportIntoStream">Specifies if we want to export data into some stream first.</param>
        /// <param name="xportToolsDemo">Exporter class instance.</param>
        /// <remarks></remarks>
        private static void ExportDataSetIntoResponse(DataSet datasetToExport, ExportTable[] tablesToExport,
            xpOutputFormat outputFormat, bool exportHeaders, bool exportIntoStream, DS2XL xportToolsDemo, string strFileName)
        {
            //string tempExportFileName;
            //System.IO.FileInfo outputFile = null;
            //MemoryStream exportStream = null;

            /*
            //Generate temporary file name.
            tempExportFileName = xPortDemoHelper.GenerateTempFileName(outputFormat);

            if (outputFormat == xpOutputFormat.HTML)
            {
                Response.ContentType = @"text/html";
            }
            else
            {
                Response.ContentType = @"application/vnd.ms-excel";
            }

            Response.AddHeader("Content-Disposition", "attachment; filename=" + tempExportFileName);
            */

            //If you need to export data from all DataTables then use overloaded Export/ExportToStream
            //method that does not require tablesToExport parameter. For example,
            //xportTools.Export(products, "Products", outputFormat, True, chkHeaders.Checked)

            /*
            if (exportIntoStream)
            {

                //For the demo purposes we export into memory stream, but it could be any type of stream.
                //When Export method executed, make sure that DataTable's TableName property is not blank
                //and set to any valid DataTable name. If DataTable does not have name, 'Incorrect table name'
                //exception will be thrown
                exportStream = (MemoryStream)xportToolsDemo.ExportToStream(datasetToExport,
                    tablesToExport, outputFormat, exportHeaders);

                //Do something with stream here. For the demo purposes we store stream content into the response output
                Response.OutputStream.Write(exportStream.ToArray(), 0, (int)exportStream.Length);
                exportStream.Close();
                exportStream = null;
            }
            else
            {
            */
                //Export data into temporary file
            xportToolsDemo.Export(datasetToExport, tablesToExport, strFileName, outputFormat, true, exportHeaders);
                //Output file into client's response
            //outputFile = new System.IO.FileInfo(strFileName);
            /*
                if (outputFile.Exists && Response.IsClientConnected)
                {
                    Response.WriteFile(tempExportFileName);
                }
            */
                //outputFile = null;
            //}

            //Response.Flush();
            //We need to close response to make sure that generated HTML markup from our
            //aspx page does not attach to output Excel file.
            //Response.Close();
        }