2009-07-02 54 views
1

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

回答

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控制的程序创建的实例。

+0

我试过这个,我得到一个错误:无法找到执行'' – 2009-07-06 16:17:51