c# - 如何以编程方式运行 ReportViewer 并将其导出为 HTML

标签 c# asp.net visual-studio-2012 reportviewer

这个问题有两个部分。第 1 部分:如何以编程方式运行报表查看器和第 2 部分:如何以编程方式将报表查看器导出为 html。

第 1 部分:.rdl 托管在远程服务器上,我需要运行此报告,就像用户单击“查看结果”一样,但是以编程方式。我给了它正确的报告 url、路径和参数,但我似乎遗漏了一些东西,因为当我导出它时,结果为 0,这意味着它没有运行。我很确定我遗漏了什么,但我不知道它是什么。

第 2 部分:我在 VS12 上运行。我读过你无法在 VS10 中导出为 HTML,但在 VS12 中你可以,但结果全错了。该报告有几个表格,其中包含颜色填充的单元格。即使数据以表格格式对齐,单元格也不会着色。我让它以 pdf 格式工作,但数据为空,这是第 1 部分的原因。我更希望它采用 html 格式,因为我计划将此导出放在电子邮件正文中。

这是我到目前为止得到的:

report.ServerReport.ReportPath = reportPath;

//Assign parameters
var parameters = new List<ReportParameter>();

            parameters.Add(new ReportParameter("Param1", param1));

            parameters.Add(new ReportParameter("Param2", param2));

            //Execute report
            report.ServerReport.SetParameters(parameters.ToArray());

            string mimeType,
                encoding,
                fileNameExtension;

            Warning[] warnings;

            string[] streamIds;

            //Export report
            byte[] exportBytes = report.ServerReport.Render("HTML4.0", null, out mimeType, out encoding,
                out fileNameExtension, out streamIds, out warnings);

             //For pdf format
             //HttpContext.Current.Response.Buffer = true;
             //HttpContext.Current.Response.Clear();
             //HttpContext.Current.Response.ContentType = mimeType;
             //HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=ExportedReport." + fileNameExtension);
             //HttpContext.Current.Response.BinaryWrite(exportBytes);
             //HttpContext.Current.Response.Flush();
             //HttpContext.Current.Response.End();

            var exportHtml = System.Text.Encoding.UTF8.GetString(exportBytes);

如果问题不多,请在您的回答中添加一些解释。我对报告还是个新手,我想了解为什么它不起作用。

最佳答案

我设法解决了它。我的代码是正确的,即使我传递了必需的参数,但报告本身并没有真正使用该参数。

关于c# - 如何以编程方式运行 ReportViewer 并将其导出为 HTML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30806580/

相关文章:

c# - 为什么不指定“ref”就可以从方法更改Struct的int []属性?

插件 DLL 的本地化资源的 c# 路径

asp.net - 使用 Elmah 记录 WCF Web 服务的用户名

asp.net - VS 2010 中缺少 App_Code 文件夹

.net - MVC3项目升级到VS2012后出现AccessViolationException

c++ - 是否可以在没有 Visual Studio 的情况下使用 MSVC 进行编译?

c# - 使用 JsonConvert.DeserializeObject 反序列化派生对象列表

安哥拉的 C# 文化名称?

asp.net - PageMethod默认超时

c++ - Winbase.h 不支持创建 DLL 文件