好的,我正在努力将我的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)
答案 0 :(得分: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
控件实例,该控件已初始化以呈现您尝试打印/保存的报告。