在Windows应用程序中从rdl / rdlc文件中编写Excel文件

时间:2015-11-09 16:15:43

标签: c++ excel reporting-services rdlc rdl

我有Report Builder 3.0生成的 rdl 文件。我需要在我用C ++编写的Windows应用程序中使用它们,以便我能够在运行时设置SQL Server连接参数和报告位置。

这可能吗?如何?

Google告诉我我需要将 rdl 转换为 rdlc 文件,但即使这样我也找不到办法设置这些参数并从C ++调用 rdlc 文件。

1 个答案:

答案 0 :(得分:0)

您可以使用ReportViewer并使用RDL或RDLC文件,但RDL可能有一些限制,因为它不包含创建数据绑定代码所需的信息。

  

RDL文件不包含设计时的一些信息   ReportViewer控件依赖于自动生成   数据绑定代码。通过手动绑定数据,可以使用RDL文件   ReportViewer控件。

您可以从ReportViewer设置参数,在C#中查看this文档和以下代码示例:

private void SetReportParameters() {
   // Set Processing Mode
   reportViewer1.ProcessingMode = ProcessingMode.Remote;

   // Set report server and report path
   reportViewer1.ServerReport.ReportServerUrl = new
      Uri("http://<ServerName>/reportserver");

   reportViewer1.ServerReport.ReportPath = 
      "/AdventureWorks Sample Reports/Employee Sales Summary";

   List<ReportParameter> paramList = new List<ReportParameter>();

   paramList.Add(new ReportParameter("EmpID", "288", false));
   paramList.Add(new ReportParameter("ReportMonth", "12", false));
   paramList.Add(new ReportParameter("ReportYear", "2003", false));

   this.reportViewer1.ServerReport.SetParameters(paramList);

   // Process and render the report
   reportViewer1.RefreshReport();
}

这是ReportViewer用于生成Excel文件的示例:

protected void Button1_Click(object sender, EventArgs e)
{
            Warning[] warnings;
            string[] streamids;
            string mimeType;
            string encoding;
            string extension;

            byte[] bytes = ReportViewer1.LocalReport.Render(
               "Excel", null, out mimeType, out encoding,
                out extension,
               out streamids, out warnings);

            FileStream fs = new FileStream(@"c:\output.xls",
               FileMode.Create);
            fs.Write(bytes, 0, bytes.Length);
            fs.Close();

            Label1.Text = "Report exported to output.xls";
}

请告诉我这是否可以帮助您。