您的位置:首页 > 其它

VSTO 学习笔记(六)在 Excel 2010中使用RDLC报表

2015-06-16 10:00 330 查看
原文:VSTO 学习笔记(六)在 Excel 2010中使用RDLC报表Excel具有强大的图表显示、分析功能,这点毋庸置疑,但是如果将常规MIS系统中的数据以报表的形式在Excel中显示,却并不那么容易。在VSTO中,我们可以借助RDLC报表组件来满足这种需求。

示例代码下载

本系列所有示例代码均在 Visual Studio 2010 Ultimate RTM + Office 2010 Professional Plus Beta x64 下测试通过

注:本次数据库使用的是 SQL Server 2008 R2 x64 RTM

1、在VS2010中,新建一个Excel 2010 Workbook项目:

代码

private void Sheet1_Startup(object sender, System.EventArgs e)
{
this.fnDataIni();
this.fnBuildDataSource(this.comCountry.Text);
}

private void Sheet1_Shutdown(object sender, System.EventArgs e)
{
}

#region VSTO Designer generated code

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InternalStartup()
{
this.comCountry.SelectedIndexChanged += new System.EventHandler(this.comCountry_SelectedIndexChanged);
this.Startup += new System.EventHandler(this.Sheet1_Startup);
this.Shutdown += new System.EventHandler(this.Sheet1_Shutdown);

}

#endregion

private void comCountry_SelectedIndexChanged(object sender, EventArgs e)
{
this.rptExcel.LocalReport.DataSources.Clear();
this.fnBuildDataSource(this.comCountry.Text);
}

10、最终运行效果:



11、生产的Excel位于Debug/Release下:



小结:

本次我们在VSTO中做了一个简单的报表,使用了Linq to SQL,当然,如果能用Excel的原生功能做报表效果更好,使用VSTO可以大大简化实现相同功能的方法,使得我们可以用更熟悉的方法来完成一些需求。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: