Пример #1
0
        private static CrystalExportFormat GetExportFormat(string fileName)
        {
            CrystalExportFormat result = CrystalExportFormat.RichText;

            string extension = Helpers.FileExtension(fileName).ToUpper(CultureInfo.CurrentCulture);

            switch (extension)
            {
            case "DOC":
                result = CrystalExportFormat.Word;
                break;

            case "XLS":
                result = CrystalExportFormat.Excel;
                break;

            case "RTF":
                result = CrystalExportFormat.RichText;
                break;

            case "PDF":
                result = CrystalExportFormat.PortableDocFormat;
                break;

            default:
                throw new CrystalHelperException(string.Format(CultureInfo.CurrentUICulture, "Unsupported export format for file '{0}'.", fileName));
            }
            return(result);
        }
Пример #2
0
        /// <summary>
        /// Exports the report to the specified HttpResponse and prompts the user for a file name. The default
        /// name is the specified file name,
        /// </summary>
        /// <param name="response">The response object to export the report to.</param>
        /// <param name="exportFormat">The export format.</param>
        /// <param name="asAttachment">If the asAttachment Boolean variable is set to True, a File Download dialog box appears. If the asAttachment Boolean variable is set to False, the exported report opens in the browser window.</param>
        /// <param name="attachmentName">When you choose to save the file, the file name is set to the attachmentName string variable. If you do not specify the attachmentName variable, then the default file name is "Untitled," with the specified file extension. The file name can be changed in the Save As dialog box.</param>
        public void Export(HttpResponse response, CrystalExportFormat exportFormat, bool asAttachment, string attachmentName)
        {
            if (response == null)
            {
                throw new ArgumentNullException("response");
            }
            if (attachmentName == null)
            {
                throw new ArgumentNullException("asAttachment");
            }

            bool openedHere = false;

            try
            {
                if (!_reportIsOpen)
                {
                    this.Open();
                    openedHere = true;
                }

                _reportDocument.ExportToHttpResponse(GetExportType(exportFormat), response, asAttachment, attachmentName);
            }
            finally
            {
                if (openedHere)
                {
                    this.Close();
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Get the Crystal Export format using the CrystalExportFormat export format definitions
        /// </summary>
        /// <param name="exportFormat"><see cref="CrystalExportFormat"/> export type</param>
        /// <returns>Crystal Reports <see cref="ExportFormatType"/> type</returns>
        private static ExportFormatType GetExportType(CrystalExportFormat exportFormat)
        {
            ExportFormatType result = ExportFormatType.RichText;

            switch (exportFormat)
            {
            case CrystalExportFormat.Word:
                result = ExportFormatType.WordForWindows;
                break;

            case CrystalExportFormat.Excel:
                result = ExportFormatType.Excel;
                break;

            case CrystalExportFormat.RichText:
                result = ExportFormatType.RichText;
                break;

            case CrystalExportFormat.PortableDocFormat:
                result = ExportFormatType.PortableDocFormat;
                break;

            default:
                throw new CrystalHelperException(string.Format(CultureInfo.CurrentUICulture, "Unsupported export format '{0}'.", exportFormat.ToString()));
            }
            return(result);
        }
Пример #4
0
        /// <summary>
        /// Export the report to a file using the specified format.
        /// </summary>
        /// <param name="fileName">Name of the export file.</param>
        /// <param name="exportFormat">CrystalExportFormat.</param>
        /// <remarks>
        /// The following document types are supported:
        /// <list type="bullet">
        /// <item><description>Word (*.doc).</description></item>
        /// <item><description>Excel (*.xls).</description></item>
        /// <item><description>Rich text (*.rtf).</description></item>
        /// <item><description>Portable Doc Format (*.pdf)</description></item>
        /// </list><br/>
        /// <p>
        /// This method will throw an exception when the Open() method is not yet called on this object.
        /// </p>
        /// </remarks>
        public void Export(string fileName, CrystalExportFormat exportFormat)
        {
            bool openedHere = false;

            if (!_reportIsOpen)
            {
                this.Open();
                openedHere = true;
            }

            _reportDocument.ExportToDisk(GetExportType(exportFormat), fileName);

            if (openedHere)
            {
                this.Close();
            }
        }
Пример #5
0
 /// <summary>
 /// Exports the report to the specified HttpResponse.
 /// </summary>
 /// <param name="response">The response object to export the report to.</param>
 /// <param name="exportFormat">The export format.</param>
 public void Export(HttpResponse response, CrystalExportFormat exportFormat)
 {
     this.Export(response, exportFormat, false, "");
 }
        /// <summary>
        /// Get the Crystal Export format using the CrystalExportFormat export format definitions
        /// </summary>
        /// <param name="exportFormat"><see cref="CrystalExportFormat"/> export type</param>
        /// <returns>Crystal Reports <see cref="ExportFormatType"/> type</returns>
        private static ExportFormatType GetExportType(CrystalExportFormat exportFormat)
        {
            ExportFormatType result = ExportFormatType.RichText;

            switch (exportFormat)
            {
                case CrystalExportFormat.Word:
                    result = ExportFormatType.WordForWindows;
                    break;
                case CrystalExportFormat.Excel:
                    result = ExportFormatType.Excel;
                    break;
                case CrystalExportFormat.RichText:
                    result = ExportFormatType.RichText;
                    break;
                case CrystalExportFormat.PortableDocFormat:
                    result = ExportFormatType.PortableDocFormat;
                    break;
                default:
                    throw new CrystalHelperException(string.Format(CultureInfo.CurrentUICulture, "Unsupported export format '{0}'.", exportFormat.ToString()));
            }
            return result;
        }
        /// <summary>
        /// Exports the report to the specified HttpResponse and prompts the user for a file name. The default 
        /// name is the specified file name, 
        /// </summary>
        /// <param name="response">The response object to export the report to.</param>
        /// <param name="exportFormat">The export format.</param>
        /// <param name="asAttachment">If the asAttachment Boolean variable is set to True, a File Download dialog box appears. If the asAttachment Boolean variable is set to False, the exported report opens in the browser window.</param>
        /// <param name="attachmentName">When you choose to save the file, the file name is set to the attachmentName string variable. If you do not specify the attachmentName variable, then the default file name is "Untitled," with the specified file extension. The file name can be changed in the Save As dialog box.</param>
        public void Export(HttpResponse response, CrystalExportFormat exportFormat, bool asAttachment, string attachmentName)
        {
            if (response == null) throw new ArgumentNullException("response");
            if (attachmentName == null) throw new ArgumentNullException("asAttachment");

            bool openedHere = false;

            try
            {
                if (!_reportIsOpen)
                {
                    this.Open();
                    openedHere = true;
                }

                _reportDocument.ExportToHttpResponse(GetExportType(exportFormat), response, asAttachment, attachmentName);
            }
            finally
            {
                if (openedHere)
                {
                    this.Close();
                }
            }
        }
 /// <summary>
 /// Exports the report to the specified HttpResponse.
 /// </summary>
 /// <param name="response">The response object to export the report to.</param>
 /// <param name="exportFormat">The export format.</param>
 public void Export(HttpResponse response, CrystalExportFormat exportFormat)
 {
     this.Export(response, exportFormat, false, "");
 }
        /// <summary>
        /// Export the report to a file using the specified format. 
        /// </summary>
        /// <param name="fileName">Name of the export file.</param>
        /// <param name="exportFormat">CrystalExportFormat.</param>
        /// <remarks>
        /// The following document types are supported:
        /// <list type="bullet">
        /// <item><description>Word (*.doc).</description></item>
        /// <item><description>Excel (*.xls).</description></item>
        /// <item><description>Rich text (*.rtf).</description></item>
        /// <item><description>Portable Doc Format (*.pdf)</description></item>
        /// </list><br/>
        /// <p>
        /// This method will throw an exception when the Open() method is not yet called on this object.
        /// </p>
        /// </remarks>
        public void Export(string fileName, CrystalExportFormat exportFormat)
        {
            bool openedHere = false;

            if (!_reportIsOpen)
            {
                this.Open();
                openedHere = true;
            }

            _reportDocument.ExportToDisk(GetExportType(exportFormat), fileName);

            if (openedHere)
            {
                this.Close();
            }
        }