在做打印时,经常需要把要打印的页面展现给客户端浏览,如果客户还需要倒出(例如倒出到Word文档),则我们可以使用水晶报表自代的倒出的功能完成。
private void btnout_Click(object sender, System.EventArgs e)
{
///<value>它这里的倒出使用的是水晶报表自己的倒出属性</value>
if (Session["reportname"]!=null && Session[lblName.Text]!=null )
{
ReportDocument MyReport=new ReportDocument();
MyReport = (ReportDocument)Session[lblName.Text];
crvMain.ReportSource=MyReport;
String Pathdoc=Server.MapPath(Request.ApplicationPath);
string FileName=Pathdoc+"\Common\打印报表.doc";
![](/Images/OutliningIndicators/InBlock.gif)
///<value>DiskFileDestinationOptions 提供属性 以便设置倒出到磁盘时的文件名</value>
DiskFileDestinationOptions mydesc=new DiskFileDestinationOptions();
![](/Images/OutliningIndicators/InBlock.gif)
///<value>DiskFileName 获取或设置数据库表的位置</value>
mydesc.DiskFileName=Pathdoc+"\Common\打印报表.doc";
![](/Images/OutliningIndicators/InBlock.gif)
///<value>提供属性 以便检索和设置用于倒出报表的选项</value>
ExportOptions exportOpts=MyReport.ExportOptions;
![](/Images/OutliningIndicators/InBlock.gif)
///<value>ExportDestinationType 获取或设置倒出目标的类型</value>
exportOpts.ExportDestinationType=ExportDestinationType.DiskFile;
![](/Images/OutliningIndicators/InBlock.gif)
///<value></value>
exportOpts.DestinationOptions=mydesc;
![](/Images/OutliningIndicators/InBlock.gif)
///</value>获取或设置倒出格式类型</value>
exportOpts.ExportFormatType= ExportFormatType.WordForWindows;
![](/Images/OutliningIndicators/InBlock.gif)
///<value>将报表倒出到在ExportOptions对象内指定的格式和目标</value>
MyReport.Export();
![](/Images/OutliningIndicators/InBlock.gif)
//读WORD文件下载
FileInfo byteinfile=new FileInfo(FileName);
instream=byteinfile.OpenRead();
FileStream f = File.OpenRead(FileName);
byte[] b = new byte[instream.Length];
f.Read(b,0,b.Length);
instream.Close();
HttpResponse rps=Page.Response;
rps.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
rps.Charset = "utf-8";
rps.BufferOutput=false;
rps.ContentType="application/doc";
FileName = HttpUtility.UrlEncode(FileName).Replace("+", "%20");
rps.AppendHeader("Content-Disposition", "attachment;FileName="+FileName);
rps.BinaryWrite(b);
rps.Close();
rps.End();
}
}这是一个自己在项目中得例子。希望对用得到的朋友有所帮助!
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)