[英]Export to CSV in LocalReport of ReportViewer of winform
I wanted to export data from ReportViewer to CSV format in LocalReport. 我想在LocalReport中将ReportViewer中的数据导出为CSV格式。 I have gone through this article on MSDN Forum which says that the Local report does not support CSV rendering.but this can be done in server Report but I can not use Server Report.
我在MSDN论坛上看过这篇文章,说本地报告不支持CSV渲染。但这可以在服务器报告中完成,但我不能使用服务器报告。
Is there any way to add a CSV export extension to ReportViewer in LocalReport? 有没有办法在LocalReport中向ReportViewer添加CSV导出扩展?
Option 1 - Customize Export To Excel Toolbar Button 选项1 - 自定义导出到Excel工具栏按钮
Handle ReportExport
event of report viewer and if selected extension is excel, do your export to csv instead. 处理报表查看器的
ReportExport
事件,如果选择的扩展名为excel,请将导出导出到csv。
private void reportViewer1_ReportExport(object sender,
Microsoft.Reporting.WinForms.ReportExportEventArgs e)
{
if (e.Extension.Name == "EXCELOPENXML")
{
//Export your data to csv here
e.Cancel = true;
}
}
Option 2 - Add Custom Button To ReportViewer Toolbar 选项2 - 向ReportViewer工具栏添加自定义按钮
Add your custom button to toolbar of report viewer and assign a handler to click event of it and do your export to csv here: 将自定义按钮添加到报表查看器的工具栏中,并指定处理程序以单击它的事件并在此处导出到csv:
private void ReportForm_Load(object sender, EventArgs e)
{
//Load your data from wherever your data is
//For example using Entity Framework:
var db = new TestDBEntities();
var data = db.Categories.ToList();
//Set data to report
this.CategoryBindingSource.DataSource = data;
this.reportViewer1.RefreshReport();
//Add your button to Toolbar of ReportViewr
ToolStrip toolStrip = (ToolStrip)reportViewer1.Controls.Find("toolStrip1", true)[0];
toolStrip.Items.Add(new ToolStripButton("Export To CSV",
null /*image*/, ExportToCSV_Click));
}
void ExportToCSV_Click(object sender, EventArgs e)
{
//Export your data to csv here
}
Note: 注意:
Wherever you want to export data to csv , you can use data of datasource that you have passed to report. 无论您想将数据导出到csv,都可以使用已传递的数据源数据进行报告。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.