Example E172
Visible to All Users

Reporting for WinForms - Export Options and After Export Actions

This example shows how to specify export options for various export formats, and how to modify export commands to perform additional actions.

Files to Review

Documentation

Example Code

ExportOptionSample/Form1.cs(vb)
C#
using DevExpress.XtraPrinting; using DevExpress.XtraReports.UI; using System; using System.Drawing.Imaging; using System.Globalization; using System.Text; namespace ExportOptionSample { public partial class Form1 : DevExpress.XtraEditors.XtraForm { public Form1() { InitializeComponent(); } private void simpleButton1_Click(object sender, EventArgs e) { var report = new XtraReport1(); report.CreateDocument(); // Obtain the current export options. ExportOptions options = report.PrintingSystem.ExportOptions; // Set Print Preview options. options.PrintPreview.ActionAfterExport = ActionAfterExport.AskUser; options.PrintPreview.DefaultDirectory = "C:\\Temp"; options.PrintPreview.DefaultFileName = "Report"; options.PrintPreview.SaveMode = SaveMode.UsingDefaultPath; options.PrintPreview.ShowOptionsBeforeExport = false; // Set E-mail options. options.Email.RecipientAddress = "someone@somewhere.com"; options.Email.RecipientName = "Someone"; options.Email.Subject = "Test"; options.Email.Body = "Test"; // Set CSV-specific export options. options.Csv.Encoding = Encoding.Unicode; options.Csv.Separator = CultureInfo.CurrentCulture.TextInfo.ListSeparator.ToString(); // Set HTML-specific export options. options.Html.CharacterSet = "UTF-8"; options.Html.RemoveSecondarySymbols = false; options.Html.Title = "Test Title"; // Set Image-specific export options. options.Image.Format = ImageFormat.Jpeg; // Set MHT-specific export options. options.Mht.CharacterSet = "UTF-8"; options.Mht.RemoveSecondarySymbols = false; options.Mht.Title = "Test Title"; // Set PDF-specific export options. options.Pdf.Compressed = true; options.Pdf.ImageQuality = PdfJpegImageQuality.Low; options.Pdf.NeverEmbeddedFonts = "Tahoma;Courier New"; options.Pdf.DocumentOptions.Application = "Test Application"; options.Pdf.DocumentOptions.Author = "Test Team"; options.Pdf.DocumentOptions.Keywords = "Test1, Test2"; options.Pdf.DocumentOptions.Subject = "Test Subject"; options.Pdf.DocumentOptions.Title = "Test Title"; // Set Text-specific export options. options.Text.Encoding = Encoding.Unicode; options.Text.Separator = CultureInfo.CurrentCulture.TextInfo.ListSeparator.ToString(); // Set XLS-specific export options. options.Xls.ShowGridLines = true; options.Xls.SheetName = "Page 1"; options.Xls.TextExportMode = TextExportMode.Value; // Set XLSX-specific export options. options.Xlsx.ShowGridLines = true; options.Xlsx.SheetName = "Page 1"; options.Xlsx.TextExportMode = TextExportMode.Value; report.ShowPreviewDialog(); } private void simpleButton2_Click(object sender, EventArgs e) { var report = new XtraReport1(); var preview = new ReportPrintTool(report); preview.PrintingSystem.AddCommandHandler(new CustomPDFExportCommandHandler()); preview.ShowRibbonPreviewDialog(); } } public class CustomPDFExportCommandHandler : DevExpress.XtraPrinting.ICommandHandler { public virtual void HandleCommand(PrintingSystemCommand command, object[] args, IPrintControl printControl, ref bool handled) { if (!CanHandleCommand(command, printControl)) return; var pdfExportOptions = new PdfExportOptions(); // You can configure your export options. pdfExportOptions.DocumentOptions.Author = "VisualExportTool"; VisualExportTool.ExportFile(pdfExportOptions, printControl.PrintingSystem); // You can add a log entry about the PDF export operation. handled = true; } public virtual bool CanHandleCommand(PrintingSystemCommand command, IPrintControl printControl) { return command == PrintingSystemCommand.ExportPdf; } } }

Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.