Current filter:
                                You should refresh the page.
                                  • Hello,

                                    Is there an easy way to hide the header (Document title) and the footer (Date and page) when exporting a report to CSV ?

                                    I export all my reports both in pdf and csv. In pdf I want the header and footer, but not in csv.

                                    I thought create a property in the Report.Designer.cs to dynamically set the "Visible" property of the header/footer elements to false, but maybe is there a more convenient way ?

                                    Thanks for help.

                                    Best regards,


                                2 Solutions

                                Creation Date Importance Sort by

                                Thanks for your answer @Yaroslav

                                Your solution is a very complete one. In my case, I don't use the preview window.
                                When I click on the "print" button in my application, I just load the report template and export it :

                                using (MyReport report = new MyReport()) { report.DataSource = MySource; report.ExportToPdf(filepath); } ProcessLaunchHelper.StartProcess(filepath);

                                Then the user can print the document using its pdf viewer.

                                So in my case, I think the most straightforward solution, is to simply add a property in "MyReport.Designer.cs" file, like :

                                public bool IsPdf { set { FooterDate.CanPublish = value; FooterPage.CanPublish = value; FooterTitle.CanPublish = value; } }

                                and then, create my reports with :using (MyReport report = new MyReport())

                                { report.DataSource = MySource; report.IsPdf = true; report.ExportToPdf(filepath); report.IsPdf = false; report.ExportToCsv(filepathcsv); } ProcessLaunchHelper.StartProcess(filepath); ProcessLaunchHelper.StartProcess(filepathcsv);

                                What do you think about this ? Do you see something wrong in my approach ?


                                • Yaroslav (DevExpress Support) 10.01.2019

                                  You're welcome, Damien!
                                  >>Do you see something wrong in my approach?
                                  If you're not going to use any UI components, this approach looks totally find to me. Still, I'd recommend that you create the produced document manually after each export call to be sure that your changes are applied correctly:

                                  report.ExportToPdf(filepath); report.IsPdf = false; report.CreateDocument(false); report.ExportToCsv(filepathcsv);


                                • Damien 10.01.2019

                                  Thanks a lot :).

                                Hi Damien,
                                >> dynamically set the "Visible" property of the header/footer elements to false, but maybe is there a more convenient way ?
                                There is another property that is specifically used to control the visibility of report elements during export:  XRControl.CanPublish. However, there are no separate "CanPublishToPdf" and "CanPublishToCsv" properties. For this reason, to conditionally manage the header visibility, it is necessary to override the "Export" routine as explained here: How to: Execute and Modify Commands in a Print Preview.  To leave other export formats and the actual print preview intact, create a separate document copy with the correct document layout (e.g., the one where bands/controls are visible). For your reference, I've attached skeleton registration of a custom print/export handler that produces a different document (not the one that you see in the DocumentViewer). In this particular implementation, I'm adding a page info label to all exported documents, but the actual approach can be modified to any degree.
                                Let me know if it helps.