Is it possible to conditionally hide (or show) columns when exporting a report to CSV?
We've noticed that our reports are including subtotals as a column with the value repeated for each row in the same group.
I figured I could bind the visibility of the textbox to some value that indicates the rendering type (CSV, or other), but I can't find anything that indicates how the report is being rendered.
I'm using Reports 2017 R2
3 Answers, 1 is accepted
In Telerik Reporting when exporting to CSV, Group Header/Footer sections are rendered before/after each detail section. You could hide (some of) this information by modifying programatically the report definition based on the rendering type before processing the report. Then you can programmatically export the modified version of the originally previewed report using Telerik Reporting API.
Here is sample code how the report definition could be modified, and then the report being exported to CSV file using ReportProcessor RenderReport method.
Note that the class CsvExporter should be instantiated and its public method ToCsv() called/attached where appropriate (for example to button click event).
Note also that you can exclude static text from the CSV output by setting NoStaticText to True in the CSV device information. The device information could be provided programmatically, or in <Telerik.Reporting> configuration section.
Thanks for the reply Todor.
I'd have to adapt this approach to be more generic to my situation as we have a number of reports where we may want to hide data from group footers.
Do you know if this can be hooked into the built-in export feature on the report viewer? (I'm working in a web environment by the way)
I don't think that the provided approach can be hooked to the reportviewer, since in each report the report definition and the data you would like to hide would be generally different.
On the other hand, the most of the code in the CsvExporter class could be reused as it doesn't depend on the exact report definition. An abstract class could be created for this purpose.
Note that the type of the report (
)could be provided via constructor parameter.
The SetReportProperty method hides/changes particular report item(s) and could be an abstract method to be implemented by each ancestor of the abstract CsvExporter.
Based on particular report definitions it might be possible to generalize further.
Let us know if you need more assistance.