在我的一个项目中,我使用以下代码每页获取一个流。不幸的是,我不使用 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
控件实例,该实例已初始化以呈现您尝试打印/保存的报告。