1

好的,所以我正在将我的 SSRS 2008 报告导出到图像。我想做的是将每个单独的页面导出为图像。从我的代码中,我只能得到它来导出报告的第一页。任何帮助将不胜感激。

    Dim warnings As Microsoft.Reporting.WebForms.Warning()
    Dim streamids As String()
    Dim mimeType, encoding, extension As String

    Dim deviceInfo As XElement = _
      <DeviceInfo>
          <OutputFormat>JPEG</OutputFormat>
      </DeviceInfo>

    Report.ServerReport.SetParameters(Parameters)
    Dim bytes As Byte() = Report.ServerReport.Render("Image", deviceInfo.ToString(), mimeType, encoding, extension, streamids, warnings)

    Dim FileStream As New MemoryStream(bytes)
    Dim ReportImage As New System.Drawing.Bitmap(FileStream)

    ReportImage.Save(Server.MapPath("/Testing.jpg"), System.Drawing.Imaging.ImageFormat.Jpeg)
4

1 回答 1

5

在我的一个项目中,我使用以下代码每页获取一个流。不幸的是,我不使用 VB.NET,但您应该能够将其从 C# 转换为 VB。注意:这适用于 SSRS2005 - 我不确定它是否也适用于 SSRS2008!此外,我正在使用代码直接打印报告,而无需使用报告查看器,因此我正在创建 EMF 设备信息 - 您可能需要更改它。

这个基本代码是在谷歌搜索几个小时后在网络上的某个地方找到的——我想感谢作者,但我没有为链接添加书签——抱歉。

CultureInfo us = new CultureInfo("en-US");
string deviceInfo = String.Format(
      "<DeviceInfo>" +
      "  <OutputFormat>EMF</OutputFormat>" +
      "  <PageWidth>{0}cm</PageWidth>" +
      "  <PageHeight>{1}cm</PageHeight>" +
      "  <MarginTop>{2}cm</MarginTop>" +
      "  <MarginLeft>{3}cm</MarginLeft>" +
      "  <MarginRight>{4}cm</MarginRight>" +
      "  <MarginBottom>{5}cm</MarginBottom>" +
      "</DeviceInfo>",
      Math.Round(m_pageSize.Width, 2).ToString(us),
      Math.Round(m_pageSize.Height, 2).ToString(us),
      Math.Round(m_marginTop, 2).ToString(us),
      Math.Round(m_marginLeft, 2).ToString(us),
      Math.Round(m_marginRight, 2).ToString(us),
      Math.Round(m_marginBottom, 2).ToString(us));

m_reportStreams = new List<Stream>();
try
{
    // Tell SSRS to store one stream per page on server
    NameValueCollection urlAccessParameters = new NameValueCollection();
    urlAccessParameters.Add("rs:PersistStreams", "True");

    // Render first page
    Stream s = viewer.ServerReport.Render("IMAGE", deviceInfo, urlAccessParameters, out mime, out extension);
    m_reportStreams.Add(s);

    // Loop to get other streams
    urlAccessParameters.Remove("rs:PersistStreams");
    urlAccessParameters.Add("rs:GetNextStream", "True");
    do
    {
        s = viewer.ServerReport.Render("IMAGE", deviceInfo, urlAccessParameters, out mime, out extension);
        if (s.Length != 0) m_reportStreams.Add(s);
    }
    while (s.Length > 0);

    // Now there's one stream per page - do stuff with it
}
finally
{
    foreach (Stream s in m_reportStreams)
    {
        s.Close();
        s.Dispose();
    }
    m_reportStreams = null;
}

编辑
忘了提到这viewer是一个以编程方式创建的ReportViewer控件实例,该实例已初始化以呈现您尝试打印/保存的报告。

于 2009-07-03T07:14:58.663 回答