Stimulsoft.Report web报表的使用,有需要的朋友可以参考下。
1、先用报表设计工具设计报表Report1.mrt(具体参照Stimulsoft_Reports 1. 报表制作http://blog.youkuaiyun.com/qq_31971935/article/details/50681730)
2、在项目中添加对Stimulsoft.Base.dll、Stimulsoft.Report.dll、Stimulsoft.Report.Web.dll、Stimulsoft.Report.WebDesign.dll的引用
3、在aspx页面中注册控件
<%@ register Namespace="Stimulsoft.Report.Web" TagPrefix="cc1" Assembly="Stimulsoft.Report.Web"%>
<%@ register Namespace="Stimulsoft.Report.Web" TagPrefix="cc2" Assembly="Stimulsoft.Report.WebDesign"%>
注:注册控件方式:
<%@ Register TagPrefix=”abc” Namespace=”空间名.类名” Assembly=”空间名.类名” %>
4、aspx页面中放置报表显示控件和报表设计控件
<cc1:StiWebViewer ID="StiWebViewer1" runat="server" GlobalizationFile="/reports/Localization/zh-CHS.xml" ShowDesignButton="True" onreportdesign="StiWebViewer1_ReportDesign" Theme="Office2010" BackColor="#e8e8e8"/>
<cc2:StiWebDesigner ID="StiWebDesigner1" runat="server" LocalizationDirectory="/reports/Localization/" Localization="zh-CHS"onsavereport="StiWebDesigner1_SaveReport" />
注:设置中文格式的文件夹应放置在项目的bin下面即可。
5、在代码文件中引用
using Stimulsoft.Report;
6、在Page_Load中
string filepath = Server.MapPath("~/Report1.mrt");
StiReport stireport = new StiReport();
stireport.Load(filepath);
stireport.Compile();
StiWebViewer1.Report = stireport;
7、在StiWebViewer1的ReportDesign中
string filepath = Server.MapPath("~/Report1.mrt");
StiReport stireport = new StiReport();
stireport.Load(filepath);
stireport.Compile();
StiWebDesigner1.Design(stireport);
8、在StiWebDesigner1的SaveReport中
var report = e.Report;
string filepath = Server.MapPath("~/Report1.mrt");
report.Save(filepath);
aspx页面:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="Stimulsoft_Reports.WebForm1" %>
<!DOCTYPE html>
<%@ register Namespace="Stimulsoft.Report.Web" TagPrefix="cc1" Assembly="Stimulsoft.Report.Web"%>
<%@ register Namespace="Stimulsoft.Report.Web" TagPrefix="cc2" Assembly="Stimulsoft.Report.WebDesign"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<cc1:StiWebViewer ID="StiWebViewer1" runat="server" GlobalizationFile="/Content/page/reports/Localization/zh-CHS.xml" ShowDesignButton="True" onreportdesign="StiWebViewer1_ReportDesign" Theme="Office2010" BackColor="#e8e8e8"/>
<cc2:StiWebDesigner ID="StiWebDesigner1" runat="server" LocalizationDirectory="/Content/page/reports/Localization/" Localization="zh-CHS" onsavereport="StiWebDesigner1_SaveReport" />
</div>
</form>
</body>
</html>
aspx.cs后台代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Stimulsoft.Report;
namespace Stimulsoft_Reports
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string filepath = Server.MapPath("~/Report1.mrt");
StiReport stireport = new StiReport();
stireport.Load(filepath);
stireport.Compile();
StiWebViewer1.Report = stireport;
}
protected void StiWebViewer1_ReportDesign(object sender, Stimulsoft.Report.Web.StiReportDesignEventArgs e)
{
string filepath = Server.MapPath("~/Report1.mrt");
StiReport stireport = new StiReport();
stireport.Load(filepath);
stireport.Compile();
StiWebDesigner1.Design(stireport);
}
protected void StiWebDesigner1_SaveReport(object sender, Stimulsoft.Report.Web.StiWebDesigner.StiSaveReportEventArgs e)
{
var report = e.Report;
string filepath = Server.MapPath("~/Report1.mrt");
report.Save(filepath);
}
}
}
项目文件结构图:
运行后效果: