Reputation: 115
Tell me please, how can I export a report (rdlc) from ReportViewer (v.11) to .xls file?
This version of viewer could export to .xlsx file by click on Export -> Excel button. In this case SaveFileDialog would be open, and I can choose only xlsx format. But I need to save reports in .xls format too.
Sorry for my English - I just started to learn it.
Thanks!
Upvotes: 3
Views: 1928
Reputation: 115
I found answer. I put it here for another...
ReportViewer of 11'th version could to export report into .xls format, but, by default, this possibility is hidden.
A array of supporting export formats you can see using ReportViewer.LocalReport.ListRenderingExtensions()
instance method. But all properties of received elements are readonly (including Visible
).
To change visibility of eleemnts you should to use a reflection. For example:
/// <summary>
/// Set visibility of specified by name RenderingExtension to setted value
/// For example, name of Excel (.xls) extension is "Excel"
/// </summary>
/// <param name="reportViewer">Instance of ReportViewer control</param>
/// <param name="extensionName">Extension name (for example: "Excel")</param>
/// <param name="visible">Visibility</param>
private void SetVisibilityOnRenderingExtension(ReportViewer reportViewer, string extensionName, bool visible)
{
var renderingExtension = reportViewer.LocalReport.ListRenderingExtensions().FirstOrDefault(e => e.Name == extensionName);
if (renderingExtension != null)
{
FieldInfo info = renderingExtension.GetType().GetField("m_isVisible", BindingFlags.NonPublic | BindingFlags.Instance);
if (info != null)
{
info.SetValue(renderingExtension, visible);
}
}
}
I hope, it helps someone :)
Upvotes: 2